dgraham 2003/07/04 13:53:42
Modified: src/share/org/apache/struts/config
ConfigHelperInterface.java ConfigHelper.java
src/share/org/apache/struts/tiles/definition
ReloadableDefinitionsFactory.java
src/share/org/apache/struts/util RequestUtils.java
src/share/org/apache/struts/tiles TilesPlugin.java
DefinitionsFactoryConfig.java
Log:
Made javadoc @since tags consistent for 1.1.
Revision Changes Path
1.6 +5 -5
jakarta-struts/src/share/org/apache/struts/config/ConfigHelperInterface.java
Index: ConfigHelperInterface.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigHelperInterface.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConfigHelperInterface.java 5 Jan 2003 00:40:04 -0000 1.5
+++ ConfigHelperInterface.java 4 Jul 2003 20:53:42 -0000 1.6
@@ -104,7 +104,7 @@
* from under the context and key used by the Struts
* ActionServlet when the resources are created.
*
- * @since 1.1
+ * @since Struts 1.1
* @author Ted Husted
* @author Luis Arias <[EMAIL PROTECTED]>
* @version $Revision$ $Date$
1.6 +5 -5
jakarta-struts/src/share/org/apache/struts/config/ConfigHelper.java
Index: ConfigHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/config/ConfigHelper.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ConfigHelper.java 4 May 2003 22:41:13 -0000 1.5
+++ ConfigHelper.java 4 Jul 2003 20:53:42 -0000 1.6
@@ -108,7 +108,7 @@
* from under the context and key used by the Struts
* ActionServlet when the resources are created.
*
- * @since 1.1
+ * @since Struts 1.1
* @author Ted Husted
* @author Luis Arias <[EMAIL PROTECTED]>
* @version $Revision$ $Date$
1.7 +212 -184
jakarta-struts/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java
Index: ReloadableDefinitionsFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/tiles/definition/ReloadableDefinitionsFactory.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ReloadableDefinitionsFactory.java 27 Feb 2003 19:19:54 -0000 1.6
+++ ReloadableDefinitionsFactory.java 4 Jul 2003 20:53:42 -0000 1.7
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -59,7 +59,6 @@
*
*/
-
package org.apache.struts.tiles.definition;
import java.util.Enumeration;
@@ -85,18 +84,26 @@
* instance.
*
* @author Cedric Dumoulin
- * @since 1.1
+ * @since Struts 1.1
* @version $Revision$ $Date$
*/
-public class ReloadableDefinitionsFactory implements ComponentDefinitionsFactory
-{
- /** The real factory instance */
- protected ComponentDefinitionsFactory factory;
- /** Initialization parameters */
- protected Map properties;
+public class ReloadableDefinitionsFactory implements ComponentDefinitionsFactory {
+
+ /**
+ * The real factory instance.
+ */
+ protected ComponentDefinitionsFactory factory = null;
- /** Name of init property carrying factory class name */
- public static final String DEFINITIONS_FACTORY_CLASSNAME =
"definitions-factory-class";
+ /**
+ * Initialization parameters.
+ */
+ protected Map properties = null;
+
+ /**
+ * Name of init property carrying factory class name.
+ */
+ public static final String DEFINITIONS_FACTORY_CLASSNAME =
+ "definitions-factory-class";
/**
* Constructor.
@@ -105,12 +112,14 @@
* @param servletConfig Our servlet config.
* @throws DefinitionsFactoryException If factory creation fail.
*/
- public ReloadableDefinitionsFactory( ServletContext servletContext, ServletConfig
servletConfig )
- throws DefinitionsFactoryException
- {
- properties = new ServletPropertiesMap( servletConfig );
- factory = createFactory( servletContext, properties);
- }
+ public ReloadableDefinitionsFactory(
+ ServletContext servletContext,
+ ServletConfig servletConfig)
+ throws DefinitionsFactoryException {
+
+ properties = new ServletPropertiesMap(servletConfig);
+ factory = createFactory(servletContext, properties);
+ }
/**
* Constructor.
@@ -119,178 +128,197 @@
* @param properties Map containing all properties.
* @throws DefinitionsFactoryException If factory creation fail.
*/
- public ReloadableDefinitionsFactory( ServletContext servletContext, Map
properties )
- throws DefinitionsFactoryException
- {
- this.properties = properties;
- factory = createFactory( servletContext, properties);
- }
-
-
- /**
- * Create Definition factory from provided classname.
- * If a factory class name is provided, a factory of this class is created.
Otherwise,
- * a default factory is created.
- * Factory must have a constructor taking ServletContext and Map as parameter.
- * @param classname Class name of the factory to create.
- * @param servletContext Servlet Context passed to newly created factory.
- * @param properties Map of name/property passed to newly created factory.
- * @return newly created factory.
- * @throws DefinitionsFactoryException If an error occur while initializing
factory
- */
- public ComponentDefinitionsFactory createFactoryFromClassname(ServletContext
servletContext, Map properties, String classname)
- throws DefinitionsFactoryException
- {
- if( classname == null )
- return createFactory( servletContext, properties );
-
- // Try to create from classname
- try
- {
- Class factoryClass = TilesUtil.applicationClass(classname);
- ComponentDefinitionsFactory factory =
(ComponentDefinitionsFactory)factoryClass.newInstance();
- factory.initFactory( servletContext, properties);
- return factory;
+ public ReloadableDefinitionsFactory(
+ ServletContext servletContext,
+ Map properties)
+ throws DefinitionsFactoryException {
+
+ this.properties = properties;
+ factory = createFactory(servletContext, properties);
}
- catch( ClassCastException ex )
- { // Bad classname
- throw new DefinitionsFactoryException( "Error - createDefinitionsFactory :
Factory class '"
- + classname +" must implements
'ComponentDefinitionsFactory'.", ex );
+
+ /**
+ * Create Definition factory from provided classname.
+ * If a factory class name is provided, a factory of this class is created.
Otherwise,
+ * a default factory is created.
+ * Factory must have a constructor taking ServletContext and Map as parameter.
+ * @param classname Class name of the factory to create.
+ * @param servletContext Servlet Context passed to newly created factory.
+ * @param properties Map of name/property passed to newly created factory.
+ * @return newly created factory.
+ * @throws DefinitionsFactoryException If an error occur while initializing
factory
+ */
+ public ComponentDefinitionsFactory createFactoryFromClassname(
+ ServletContext servletContext,
+ Map properties,
+ String classname)
+ throws DefinitionsFactoryException {
+
+ if (classname == null) {
+ return createFactory(servletContext, properties);
+ }
+
+ // Try to create from classname
+ try {
+ Class factoryClass = TilesUtil.applicationClass(classname);
+ ComponentDefinitionsFactory factory =
+ (ComponentDefinitionsFactory) factoryClass.newInstance();
+ factory.initFactory(servletContext, properties);
+ return factory;
+
+ } catch (ClassCastException ex) { // Bad classname
+ throw new DefinitionsFactoryException(
+ "Error - createDefinitionsFactory : Factory class '"
+ + classname
+ + " must implements 'ComponentDefinitionsFactory'.",
+ ex);
+
+ } catch (ClassNotFoundException ex) { // Bad classname
+ throw new DefinitionsFactoryException(
+ "Error - createDefinitionsFactory : Bad class name '"
+ + classname
+ + "'.",
+ ex);
+
+ } catch (InstantiationException ex) { // Bad constructor or error
+ throw new DefinitionsFactoryException(ex);
+
+ } catch (IllegalAccessException ex) {
+ throw new DefinitionsFactoryException(ex);
+ }
+
}
- catch( ClassNotFoundException ex )
- { // Bad classname
- throw new DefinitionsFactoryException( "Error - createDefinitionsFactory : Bad
class name '"
- + classname +"'.", ex );
+
+ /**
+ * Create default Definition factory.
+ * Factory must have a constructor taking ServletContext and Map as parameter.
+ * In this implementation, default factory is of class I18nFactorySet
+ * @param servletContext Servlet Context passed to newly created factory.
+ * @param properties Map of name/property passed to newly created factory.
+ * @return newly created factory.
+ * @throws DefinitionsFactoryException If an error occur while initializing
factory
+ */
+ public ComponentDefinitionsFactory createDefaultFactory(
+ ServletContext servletContext,
+ Map properties)
+ throws DefinitionsFactoryException {
+
+ ComponentDefinitionsFactory factory =
+ new I18nFactorySet(servletContext, properties);
+
+ return factory;
}
- catch( InstantiationException ex )
- { // Bad constructor or error
- throw new DefinitionsFactoryException( ex );
+
+ /**
+ * Create Definition factory.
+ * Convenience method. ServletConfig is wrapped into a Map allowing retrieval
+ * of init parameters. Factory classname is also retrieved, as well as debug
level.
+ * Finally, approriate createDefinitionsFactory() is called.
+ * @param servletContext Servlet Context passed to newly created factory.
+ * @param properties Map containing all properties.
+ */
+ public ComponentDefinitionsFactory createFactory(
+ ServletContext servletContext,
+ Map properties)
+ throws DefinitionsFactoryException {
+
+ String classname = (String) properties.get(DEFINITIONS_FACTORY_CLASSNAME);
+
+ if (classname != null) {
+ return createFactoryFromClassname(servletContext, properties,
classname);
+ }
+
+ return new I18nFactorySet(servletContext, properties);
+ }
+
+ /**
+ * Get a definition by its name.
+ * Call appropriate method on underlying factory instance.
+ * Throw appropriate exception if definition or definition factory is not found.
+ * @param definitionName Name of requested definition.
+ * @param request Current servlet request.
+ * @param servletContext Current servlet context.
+ * @throws FactoryNotFoundException Can't find definition factory.
+ * @throws DefinitionsFactoryException General error in factory while getting
definition.
+ */
+ public ComponentDefinition getDefinition(
+ String definitionName,
+ ServletRequest request,
+ ServletContext servletContext)
+ throws FactoryNotFoundException, DefinitionsFactoryException {
+
+ return factory.getDefinition(
+ definitionName,
+ (HttpServletRequest) request,
+ servletContext);
}
- catch( IllegalAccessException ex )
- { //
- throw new DefinitionsFactoryException( ex );
+
+ /**
+ * Reload underlying factory.
+ * Reload is done by creating a new factory instance, and replacing the old
instance
+ * with the new one.
+ * @param servletContext Current servlet context.
+ * @throws DefinitionsFactoryException If factory creation fails.
+ */
+ public void reload(ServletContext servletContext)
+ throws DefinitionsFactoryException {
+
+ ComponentDefinitionsFactory newInstance =
+ createFactory(servletContext, properties);
+
+ factory = newInstance;
}
- }
+ /**
+ * Get underlying factory instance.
+ * @return ComponentDefinitionsFactory
+ */
+ public ComponentDefinitionsFactory getFactory() {
+ return factory;
+ }
- /**
- * Create default Definition factory.
- * Factory must have a constructor taking ServletContext and Map as parameter.
- * In this implementation, default factory is of class I18nFactorySet
- * @param servletContext Servlet Context passed to newly created factory.
- * @param properties Map of name/property passed to newly created factory.
- * @return newly created factory.
- * @throws DefinitionsFactoryException If an error occur while initializing
factory
- */
- public ComponentDefinitionsFactory createDefaultFactory(ServletContext
servletContext, Map properties)
- throws DefinitionsFactoryException
- {
- ComponentDefinitionsFactory factory = new I18nFactorySet(servletContext,
properties); ;
- return factory;
- }
-
- /**
- * Create Definition factory.
- * Convenience method. ServletConfig is wrapped into a Map allowing retrieval
- * of init parameters. Factory classname is also retrieved, as well as debug
level.
- * Finally, approriate createDefinitionsFactory() is called.
- * @param servletContext Servlet Context passed to newly created factory.
- * @param properties Map containing all properties.
- */
- public ComponentDefinitionsFactory createFactory(ServletContext servletContext,
Map properties)
- throws DefinitionsFactoryException
- {
- String classname = (String)properties.get(DEFINITIONS_FACTORY_CLASSNAME);
- if(classname!=null)
- return createFactoryFromClassname( servletContext, properties, classname);
-
- return new I18nFactorySet( servletContext, properties );
- }
-
-
- /**
- * Get a definition by its name.
- * Call appropriate method on underlying factory instance.
- * Throw appropriate exception if definition or definition factory is not found.
- * @param definitionName Name of requested definition.
- * @param request Current servlet request.
- * @param servletContext Current servlet context.
- * @throws FactoryNotFoundException Can't find definition factory.
- * @throws DefinitionsFactoryException General error in factory while getting
definition.
- */
- public ComponentDefinition getDefinition(String definitionName, ServletRequest
request, ServletContext servletContext)
- throws FactoryNotFoundException, DefinitionsFactoryException
- {
- return factory.getDefinition(definitionName, (HttpServletRequest)request,
servletContext);
- }
-
- /**
- * Reload underlying factory.
- * Reload is done by creating a new factory instance, and replacing the old
instance
- * with the new one.
- * @param servletContext Current servlet context.
- * @throws DefinitionsFactoryException If factory creation fails.
- */
- public void reload(ServletContext servletContext)
- throws DefinitionsFactoryException
- {
- ComponentDefinitionsFactory newInstance = createFactory( servletContext,
properties);
- factory = newInstance;
- }
-
- /**
- * Get underlying factory instance.
- * @return ComponentDefinitionsFactory
- */
- public ComponentDefinitionsFactory getFactory()
- {
- return factory;
- }
-
- /**
- * Init factory.
- * This method is required by interface ComponentDefinitionsFactory. It is
- * not used in this implementation, as it manages itself the underlying creation
- * and initialization.
- * @param servletContext Servlet Context passed to newly created factory.
- * @param properties Map of name/property passed to newly created factory.
- * Map can contain more properties than requested.
- * @throws DefinitionsFactoryException An error occur during initialization.
- */
- public void initFactory(ServletContext servletContext, Map properties) throws
DefinitionsFactoryException
- { // do nothing
- }
-
- /**
- * Return String representation.
- * @return String representation.
+ /**
+ * Init factory.
+ * This method is required by interface ComponentDefinitionsFactory. It is
+ * not used in this implementation, as it manages itself the underlying
creation
+ * and initialization.
+ * @param servletContext Servlet Context passed to newly created factory.
+ * @param properties Map of name/property passed to newly created factory.
+ * Map can contain more properties than requested.
+ * @throws DefinitionsFactoryException An error occur during initialization.
*/
- public String toString()
- {
- return factory.toString();
- }
-
- /**
- * Inner class.
- * Wrapper for ServletContext init parameters.
- * Object of this class is an HashMap containing parameters and values
- * defined in the servlet config file (web.xml).
- */
- class ServletPropertiesMap extends HashMap {
+ public void initFactory(ServletContext servletContext, Map properties)
+ throws DefinitionsFactoryException {
+ // do nothing
+ }
+
/**
- * Constructor.
+ * Return String representation.
+ * @return String representation.
*/
- ServletPropertiesMap( ServletConfig config )
- {
- // This implementation is very simple.
- // It is possible to avoid creation of a new structure, but this would
- // imply writing all of the Map interface.
- Enumeration enum = config.getInitParameterNames();
- while( enum.hasMoreElements() )
- {
- String key = (String)enum.nextElement();
- put( key, config.getInitParameter( key ) );
- }
+ public String toString() {
+ return factory.toString();
}
-} // end inner class
+
+ /**
+ * Inner class.
+ * Wrapper for ServletContext init parameters.
+ * Object of this class is an HashMap containing parameters and values
+ * defined in the servlet config file (web.xml).
+ */
+ class ServletPropertiesMap extends HashMap {
+ /**
+ * Constructor.
+ */
+ ServletPropertiesMap(ServletConfig config) {
+ // This implementation is very simple.
+ // It is possible to avoid creation of a new structure, but this would
+ // imply writing all of the Map interface.
+ Enumeration enum = config.getInitParameterNames();
+ while (enum.hasMoreElements()) {
+ String key = (String) enum.nextElement();
+ put(key, config.getInitParameter(key));
+ }
+ }
+ } // end inner class
}
1.108 +8 -8
jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
Index: RequestUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -r1.107 -r1.108
--- RequestUtils.java 3 Jul 2003 01:47:05 -0000 1.107
+++ RequestUtils.java 4 Jul 2003 20:53:42 -0000 1.108
@@ -1699,7 +1699,7 @@
* @param prefix The module prefix of the desired module
* @param request The servlet request we are processing
* @param context The ServletContext for this web application
- * @since struts 1.1
+ * @since Struts 1.1
*/
public static void selectModule(
String prefix,
@@ -1801,7 +1801,7 @@
* @param request The servlet request we are processing
* @return the ModuleConfig object from request, or null if none is set in
* the request.
- * @since 1.1
+ * @since Struts 1.1
*/
public static ModuleConfig getRequestModuleConfig( HttpServletRequest request) {
return (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
@@ -1812,7 +1812,7 @@
* @param request The servlet request we are processing
* @param context The ServletContext for this web application
* @return the ModuleConfig object
- * @since 1.1
+ * @since Struts 1.1
*/
public static ModuleConfig getModuleConfig(
HttpServletRequest request,
@@ -1829,7 +1829,7 @@
* Return the ModuleConfig object if it exists, null if otherwise.
* @param pageContext The page context.
* @return the ModuleConfig object
- * @since 1.1
+ * @since Struts 1.1
*/
public static ModuleConfig getModuleConfig(PageContext pageContext) {
return getModuleConfig(
1.21 +203 -179
jakarta-struts/src/share/org/apache/struts/tiles/TilesPlugin.java
Index: TilesPlugin.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/tiles/TilesPlugin.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- TilesPlugin.java 17 Apr 2003 03:51:12 -0000 1.20
+++ TilesPlugin.java 4 Jul 2003 20:53:42 -0000 1.21
@@ -98,27 +98,35 @@
* The plugin should be declared in each struts-config.xml file in order to
* properly initialize the request processor.
* @author Cedric Dumoulin
- * @since 1.1
+ * @since Struts 1.1
*/
public class TilesPlugin implements PlugIn {
- /** Commons Logging instance. */
+ /**
+ * Commons Logging instance.
+ */
protected static Log log = LogFactory.getLog(TilesPlugin.class);
- /** Is the factory module aware ? */
+ /**
+ * Is the factory module aware ?
+ */
protected boolean moduleAware = false;
- /** Tiles util implementation classname. This property can be set
- * by user in the plugin declaration
- */
+ /**
+ * Tiles util implementation classname. This property can be set
+ * by user in the plugin declaration.
+ */
protected String tilesUtilImplClassname = null;
- /** Associated definition factory */
+ /**
+ * Associated definition factory.
+ */
protected DefinitionsFactory definitionFactory;
- /** The plugin config object provided by the ActionServlet initializing
- * this plugin.
- */
+ /**
+ * The plugin config object provided by the ActionServlet initializing
+ * this plugin.
+ */
protected PlugInConfig currentPlugInConfigObject;
/**
@@ -153,89 +161,96 @@
* @exception ServletException if this <code>PlugIn</code> cannot
* be successfully initialized.
*/
- public void init(ActionServlet servlet, ModuleConfig moduleConfig) throws
ServletException
- {
- // Create factory config object
- DefinitionsFactoryConfig factoryConfig = readFactoryConfig(servlet,
moduleConfig);
- // Set the module name in the config. This name will be used to compute
- // the name under which the factory is stored.
- factoryConfig.setFactoryName(moduleConfig.getPrefix());
- // Set RequestProcessor class
- initRequestProcessorClass(moduleConfig);
-
- // Set Tiles util implementation according to properties
'tilesUtilImplClassname'
- // and 'moduleAware'.
- // These properties are taken into account only once. A
- // side effect is that only the values set in the first initialized plugin
- // are effectively taken into account.
- if( !TilesUtil.isTilesUtilImplSet())
- { // TilesUtilImpl not set , do it
- // Check if user has specified a TilesUtil implementation classname or not.
- // If no implementation is specified, check if user has specified one
- // shared single factory for all module, or one factory for each module.
- if( getTilesUtilImplClassname() == null )
- { // No implementation specified, check if moduleAware is set
- if (isModuleAware())
- { // Use appropriate TilesUtil implementation
- TilesUtil.setTilesUtil(new TilesUtilStrutsModulesImpl());
- }
- else
- { // Use appropriate TilesUtil implementation
- TilesUtil.setTilesUtil(new TilesUtilStrutsImpl());
- }
- }
- else
- { // A classname is specified for the tilesUtilImp, use it.
- try
- {
- TilesUtilStrutsImpl impl =
- (TilesUtilStrutsImpl) RequestUtils
- .applicationClass(getTilesUtilImplClassname())
- .newInstance();
- TilesUtil.setTilesUtil(impl);
- }
- catch( ClassCastException ex )
- {
- throw new ServletException( "Can't set TilesUtil implementation to '"
- + getTilesUtilImplClassname()
- + "'. TilesUtil implementation should be a
subclass of '"
- + TilesUtilStrutsImpl.class.getName()
- + "'" );
- }
- catch( Exception ex )
- {
- throw new ServletException( "Can't set TilesUtil implementation.", ex );
- }
+ public void init(ActionServlet servlet, ModuleConfig moduleConfig)
+ throws ServletException {
+
+ // Create factory config object
+ DefinitionsFactoryConfig factoryConfig =
+ readFactoryConfig(servlet, moduleConfig);
+
+ // Set the module name in the config. This name will be used to compute
+ // the name under which the factory is stored.
+ factoryConfig.setFactoryName(moduleConfig.getPrefix());
+
+ // Set RequestProcessor class
+ initRequestProcessorClass(moduleConfig);
+
+ // Set Tiles util implementation according to properties
'tilesUtilImplClassname'
+ // and 'moduleAware'.
+ // These properties are taken into account only once. A
+ // side effect is that only the values set in the first initialized plugin
+ // are effectively taken into account.
+ if (!TilesUtil.isTilesUtilImplSet()) { // TilesUtilImpl not set , do it
+ // Check if user has specified a TilesUtil implementation classname or
not.
+ // If no implementation is specified, check if user has specified one
+ // shared single factory for all module, or one factory for each module.
+ if (getTilesUtilImplClassname() == null) {
+ // No implementation specified, check if moduleAware is set
+ if (isModuleAware()) { // Use appropriate TilesUtil implementation
+ TilesUtil.setTilesUtil(new TilesUtilStrutsModulesImpl());
+ } else { // Use appropriate TilesUtil implementation
+ TilesUtil.setTilesUtil(new TilesUtilStrutsImpl());
+ }
+ } else { // A classname is specified for the tilesUtilImp, use it.
+ try {
+ TilesUtilStrutsImpl impl =
+ (TilesUtilStrutsImpl) RequestUtils
+ .applicationClass(getTilesUtilImplClassname())
+ .newInstance();
+ TilesUtil.setTilesUtil(impl);
+
+ } catch (ClassCastException ex) {
+ throw new ServletException(
+ "Can't set TilesUtil implementation to '"
+ + getTilesUtilImplClassname()
+ + "'. TilesUtil implementation should be a subclass of
'"
+ + TilesUtilStrutsImpl.class.getName()
+ + "'");
+
+ } catch (Exception ex) {
+ throw new ServletException(
+ "Can't set TilesUtil implementation.",
+ ex);
+ }
+ } // end if
} // end if
- } // end if
+ // Check if a factory already exist for this module
+ definitionFactory =
+ ((TilesUtilStrutsImpl) TilesUtil.getTilesUtil()).getDefinitionsFactory(
+ servlet.getServletContext(),
+ moduleConfig);
+
+ if (definitionFactory != null) {
+ if (log.isInfoEnabled())
+ log.info(
+ "Factory already exists for module '"
+ + moduleConfig.getPrefix()
+ + "'. The factory found is from module '"
+ + definitionFactory.getConfig().getFactoryName()
+ + "'. No new creation.");
+ return;
+ }
- // Check if a factory already exist for this module
- definitionFactory =
((TilesUtilStrutsImpl)TilesUtil.getTilesUtil()).getDefinitionsFactory(servlet.getServletContext(),
moduleConfig);
- if (definitionFactory != null)
- {
- if (log.isInfoEnabled())
- log.info( "Factory already exists for module '"
- + moduleConfig.getPrefix()
- + "'. The factory found is from module '"
- + definitionFactory.getConfig().getFactoryName()
- + "'. No new creation.");
- return;
- } // end if
-
-
- // Create configurable factory
- try
- {
- definitionFactory =
TilesUtil.createDefinitionsFactory(servlet.getServletContext(), factoryConfig);
- }
- catch (DefinitionsFactoryException ex)
- {
- log.error("Can't create Tiles definition factory for module '" +
moduleConfig.getPrefix() + "'.");
- throw new ServletException(ex);
- }
+ // Create configurable factory
+ try {
+ definitionFactory =
+ TilesUtil.createDefinitionsFactory(
+ servlet.getServletContext(),
+ factoryConfig);
+
+ } catch (DefinitionsFactoryException ex) {
+ log.error(
+ "Can't create Tiles definition factory for module '"
+ + moduleConfig.getPrefix()
+ + "'.");
+ throw new ServletException(ex);
+ }
- log.info("Tiles definition factory loaded for module '" +
moduleConfig.getPrefix() + "'.");
+ log.info(
+ "Tiles definition factory loaded for module '"
+ + moduleConfig.getPrefix()
+ + "'.");
}
/**
@@ -256,39 +271,47 @@
* @exception ServletException if this <code>PlugIn</code> cannot
* be successfully initialized.
*/
- protected DefinitionsFactoryConfig readFactoryConfig( ActionServlet servlet,
ModuleConfig config)
- throws ServletException
- {
- // Create tiles definitions config object
- DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
- // Get init parameters from web.xml files
- try
- {
- DefinitionsUtil.populateDefinitionsFactoryConfig( factoryConfig,
servlet.getServletConfig());
- }
- catch (Exception ex)
- {
- if (log.isDebugEnabled())
- log.debug("", ex);
- ex.printStackTrace();
- throw new UnavailableException( "Can't populate DefinitionsFactoryConfig
class from 'web.xml': " + ex.getMessage());
- }
- // Get init parameters from struts-config.xml
- try
- {
- Map strutsProperties = findStrutsPlugInConfigProperties(servlet, config);
- factoryConfig.populate(strutsProperties);
- }
- catch (Exception ex)
- {
- if (log.isDebugEnabled())
- log.debug("", ex);
- throw new UnavailableException( "Can't populate DefinitionsFactoryConfig
class from '"
- + config.getPrefix()
- + "/struts-config.xml':"
- + ex.getMessage());
- }
- return factoryConfig;
+ protected DefinitionsFactoryConfig readFactoryConfig(
+ ActionServlet servlet,
+ ModuleConfig config)
+ throws ServletException {
+
+ // Create tiles definitions config object
+ DefinitionsFactoryConfig factoryConfig = new DefinitionsFactoryConfig();
+ // Get init parameters from web.xml files
+ try {
+ DefinitionsUtil.populateDefinitionsFactoryConfig(
+ factoryConfig,
+ servlet.getServletConfig());
+
+ } catch (Exception ex) {
+ if (log.isDebugEnabled()){
+ log.debug("", ex);
+ }
+ ex.printStackTrace();
+ throw new UnavailableException(
+ "Can't populate DefinitionsFactoryConfig class from 'web.xml': "
+ + ex.getMessage());
+ }
+
+ // Get init parameters from struts-config.xml
+ try {
+ Map strutsProperties = findStrutsPlugInConfigProperties(servlet,
config);
+ factoryConfig.populate(strutsProperties);
+
+ } catch (Exception ex) {
+ if (log.isDebugEnabled()) {
+ log.debug("", ex);
+ }
+
+ throw new UnavailableException(
+ "Can't populate DefinitionsFactoryConfig class from '"
+ + config.getPrefix()
+ + "/struts-config.xml':"
+ + ex.getMessage());
+ }
+
+ return factoryConfig;
}
/**
@@ -303,10 +326,12 @@
* @exception ServletException if this <code>PlugIn</code> cannot
* be successfully initialized.
*/
- protected Map findStrutsPlugInConfigProperties(ActionServlet servlet,
ModuleConfig config)
- throws ServletException
- {
- return currentPlugInConfigObject.getProperties();
+ protected Map findStrutsPlugInConfigProperties(
+ ActionServlet servlet,
+ ModuleConfig config)
+ throws ServletException {
+
+ return currentPlugInConfigObject.getProperties();
}
/**
@@ -319,46 +344,47 @@
* this plugin is associated.
* @throws ServletException On errors.
*/
- protected void initRequestProcessorClass(ModuleConfig config) throws
ServletException
- {
- String tilesProcessorClassname = TilesRequestProcessor.class.getName();
- ControllerConfig ctrlConfig = config.getControllerConfig();
- String configProcessorClassname = ctrlConfig.getProcessorClass();
-
- // Check if specified classname exist
- Class configProcessorClass;
- try
- {
- configProcessorClass = RequestUtils.applicationClass(
configProcessorClassname);
- }
- catch(java.lang.ClassNotFoundException ex)
- {
- log.fatal( "Can't set TilesRequestProcessor: bad class name '"
- + configProcessorClassname
- + "'.");
- throw new ServletException(ex);
- }
+ protected void initRequestProcessorClass(ModuleConfig config)
+ throws ServletException {
+
+ String tilesProcessorClassname = TilesRequestProcessor.class.getName();
+ ControllerConfig ctrlConfig = config.getControllerConfig();
+ String configProcessorClassname = ctrlConfig.getProcessorClass();
+
+ // Check if specified classname exist
+ Class configProcessorClass;
+ try {
+ configProcessorClass =
+ RequestUtils.applicationClass(configProcessorClassname);
+
+ } catch (ClassNotFoundException ex) {
+ log.fatal(
+ "Can't set TilesRequestProcessor: bad class name '"
+ + configProcessorClassname
+ + "'.");
+ throw new ServletException(ex);
+ }
- // Check if it is the default request processor or Tiles one.
- // If true, replace by Tiles' one.
- if(configProcessorClassname.equals(RequestProcessor.class.getName())
- || configProcessorClassname.endsWith(tilesProcessorClassname))
- {
- ctrlConfig.setProcessorClass(tilesProcessorClassname);
- return;
- }
-
- // Check if specified request processor is compatible with Tiles.
- Class tilesProcessorClass = TilesRequestProcessor.class;
- if(!tilesProcessorClass.isAssignableFrom(configProcessorClass))
- { // Not compatible
- String msg = "TilesPlugin : Specified RequestProcessor not compatible with
TilesRequestProcessor";
- if (log.isFatalEnabled())
- {
- log.fatal(msg);
+ // Check if it is the default request processor or Tiles one.
+ // If true, replace by Tiles' one.
+ if (configProcessorClassname.equals(RequestProcessor.class.getName())
+ || configProcessorClassname.endsWith(tilesProcessorClassname)) {
+
+ ctrlConfig.setProcessorClass(tilesProcessorClassname);
+ return;
+ }
+
+ // Check if specified request processor is compatible with Tiles.
+ Class tilesProcessorClass = TilesRequestProcessor.class;
+ if (!tilesProcessorClass.isAssignableFrom(configProcessorClass)) {
+ // Not compatible
+ String msg =
+ "TilesPlugin : Specified RequestProcessor not compatible with
TilesRequestProcessor";
+ if (log.isFatalEnabled()) {
+ log.fatal(msg);
+ }
+ throw new ServletException(msg);
}
- throw new ServletException(msg);
- } // end if
}
/**
@@ -366,27 +392,25 @@
* If this property is set, the flag <code>moduleAware</code> will not be used
anymore.
* @param tilesUtilImplClassname Classname.
*/
- public void setTilesUtilImplClassname(String tilesUtilImplClassname)
- {
- this.tilesUtilImplClassname = tilesUtilImplClassname;
- }
+ public void setTilesUtilImplClassname(String tilesUtilImplClassname) {
+ this.tilesUtilImplClassname = tilesUtilImplClassname;
+ }
+
/**
* Get Tiles util implemention classname.
* @return The classname or <code>null</code> if none is set.
*/
- public String getTilesUtilImplClassname()
- {
- return tilesUtilImplClassname;
- }
+ public String getTilesUtilImplClassname() {
+ return tilesUtilImplClassname;
+ }
/**
* Method used by the ActionServlet initializing this plugin.
* Set the plugin config object read from module config.
* @param plugInConfigObject PlugInConfig.
*/
- public void setCurrentPlugInConfigObject(PlugInConfig plugInConfigObject)
- {
- this.currentPlugInConfigObject = plugInConfigObject;
- }
+ public void setCurrentPlugInConfigObject(PlugInConfig plugInConfigObject) {
+ this.currentPlugInConfigObject = plugInConfigObject;
+ }
}
1.8 +92 -84
jakarta-struts/src/share/org/apache/struts/tiles/DefinitionsFactoryConfig.java
Index: DefinitionsFactoryConfig.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/tiles/DefinitionsFactoryConfig.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DefinitionsFactoryConfig.java 27 Feb 2003 19:20:51 -0000 1.7
+++ DefinitionsFactoryConfig.java 4 Jul 2003 20:53:42 -0000 1.8
@@ -59,10 +59,10 @@
*
*/
-
package org.apache.struts.tiles;
import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -75,18 +75,18 @@
* definition factory.
*
* @author Cedric Dumoulin
- * @since 1.1
+ * @since Struts 1.1
* @version $Revision$ $Date$
*/
-public class DefinitionsFactoryConfig implements Serializable
-{
+public class DefinitionsFactoryConfig implements Serializable {
/**
* Fully qualified classname of the factory to create.
* If no classname is set, a default factory is created
* (of class "org.apache.struts.tiles.xmlDefinition.I18nFactorySet").
*/
- protected String factoryClassname =
"org.apache.struts.tiles.xmlDefinition.I18nFactorySet";
+ protected String factoryClassname =
+ "org.apache.struts.tiles.xmlDefinition.I18nFactorySet";
/**
* Debug level value. 0=no debug info >0 = debug info.
@@ -106,8 +106,11 @@
* Default value is true.
*/
protected boolean parserValidate = true;
- /** Definition configuration file specified by user */
- protected String definitionConfigFiles;
+
+ /**
+ * Definition configuration file specified by user.
+ */
+ protected String definitionConfigFiles = null;
/**
* Specifies whether the factory is "module-aware".
@@ -124,15 +127,33 @@
*/
protected String factoryName;
- /** Alternate name for parser debug details properties in configuration file */
- public static final String PARSER_DETAILS_PARAMETER_NAME =
"definitions-parser-details";
- /** Alternate name for parser validate properties in configuration file */
- public static final String PARSER_VALIDATE_PARAMETER_NAME =
"definitions-parser-validate";
- /** Alternate name for factory classname properties in configuration file */
- public static final String FACTORY_CLASSNAME_PARAMETER_NAME =
"definitions-factory-class";
- /** Alternate name for definition files properties in configuration file */
- public static final String DEFINITIONS_CONFIG_PARAMETER_NAME =
"definitions-config";
- /** Alternate name for definition debug details properties in configuration
file */
+ /**
+ * Alternate name for parser debug details properties in configuration file.
+ */
+ public static final String PARSER_DETAILS_PARAMETER_NAME =
+ "definitions-parser-details";
+
+ /**
+ * Alternate name for parser validate properties in configuration file.
+ */
+ public static final String PARSER_VALIDATE_PARAMETER_NAME =
+ "definitions-parser-validate";
+
+ /**
+ * Alternate name for factory classname properties in configuration file.
+ */
+ public static final String FACTORY_CLASSNAME_PARAMETER_NAME =
+ "definitions-factory-class";
+
+ /**
+ * Alternate name for definition files properties in configuration file.
+ */
+ public static final String DEFINITIONS_CONFIG_PARAMETER_NAME =
+ "definitions-config";
+
+ /**
+ * Alternate name for definition debug details properties in configuration
file.
+ */
public static final String TILES_DETAILS_PARAMETER_NAME = "definitions-debug";
/**
@@ -143,9 +164,8 @@
/**
* Default constructor.
*/
- public DefinitionsFactoryConfig()
- {
-
+ public DefinitionsFactoryConfig() {
+ super();
}
/**
@@ -155,9 +175,8 @@
* attribute.
* @param initParameters Map.
*/
- public DefinitionsFactoryConfig(Map initParameters)
- {
-
+ public DefinitionsFactoryConfig(Map initParameters) {
+ super();
}
/**
@@ -165,8 +184,7 @@
* @return <code>true</code>: user wants a single factory instance,
* <code>false</code>: user wants multiple factory instances (one per module
with Struts)
*/
- public boolean isModuleAware()
- {
+ public boolean isModuleAware() {
return moduleAware;
}
/**
@@ -174,8 +192,7 @@
* @param moduleAware <code>true</code>: user wants a single factory instance,
* <code>false</code>: user wants multiple factory instances (one per module
with Struts)
*/
- public void setModuleAware(boolean moduleAware)
- {
+ public void setModuleAware(boolean moduleAware) {
this.moduleAware = moduleAware;
}
@@ -183,8 +200,7 @@
* Get the classname of the factory.
* @return Classname.
*/
- public String getFactoryClassname()
- {
+ public String getFactoryClassname() {
return factoryClassname;
}
@@ -192,8 +208,7 @@
* Set the classname of the factory..
* @param aFactoryClassname Classname of the factory.
*/
- public void setFactoryClassname(String aFactoryClassname)
- {
+ public void setFactoryClassname(String aFactoryClassname) {
factoryClassname = aFactoryClassname;
}
@@ -202,8 +217,7 @@
* @return Debug level.
* @deprecated Use commons-logging mechanism.
*/
- public int getDebugLevel()
- {
+ public int getDebugLevel() {
return debugLevel;
}
@@ -212,8 +226,7 @@
* @param aDebugLevel Debug level.
* @deprecated Use commons-logging mechanism.
*/
- public void setDebugLevel(int aDebugLevel)
- {
+ public void setDebugLevel(int aDebugLevel) {
debugLevel = aDebugLevel;
}
@@ -222,8 +235,7 @@
* @return Debug level.
* @deprecated Use commons-logging mechanism.
*/
- public int getParserDebugLevel()
- {
+ public int getParserDebugLevel() {
return parserDebugLevel;
}
@@ -232,8 +244,7 @@
* @param aParserDebugLevel Debug level.
* @deprecated Use commons-logging mechanism.
*/
- public void setParserDebugLevel(int aParserDebugLevel)
- {
+ public void setParserDebugLevel(int aParserDebugLevel) {
parserDebugLevel = aParserDebugLevel;
}
@@ -241,8 +252,7 @@
* Determines if the parser is validating.
* @return <code>true<code> when in validating mode.
*/
- public boolean getParserValidate()
- {
+ public boolean getParserValidate() {
return parserValidate;
}
@@ -250,8 +260,7 @@
* Set the validating mode for the parser.
* @param aParserValidate <code>true</code> for validation, <code>false</code>
otherwise
*/
- public void setParserValidate(boolean aParserValidate)
- {
+ public void setParserValidate(boolean aParserValidate) {
parserValidate = aParserValidate;
}
@@ -259,8 +268,7 @@
* Get the definition config files.
* @return Defition config files.
*/
- public String getDefinitionConfigFiles()
- {
+ public String getDefinitionConfigFiles() {
return definitionConfigFiles;
}
@@ -268,8 +276,7 @@
* Set the definition config files.
* @param aDefinitionConfigFiles Definition config files.
*/
- public void setDefinitionConfigFiles(String aDefinitionConfigFiles)
- {
+ public void setDefinitionConfigFiles(String aDefinitionConfigFiles) {
definitionConfigFiles = aDefinitionConfigFiles;
}
@@ -278,8 +285,7 @@
* @param name Name of the attribute.
* @param value Value of the attribute.
*/
- public void setAttribute(String name, Object value)
- {
+ public void setAttribute(String name, Object value) {
extraAttributes.put(name, value);
}
@@ -288,8 +294,7 @@
* @param name Name of the attribute.
* @return Value of the attribute, or null if not found.
*/
- public Object getAttribute(String name)
- {
+ public Object getAttribute(String name) {
return extraAttributes.get(name);
}
@@ -297,8 +302,7 @@
* Get additional attributes as a Map.
* @return Map A Map containing attribute name - value pairs.
*/
- public Map getAttributes()
- {
+ public Map getAttributes() {
Map map = new HashMap(extraAttributes);
// Add property attributes using old names
/*
@@ -306,7 +310,7 @@
map.put(TILES_DETAILS_PARAMETER_NAME, Integer.toString(getDebugLevel()) );
map.put(PARSER_DETAILS_PARAMETER_NAME,
Integer.toString(getParserDebugLevel()) );
map.put(PARSER_VALIDATE_PARAMETER_NAME, new
Boolean(getParserValidate()).toString() );
-
+
if( !
"org.apache.struts.tiles.xmlDefinition.I18nFactorySet".equals(getFactoryClassname()) )
map.put(FACTORY_CLASSNAME_PARAMETER_NAME, getFactoryClassname());
*/
@@ -337,16 +341,16 @@
*
* @exception IllegalAccessException if the caller does not have
* access to the property accessor method.
- * @exception java.lang.reflect.InvocationTargetException if the property
accessor method
+ * @exception InvocationTargetException if the property accessor method
* throws an exception.
* @see org.apache.commons.beanutils.BeanUtils
*/
- public void populate( Map properties)
- throws
java.lang.IllegalAccessException,java.lang.reflect.InvocationTargetException
- {
+ public void populate(Map properties)
+ throws IllegalAccessException, InvocationTargetException {
+
// link old parameter names for backward compatibility
linkOldPropertyNames(properties);
- BeanUtils.populate( this, properties);
+ BeanUtils.populate(this, properties);
}
/**
@@ -355,42 +359,46 @@
* @param properties Map keyed by property name, with the
* corresponding (String or String[]) value(s) to be set.
*/
- static public void linkOldPropertyNames( Map properties)
- {
+ static public void linkOldPropertyNames(Map properties) {
Set entries = properties.entrySet();
Map toAdd = new HashMap();
Iterator i = entries.iterator();
- while( i.hasNext() )
- {
- Map.Entry entry = (Map.Entry)i.next();
- if(DEFINITIONS_CONFIG_PARAMETER_NAME.equals(entry.getKey()))
- toAdd.put( "definitionConfigFiles", entry.getValue());
- else if(FACTORY_CLASSNAME_PARAMETER_NAME.equals(entry.getKey()))
- toAdd.put( "factoryClassname", entry.getValue());
- else if(PARSER_DETAILS_PARAMETER_NAME.equals(entry.getKey()))
- toAdd.put( "parserDebugLevel", entry.getValue());
- else if(PARSER_VALIDATE_PARAMETER_NAME.equals(entry.getKey()))
- toAdd.put( "parserValidate", entry.getValue());
- else if(TILES_DETAILS_PARAMETER_NAME.equals(entry.getKey()))
- toAdd.put( "debugLevel", entry.getValue());
- } // end loop
- if( toAdd.size() > 0 )
- properties.putAll( toAdd );
+ while (i.hasNext()) {
+ Map.Entry entry = (Map.Entry) i.next();
+
+ if (DEFINITIONS_CONFIG_PARAMETER_NAME.equals(entry.getKey())) {
+ toAdd.put("definitionConfigFiles", entry.getValue());
+
+ } else if (FACTORY_CLASSNAME_PARAMETER_NAME.equals(entry.getKey())) {
+ toAdd.put("factoryClassname", entry.getValue());
+
+ } else if (PARSER_DETAILS_PARAMETER_NAME.equals(entry.getKey())) {
+ toAdd.put("parserDebugLevel", entry.getValue());
+
+ } else if (PARSER_VALIDATE_PARAMETER_NAME.equals(entry.getKey())) {
+ toAdd.put("parserValidate", entry.getValue());
+
+ } else if (TILES_DETAILS_PARAMETER_NAME.equals(entry.getKey())) {
+ toAdd.put("debugLevel", entry.getValue());
+ }
+ }
+
+ if (toAdd.size() > 0) {
+ properties.putAll(toAdd);
+ }
}
/**
* Get the factory name.
*/
- public String getFactoryName()
- {
+ public String getFactoryName() {
return factoryName;
}
/**
* Set the factory name.
* @param factoryName Name of the factory.
*/
- public void setFactoryName(String factoryName)
- {
+ public void setFactoryName(String factoryName) {
this.factoryName = factoryName;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]