tiles-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David H. DeWolf" <ddew...@apache.org>
Subject Re: svn commit: r503628 - in /tiles/framework/trunk: tiles-api/src/main/java/org/apache/tiles/TilesContainer.java tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
Date Mon, 05 Feb 2007 12:24:27 GMT
Antonio,

I'm starting to get a *little* concerned that our container interface is 
becoming more verbose than it needs to be.  Can you explain the use case 
for the additions below and why we can't just add/remove attributes to 
the existing context to meet the requirement?

David

apetrelli@apache.org wrote:
> Author: apetrelli
> Date: Mon Feb  5 03:03:16 2007
> New Revision: 503628
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=503628
> Log:
> TILES-100
> Added "render" and "prepare" methods that support the use of a custom ComponentContext.
> Added "createComponentContext" methods for the creation of a new ComponentContext.
> 
> Modified:
>     tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java
>     tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
> 
> Modified: tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java
> URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java?view=diff&rev=503628&r1=503627&r2=503628
> ==============================================================================
> --- tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java
(original)
> +++ tiles/framework/trunk/tiles-api/src/main/java/org/apache/tiles/TilesContainer.java
Mon Feb  5 03:03:16 2007
> @@ -68,6 +68,21 @@
>      ComponentContext getComponentContext(PageContext context);
>  
>      /**
> +     * Creates a new component context from the current request
> +     * @param context the current request.
> +     * @return map of the attributes in the current component context.
> +     */
> +    ComponentContext createComponentContext(PageContext context);
> +
> +    /**
> +     * Creates a new component context from the current request
> +     * @param request the current request.
> +     * @param response the current reponse.
> +     * @return map of the attributes in the current component context.
> +     */
> +    ComponentContext createComponentContext(Object request, Object response);
> +
> +    /**
>       * @param request the current request
>       * @param response the current response
>       * @param definition the requested definition
> @@ -84,6 +99,25 @@
>  
>  
>      /**
> +     * @param request the current request
> +     * @param response the current response
> +     * @param componentContext the current component context
> +     * @param definition the requested definition
> +     * @throws TilesException is processing fails.
> +     */
> +    void prepare(Object request, Object response, ComponentContext componentContext,
> +    		String definition) throws TilesException;
> +
> +    /**
> +     * @param pageContext the current pageContext
> +     * @param definition the current definition
> +     * @param componentContext the current component context
> +     * @throws TilesException is processing fails.
> +     */
> +    void prepare(PageContext pageContext, ComponentContext componentContext,
> +    		String definition) throws TilesException;
> +
> +    /**
>       * Render the given tiles request
>       *
>       * @param request the current request
> @@ -108,6 +142,34 @@
>       */
>      void render(PageContext pageContext, ComponentAttribute attribute)
>          throws TilesException, IOException;
> +
> +    /**
> +     * Render the given tiles request
> +     *
> +     * @param request the current request
> +     * @param response the current response
> +     * @param definition the current definition
> +     * @throws TilesException is processing fails.
> +     */
> +    void render(Object request, Object response, ComponentContext componentContext,
> +    		String definition) throws TilesException;
> +
> +    /**
> +     * @param pageContext the current pageContext.
> +     * @param definition the requested definition.
> +     * @throws TilesException is processing fails.
> +     */
> +    void render(PageContext pageContext, ComponentContext componentContext,
> +    		String definition) throws TilesException;
> +
> +    /**
> +     * Render the given ComponentAttribute.
> +     * @param pageContext
> +     * @param attribute
> +     * @throws TilesException
> +     */
> +    void render(PageContext pageContext, ComponentContext componentContext,
> +    		ComponentAttribute attribute) throws TilesException, IOException;
>  
>      /**
>       * Determine whether or not the definition exists.
> 
> Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
> URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java?view=diff&rev=503628&r1=503627&r2=503628
> ==============================================================================
> --- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
(original)
> +++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
Mon Feb  5 03:03:16 2007
> @@ -182,6 +182,16 @@
>          return getComponentContext(tilesContext);
>      }
>  
> +    public ComponentContext createComponentContext(Object request, Object response)
{
> +		ComponentContext componentContext = getComponentContext(request, response);
> +		return new BasicComponentContext(componentContext);
> +	}
> +
> +	public ComponentContext createComponentContext(PageContext context) {
> +		ComponentContext componentContext = getComponentContext(context);
> +		return new BasicComponentContext(componentContext);
> +	}
> +
>      private ComponentContext getComponentContext(TilesRequestContext tilesContext) {
>          ComponentContext context = BasicComponentContext.getContext(tilesContext);
>          if (context == null) {
> @@ -191,7 +201,7 @@
>          return context;
>      }
>  
> -    private TilesRequestContext getRequestContext(Object request, Object response) {
> +	private TilesRequestContext getRequestContext(Object request, Object response) {
>          return getContextFactory().createRequestContext(
>              getApplicationContext(),
>              request,
> @@ -258,11 +268,23 @@
>      public void prepare(Object request, Object response, String preparer)
>          throws TilesException {
>          TilesRequestContext requestContext = getContextFactory().createRequestContext(
> +                getApplicationContext(),
> +                request,
> +                response
> +            );
> +        ComponentContext componentContext = BasicComponentContext.getContext(requestContext);
> +        prepare(requestContext, componentContext, preparer, false);
> +    }
> +
> +    public void prepare(Object request, Object response,
> +    		ComponentContext componentContext, String preparer)
> +        throws TilesException {
> +        TilesRequestContext requestContext = getContextFactory().createRequestContext(
>              getApplicationContext(),
>              request,
>              response
>          );
> -        prepare(requestContext, preparer, false);
> +        prepare(requestContext, componentContext, preparer, false);
>      }
>  
>      public void prepare(PageContext context, String preparer)
> @@ -270,10 +292,21 @@
>          TilesRequestContext requestContext = getContextFactory().createRequestContext(
>              getApplicationContext(), context
>          );
> -        prepare(requestContext, preparer, false);
> +        ComponentContext componentContext = BasicComponentContext.getContext(requestContext);
> +        prepare(requestContext, componentContext, preparer, false);
> +    }
> +
> +    public void prepare(PageContext context,
> +    		ComponentContext componentContext, String preparer)
> +        throws TilesException {
> +        TilesRequestContext requestContext = getContextFactory().createRequestContext(
> +            getApplicationContext(), context
> +        );
> +        prepare(requestContext, componentContext, preparer, false);
>      }
>  
> -    private void prepare(TilesRequestContext context, String preparerName, boolean ignoreMissing)
> +	private void prepare(TilesRequestContext context,
> +			ComponentContext componentContext, String preparerName, boolean ignoreMissing)
>          throws TilesException {
>  
>          if (LOG.isDebugEnabled()) {
> @@ -289,8 +322,6 @@
>              throw new NoSuchPreparerException("Preparer '" + preparerName + " not found");
>          }
>  
> -        ComponentContext componentContext = BasicComponentContext.getContext(context);
> -
>          // TODO: Temporary while preparerInstance gets refactored to throw a more specific
exception.
>          try {
>              preparer.execute(context, componentContext);
> @@ -312,7 +343,8 @@
>              request,
>              response
>          );
> -        render(requestContext, definitionName);
> +        ComponentContext componentContext = getComponentContext(requestContext);
> +        render(requestContext, componentContext, definitionName);
>      }
>  
>      public void render(PageContext context, String definitionName)
> @@ -320,10 +352,37 @@
>          TilesRequestContext requestContext = getContextFactory().createRequestContext(
>              getApplicationContext(), context
>          );
> -        render(requestContext, definitionName);
> +        ComponentContext componentContext = getComponentContext(requestContext);
> +        render(requestContext, componentContext, definitionName);
>      }
>  
> -    private void render(TilesRequestContext request, String definitionName)
> +    /**
> +     * Render the specified definition.
> +     *
> +     * @param request the TilesRequestContext
> +     * @throws TilesException
> +     */
> +    public void render(Object request, Object response,
> +    		ComponentContext componentContext, String definitionName)
> +        throws TilesException {
> +        TilesRequestContext requestContext = getContextFactory().createRequestContext(
> +            getApplicationContext(),
> +            request,
> +            response
> +        );
> +        render(requestContext, componentContext, definitionName);
> +    }
> +
> +    public void render(PageContext context, ComponentContext componentContext,
> +    		String definitionName)
> +        throws TilesException {
> +        TilesRequestContext requestContext = getContextFactory().createRequestContext(
> +            getApplicationContext(), context
> +        );
> +        render(requestContext, componentContext, definitionName);
> +    }
> +
> +    private void render(TilesRequestContext request, ComponentContext originalContext,
String definitionName)
>          throws TilesException {
>  
>          if (LOG.isDebugEnabled()) {
> @@ -346,14 +405,13 @@
>              return;
>          }
>  
> -        ComponentContext originalContext = getComponentContext(request);
>          BasicComponentContext subContext = new BasicComponentContext(originalContext);
>          subContext.addMissing(definition.getAttributes());
>          BasicComponentContext.setContext(subContext, request);
>  
>          try {
>              if (definition.getPreparer() != null) {
> -                prepare(request, definition.getPreparer(), true);
> +                prepare(request, subContext, definition.getPreparer(), true);
>              }
>  
>              String dispatchPath = definition.getTemplate();
> @@ -379,6 +437,12 @@
>      public void render(PageContext pageContext, ComponentAttribute attr)
>          throws TilesException, IOException {
>          ComponentContext context = getComponentContext(pageContext);
> +        render(pageContext, context, attr);
> +    }
> +
> +    public void render(PageContext pageContext, ComponentContext componentContext,
> +    		ComponentAttribute attr)
> +        throws TilesException, IOException {
>          TilesRequestContext request = getRequestContext(pageContext);
>  
>          String type = calculateType(pageContext, attr);
> @@ -391,12 +455,12 @@
>          Map<String, ComponentAttribute> attrs = attr.getAttributes();
>          if (attrs != null) {
>              for (Map.Entry<String, ComponentAttribute> a : attrs.entrySet()) {
> -                context.putAttribute(a.getKey(), a.getValue());
> +                componentContext.putAttribute(a.getKey(), a.getValue());
>              }
>          }
>  
>          if (isDefinition(pageContext, attr)) {
> -            render(request, attr.getValue().toString());
> +            render(request, componentContext, attr.getValue().toString());
>          } else {
>              request.include(attr.getValue().toString());
>          }
> 
> 
> 

Mime
View raw message