struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David H. DeWolf" <ddew...@apache.org>
Subject [tiles2] Re: svn commit: r488006 - in /struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles: factory/TilesContainerFactory.java impl/BasicTilesContainer.java
Date Tue, 19 Dec 2006 13:26:07 GMT
Antonio,

I'm not sure I understand why we need to support both the context and a 
map of defaults for retrieving config info for factories.  It seems 
redundant and thus confusing.

If we want to use a map, shouldn't we just remove the context all 
together and have the client push all of the init parameters into the 
map prior to invocation?

Thoughts?

David

apetrelli@apache.org wrote:
> Author: apetrelli
> Date: Sun Dec 17 08:50:35 2006
> New Revision: 488006
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=488006
> Log:
> SB-101
> Refactorings to allow easier inheritance.
> 
> Modified:
>     struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
>     struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
> 
> Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
> URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java?view=diff&rev=488006&r1=488005&r2=488006
> ==============================================================================
> --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
(original)
> +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/factory/TilesContainerFactory.java
Sun Dec 17 08:50:35 2006
> @@ -93,8 +93,28 @@
>       */
>      public static TilesContainerFactory getFactory(Object context)
>          throws TilesException {
> +        return getFactory(context, DEFAULTS);
> +    }
> +
> +    /**
> +     * Retrieve a factory instance as configured through the
> +     * specified context.
> +     * <p/>
> +     * The context will be queried and if a init parameter
> +     * named 'org.apache.tiles.CONTAINER_FACTORY' is discovered
> +     * this class will be instantiated and returned. Otherwise,
> +     * the factory will attempt to utilize one of it's internal
> +     * factories.
> +     *
> +     * @param context the executing applications context.
> +     *                Typically a ServletContext or PortletContext
> +     * @return a tiles container
> +     * @throws TilesException if an error occurs creating the factory.
> +     */
> +    public static TilesContainerFactory getFactory(Object context,
> +    		Map<String, String> defaults) throws TilesException {
>          return (TilesContainerFactory) TilesContainerFactory
> -            .createFactory(context, CONTAINER_FACTORY_INIT_PARAM);
> +            .createFactory(context, CONTAINER_FACTORY_INIT_PARAM, defaults);
>      }
>  
>      public TilesContainer createContainer(Object context) throws TilesException {
> @@ -108,30 +128,44 @@
>  
>      public TilesContainer createTilesContainer(Object context)
>          throws TilesException {
> +        return createTilesContainer(context, DEFAULTS);
> +    }
> +
> +    public TilesContainer createTilesContainer(Object context,
> +    		Map<String, String> defaults) throws TilesException {
>          BasicTilesContainer container = new BasicTilesContainer();
> -        initializeContainer(context, container);
> +        initializeContainer(context, container, defaults);
>          return container;
>      }
>  
>      public MutableTilesContainer createMutableTilesContainer(Object context)
>          throws TilesException {
> +    	return createMutableTilesContainer(context, DEFAULTS);
> +    }
> +
> +    public MutableTilesContainer createMutableTilesContainer(Object context,
> +    		Map<String, String> defaults) throws TilesException {
>          CachingTilesContainer container = new CachingTilesContainer();
> -        initializeContainer(context, container);
> +        initializeContainer(context, container, defaults);
>          return container;
>      }
>  
> -    public void initializeContainer(Object context,
> -                                    BasicTilesContainer container)
> +    protected void initializeContainer(Object context,
> +                                    BasicTilesContainer container,
> +                                    Map<String, String> defaults)
>          throws TilesException {
>  
>          TilesContextFactory contextFactory =
> -            (TilesContextFactory) createFactory(context, CONTEXT_FACTORY_INIT_PARAM);
> +            (TilesContextFactory) createFactory(context,
> +            		CONTEXT_FACTORY_INIT_PARAM, defaults);
>  
>          DefinitionsFactory defsFactory =
> -            (DefinitionsFactory) createFactory(context, DEFINITIONS_FACTORY_INIT_PARAM);
> +            (DefinitionsFactory) createFactory(context,
> +            		DEFINITIONS_FACTORY_INIT_PARAM, defaults);
>  
>          PreparerFactory prepFactory =
> -            (PreparerFactory) createFactory(context, PREPARER_FACTORY_INIT_PARAM);
> +            (PreparerFactory) createFactory(context,
> +            		PREPARER_FACTORY_INIT_PARAM, defaults);
>  
>          TilesApplicationContext tilesContext =
>              contextFactory.createApplicationContext(context);
> @@ -168,15 +202,21 @@
>      }
>  
>  
> -    public static Object createFactory(Object context, String initParameterName)
> +    protected static Object createFactory(Object context,
> +    		String initParameterName, Map<String, String> defaults)
>          throws TilesException {
> -        String factoryName = resolveFactoryName(context, initParameterName);
> +        String factoryName = resolveFactoryName(context, initParameterName,
> +        		defaults);
>          return ClassUtil.instantiate(factoryName);
>      }
>  
> -    public static String resolveFactoryName(Object context, String parameterName)
> +    protected static String resolveFactoryName(Object context,
> +    		String parameterName, Map<String, String> defaults)
>          throws TilesException {
>          Object factoryName = getInitParameter(context, parameterName);
> +        if (factoryName == null && defaults != null) {
> +        	factoryName = defaults.get(parameterName);
> +        }
>          return factoryName == null
>              ? DEFAULTS.get(parameterName)
>              : factoryName.toString();
> 
> Modified: struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
> URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java?view=diff&rev=488006&r1=488005&r2=488006
> ==============================================================================
> --- struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
(original)
> +++ struts/sandbox/trunk/tiles/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
Sun Dec 17 08:50:35 2006
> @@ -101,12 +101,42 @@
>          }
>  
>          contextFactory.init(initParameters);
> -        definitionsFactory.init(initParameters);
>  
>          //Everything is now initialized.  We will populate
>          // our definitions
> -        String resourceString = getResourceString();
> +        initializeDefinitionsFactory(definitionsFactory, getResourceString(),
> +        		initParameters);
> +    }
> +
> +    /**
> +     * Determine whether or not the container has been
> +     * initialized. Utility method used for methods which
> +     * can not be invoked after the container has been
> +     * started.
> +     *
> +     * @throws IllegalStateException if the container has already been initialized.
> +     */
> +    protected void checkInit() {
> +        if (initialized) {
> +            throw new IllegalStateException("Container allready initialized");
> +        }
> +    }
> +    
> +    /**
> +     * Initializes a definitions factory.
> +     *
> +     * @param definitionsFactory The factory to initializes. 
> +     * @param resourceString The string containing a comma-separated-list of
> +     * resources.
> +     * @param initParameters A map containing the initialization parameters.
> +     * @throws TilesException If something goes wrong.
> +     */
> +    protected void initializeDefinitionsFactory(
> +    		DefinitionsFactory definitionsFactory, String resourceString,
> +    		Map<String, String> initParameters) throws TilesException {
>          List<String> resources = getResourceNames(resourceString);
> +        definitionsFactory.init(initParameters);
> +        
>          try {
>              for (String resource : resources) {
>                  URL resourceUrl = context.getResource(resource);
> @@ -129,20 +159,6 @@
>      }
>  
>      /**
> -     * Determine whether or not the container has been
> -     * initialized. Utility method used for methods which
> -     * can not be invoked after the container has been
> -     * started.
> -     *
> -     * @throws IllegalStateException if the container has already been initialized.
> -     */
> -    private void checkInit() {
> -        if (initialized) {
> -            throw new IllegalStateException("Container allready initialized");
> -        }
> -    }
> -
> -    /**
>       * Standard Getter
>       *
>       * @return the application context for this container.
> @@ -442,7 +458,19 @@
>       * @return resource string to be parsed.
>       */
>      protected String getResourceString() {
> -        Map<String, String> parms = context.getInitParams();
> +        return getResourceString(context.getInitParams());
> +    }
> +
> +    /**
> +     * Derive the resource string from the initialization parameters.
> +     * If no parameter {@link #DEFINITIONS_CONFIG} is available, attempts
> +     * to retrieve {@link #LEGACY_DEFINITIONS_CONFIG}.  If niether are
> +     * available, returns "/WEB-INF/tiles.xml".
> +     *
> +     * @param parms The initialization parameters.
> +     * @return resource string to be parsed.
> +     */
> +    protected String getResourceString(Map<String, String> parms) {
>          String resourceStr = parms.get(DEFINITIONS_CONFIG);
>          if (resourceStr == null) {
>              resourceStr = parms.get(LEGACY_DEFINITIONS_CONFIG);
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message