Author: husted Date: Wed Nov 22 12:35:46 2006 New Revision: 478313 URL: http://svn.apache.org/viewvc?view=rev&rev=478313 Log: WW-1483 Javadoc and IDEA refactorings only. No functional changes.
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java?view=diff&rev=478313&r1=478312&r2=478313 ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java Wed Nov 22 12:35:46 2006 @@ -132,6 +132,7 @@ /** * Create instance utilizing a list of packages to scan for Action classes. + * * @param pkgs List of pacaktges to scan for Action Classes. */ public ClasspathConfigurationProvider(String[] pkgs) { @@ -151,10 +152,16 @@ } + /** + * PageLocator defines a locate method that can be used to discover server pages. + */ public static interface PageLocator { public URL locate(String path); } + /** + * ClasspathPathLocator searches the classpath for server pages. + */ public static class ClasspathPageLocator implements PageLocator { public URL locate(String path) { return ClassLoaderUtil.getResource(path, getClass()); @@ -162,32 +169,49 @@ } /** - * @param defaultParentPackage the defaultParentPackage to set + * Register a default parent package for the actions. + * + * @param defaultParentPackage the new defaultParentPackage */ public void setDefaultParentPackage(String defaultParentPackage) { this.defaultParentPackage = defaultParentPackage; } /** - * @param defaultPageExtension the defaultPageExtension to set + * Register a default page extension to use when locating pages. + * + * @param defaultPageExtension the new defaultPageExtension */ public void setDefaultPageExtension(String defaultPageExtension) { this.defaultPageExtension = defaultPageExtension; } /** + * Reigster a default page prefix to use when locating pages. + * * @param defaultPagePrefix the defaultPagePrefix to set */ public void setDefaultPagePrefix(String defaultPagePrefix) { this.defaultPagePrefix = defaultPagePrefix; } + /** + * Register a PageLocation to use to scan for server pages. + * + * @param locator + */ public void setPageLocator(PageLocator locator) { this.pageLocator = locator; } /** - * @param pkgs A set of packages to load + * Scan a list of packages for Action classes. + * + * This method loads classes that implement the Action interface + * or have a class name that ends with the letters "Action". + * + * @param pkgs A list of packages to load + * @see #processActionClass */ protected void loadPackages(String[] pkgs) { @@ -201,6 +225,7 @@ } }, pkgs); + Set<? extends Class<? extends Class>> actionClasses = resolver.getClasses(); for (Object obj : actionClasses) { Class cls = (Class) obj; @@ -215,9 +240,14 @@ } /** + * Create a default action mapping for a class instance. + * + * The namespace annotation is honored, if found, otherwise + * the Java package is converted into the namespace + * by changing the dots (".") to slashes ("/"). * * @param cls Action or POJO instance to process - * @param pkgs Set of packages to scan for Actions + * @param pkgs List of packages that were scanned for Actions */ protected void processActionClass(Class cls, String[] pkgs) { String name = cls.getName(); @@ -227,7 +257,7 @@ for (String pkg : pkgs) { if (name.startsWith(pkg)) { if (LOG.isDebugEnabled()) { - LOG.debug("Processing class "+name); + LOG.debug("ClasspathConfigurationProvider: Processing class "+name); } name = name.substring(pkg.length() + 1); @@ -249,7 +279,7 @@ String parent = ((ParentPackage)annotation).value(); PackageConfig parentPkg = configuration.getPackageConfig(parent); if (parentPkg == null) { - throw new ConfigurationException("Unable to locate parent package "+parent, annotation); + throw new ConfigurationException("ClasspathConfigurationProvider: Unable to locate parent package "+parent, annotation); } pkgConfig.addParent(parentPkg); @@ -263,6 +293,7 @@ actionName = actionName.substring(0, actionName.length() - ACTION.length()); } + // Force initial letter of action to lowercase if (actionName.length() > 1) { int lowerPos = actionName.lastIndexOf('/') + 1; StringBuilder sb = new StringBuilder(); @@ -282,8 +313,15 @@ } /** + * Finds or creates the package configuration for an Action class. + * + * The namespace annotation is honored, if found, + * and the namespace is checked for a parent configuration. + * + * @param actionNamespace The configuration namespace * @param actionPackage The Java package containing our Action classes - * @return + * @param actionClass The Action class instance + * @return PackageConfig object for the Action class */ protected PackageConfig loadPackageConfig(String actionNamespace, String actionPackage, Class actionClass) { PackageConfig parent = null; @@ -307,7 +345,7 @@ } if (parent == null) { - throw new ConfigurationException("Unable to locate default parent package: " + + throw new ConfigurationException("ClasspathConfigurationProvider: Unable to locate default parent package: " + defaultParentPackage); } pkgConfig.addParent(parent); @@ -319,27 +357,45 @@ return pkgConfig; } + /** + * Default destructor. Override to provide behavior. + */ public void destroy() { } - + + /** + * Register this application's configuration. + * + * @param config The configuration for this application. + */ public void init(Configuration config) { this.configuration = config; } + /** + * Clears and loads the list of packages registered at construction. + * + * @throws ConfigurationException + */ public void loadPackages() throws ConfigurationException { loadedPackageConfigs.clear(); loadPackages(packages); initialized = true; } + /** + * Indicates whether the packages have been initialized. + * + * @return True if the packages have been initialized + */ public boolean needsReload() { return !initialized; } /** - * Creates result configs from result annotations, and if a result isn't found, - * creates them on the fly. + * Creates ResultConfig objects from result annotations, + * and if a result isn't found, creates it on the fly. */ class ResultMap<K,V> extends HashMap<K,V> { private Class actionClass; @@ -376,6 +432,12 @@ } + /** + * Extracts result name and value and calls [EMAIL PROTECTED] #createResultConfig}. + * + * @param result Result annotation reference representing result type to create + * @return New or cached ResultConfig object for result + */ protected ResultConfig createResultConfig(Result result) { Class<? extends Object> cls = result.type(); if (cls == NullResult.class) { @@ -384,6 +446,12 @@ return createResultConfig(result.name(), cls, result.value()); } + /** + * Retrieve ResultConfig from cache. + * + * @param key Name of ResultConfig + * @return ResultConfig correspnding to key + */ public V get(Object key) { V result = super.get(key); @@ -391,8 +459,8 @@ return result; } else { - // TODO: This code never is actually used, do to how the runtime configuration - // is created. + // This code should never actually be called, + // due to how the runtime configuration is created. String actionPath = pkgConfig.getNamespace() + "/" + actionName; String fileName = actionPath + "-" + key + defaultPageExtension; @@ -406,22 +474,26 @@ } /** - * @param key - * @param resultClass - * @param location - * @return + * Creates a default ResultConfig, + * using either the resultClass or the default ResultType for configuration package + * associated this ResultMap class. + * + * @param key The result type name + * @param resultClass The class for the result type + * @param location Path to the resource represented by this type + * @return A ResultConfig for key mapped to location */ private ResultConfig createResultConfig(Object key, Class<? extends Object> resultClass, String location) { Map<? extends Object, ? extends Object> configParams = null; if (resultClass == null) { String defaultResultType = pkgConfig.getFullDefaultResultType(); - ResultTypeConfig resultType = (ResultTypeConfig) pkgConfig.getAllResultTypeConfigs().get(defaultResultType); + ResultTypeConfig resultType = pkgConfig.getAllResultTypeConfigs().get(defaultResultType); configParams = resultType.getParams(); String className = resultType.getClazz(); try { resultClass = ClassLoaderUtil.loadClass(className, getClass()); } catch (ClassNotFoundException ex) { - throw new ConfigurationException("Unable to locate result class "+className, actionClass); + throw new ConfigurationException("ClasspathConfigurationProvider: Unable to locate result class "+className, actionClass); } } @@ -442,7 +514,8 @@ } } + // See superclass for Javadoc public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException { - // Nothing + // Override to provide functionality } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java?view=diff&rev=478313&r1=478312&r2=478313 ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/DefaultSettings.java Wed Nov 22 12:35:46 2006 @@ -32,117 +32,111 @@ /** - * Default implementation of Settings - creates and delegates to other settingss by using an internal - * [EMAIL PROTECTED] DelegatingSettings}. + * DefaultSettings implements optional methods of Settings. + * <p> + * This class creates and delegates to other settings by using an internal + * [EMAIL PROTECTED] DelegatingSettings} object. */ public class DefaultSettings extends Settings { + /** + * The logging instance for this class. + */ protected Log log = LogFactory.getLog(this.getClass()); - Settings config; + /** + * The Settings object that handles API calls. + */ + Settings delegate; /** - * Creates a new DefaultSettings object by loading all property files - * and creating an internal [EMAIL PROTECTED] DelegatingSettings} object. All calls to get and set - * in this class will call that settings object. + * Constructs an instance by loading the standard property files, + * any custom property files (<code>struts.custom.properties</code>), + * and any custom message resources (). + * <p> + * Since this constructor combines Settings from multiple resources, + * it utilizes a [EMAIL PROTECTED] DelegatingSettings} instance, + * and all API calls are handled by that instance. */ public DefaultSettings() { - // Create default implementations - // Use default properties and struts.properties + ArrayList<Settings> list = new ArrayList<Settings>(); + // stuts.properties, default.properties try { list.add(new PropertiesSettings("struts")); } catch (Exception e) { - log.warn("Could not find or error in struts.properties", e); + log.warn("DefaultSettings: Could not find or error in struts.properties", e); } try { list.add(new PropertiesSettings("org/apache/struts2/default")); } catch (Exception e) { - log.error("Could not find org/apache/struts2/default.properties", e); + log.error("DefaultSettings: Could not find or error in org/apache/struts2/default.properties", e); } - Settings[] configList = new Settings[list.size()]; - config = new DelegatingSettings((Settings[]) list.toArray(configList)); + Settings[] settings = new Settings[list.size()]; + delegate = new DelegatingSettings(list.toArray(settings)); - // Add list of additional properties settingss + // struts.custom.properties try { - StringTokenizer configFiles = new StringTokenizer((String) config.getImpl(StrutsConstants.STRUTS_CUSTOM_PROPERTIES), ","); + StringTokenizer customProperties = new StringTokenizer(delegate.getImpl(StrutsConstants.STRUTS_CUSTOM_PROPERTIES), ","); - while (configFiles.hasMoreTokens()) { - String name = configFiles.nextToken(); + while (customProperties.hasMoreTokens()) { + String name = customProperties.nextToken(); try { list.add(new PropertiesSettings(name)); } catch (Exception e) { - log.error("Could not find " + name + ".properties. Skipping"); + log.error("DefaultSettings: Could not find " + name + ".properties. Skipping."); } } - configList = new Settings[list.size()]; - config = new DelegatingSettings((Settings[]) list.toArray(configList)); + settings = new Settings[list.size()]; + delegate = new DelegatingSettings(list.toArray(settings)); } catch (IllegalArgumentException e) { - // thrown when Settings is unable to find a certain property - // eg. struts.custom.properties in default.properties which is commented - // out + // Assume it's OK, since IllegalArgumentException is thrown + // when Settings is unable to find a certain setting, + // like the struts.custom.properties, which is commented out } - // Add additional list of i18n global resource bundles + // struts.custom.i18n.resources try { LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages"); - StringTokenizer bundleFiles = new StringTokenizer((String) config.getImpl(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES), ", "); + StringTokenizer customBundles = new StringTokenizer(delegate.getImpl(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES), ", "); - while (bundleFiles.hasMoreTokens()) { - String name = bundleFiles.nextToken(); + while (customBundles.hasMoreTokens()) { + String name = customBundles.nextToken(); try { - log.info("Loading global messages from " + name); + log.info("DefaultSettings: Loading global messages from " + name); LocalizedTextUtil.addDefaultResourceBundle(name); } catch (Exception e) { - log.error("Could not find " + name + ".properties. Skipping"); + log.error("DefaultSettings: Could not find " + name + ".properties. Skipping"); } } } catch (IllegalArgumentException e) { - // struts.custom.i18n.resources wasn't provided + // Assume it's OK, since many applications do not provide custom resource bundles. } } - - /** - * Sets the given property - delegates to the internal config implementation. - * - * @see #set(String, String) - */ - public void setImpl(String aName, String aValue) throws IllegalArgumentException, UnsupportedOperationException { - config.setImpl(aName, aValue); + // See superclass for Javadoc + public void setImpl(String name, String value) throws IllegalArgumentException, UnsupportedOperationException { + delegate.setImpl(name, value); } - /** - * Gets the specified property - delegates to the internal config implementation. - * - * @see #get(String) - */ + // See superclass for Javadoc public String getImpl(String aName) throws IllegalArgumentException { - // Delegate - return config.getImpl(aName); + return delegate.getImpl(aName); } - /** - * Determines whether or not a value has been set - delegates to the internal config implementation. - * - * @see #isSet(String) - */ + // See superclass for Javadoc public boolean isSetImpl(String aName) { - return config.isSetImpl(aName); + return delegate.isSetImpl(aName); } - /** - * Returns a list of all property names - delegates to the internal config implementation. - * - * @see #list() - */ + // See superclass for Javadoc public Iterator listImpl() { - return config.listImpl(); + return delegate.listImpl(); } } Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java?view=diff&rev=478313&r1=478312&r2=478313 ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Settings.java Wed Nov 22 12:35:46 2006 @@ -244,24 +244,24 @@ /** * Implements the [EMAIL PROTECTED] #get(String)} method. * - * @param aName The name of the setting value to retreive + * @param name The name of the setting value to retreive * @return The setting value as a String * @throws IllegalArgumentException if an error occurs when retrieving the value * @see #get(String) */ - public String getImpl(String aName) throws IllegalArgumentException { + public String getImpl(String name) throws IllegalArgumentException { return null; } /** * Implements the [EMAIL PROTECTED] #getLocation(String)} method. * + * @param name Name of the setting to locate * @return The location of the setting - * @param aName Name of the setting to locate * @throws IllegalArgumentException if an error occurs when retrieving the value * @see #getLocation(String) */ - public Location getLocationImpl(String aName) throws IllegalArgumentException { + public Location getLocationImpl(String name) throws IllegalArgumentException { return null; }