You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2007/02/05 12:03:18 UTC

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

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());
         }



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

Posted by Antonio Petrelli <an...@gmail.com>.
Ok I am reopening TILES-100 and working on it, thank you :-)

Antonio

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

Posted by "David H. DeWolf" <dd...@apache.org>.
agreed. push at the beginning of the invocation and pop at the end.

Antonio Petrelli wrote:
> 2007/2/5, David H. DeWolf <dd...@apache.org>:
>> But wouldn't it be better to simply modify the container to
>> appropriately scope the attributes?
>> For intance, could there be a stack
>> that we pop off when the attributes get out of scope?
> 
> I think that you need to call some methods to "push" (at tag's start)
> and "pop" (at tags end) the corresponding ComponentContext.
> If it is the case, you're right, the solution is cleaner (and
> <tiles:insertTemplate> will work better I suppose).
> 
> Antonio
> 

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

Posted by Antonio Petrelli <an...@gmail.com>.
2007/2/5, David H. DeWolf <dd...@apache.org>:
> But wouldn't it be better to simply modify the container to
> appropriately scope the attributes?
> For intance, could there be a stack
> that we pop off when the attributes get out of scope?

I think that you need to call some methods to "push" (at tag's start)
and "pop" (at tags end) the corresponding ComponentContext.
If it is the case, you're right, the solution is cleaner (and
<tiles:insertTemplate> will work better I suppose).

Antonio

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

Posted by "David H. DeWolf" <dd...@apache.org>.
But wouldn't it be better to simply modify the container to 
appropriately scope the attributes?  For intance, could there be a stack 
that we pop off when the attributes get out of scope?  I guess I don't 
see what this problem requires additional container methods.  It should 
be handled internally, not by requiring every client to use it.

David

Antonio Petrelli wrote:
> 2007/2/5, David H. DeWolf <dd...@apache.org>:
>> 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 attributes to the
>> existing context?
> 
> The answer is almost completely here:
> http://issues.apache.org/struts/browse/TILES-96
> If you put an attribute using <tiles:putAttribute> every attribute
> with the same name will be overridden, instead of working only inside
> their parent tag.
> I think that the methods without the ComponentContext parameters are
> of no use (at least they are not used inside JSP tags).
> I added a new test link in the test webapp ("Test Insert Configured
> Definition with an overridden content and one with original content").
> 
> Antonio
> 

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

Posted by Antonio Petrelli <an...@gmail.com>.
2007/2/5, David H. DeWolf <dd...@apache.org>:
> 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 attributes to the
> existing context?

The answer is almost completely here:
http://issues.apache.org/struts/browse/TILES-96
If you put an attribute using <tiles:putAttribute> every attribute
with the same name will be overridden, instead of working only inside
their parent tag.
I think that the methods without the ComponentContext parameters are
of no use (at least they are not used inside JSP tags).
I added a new test link in the test webapp ("Test Insert Configured
Definition with an overridden content and one with original content").

Antonio

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

Posted by "David H. DeWolf" <dd...@apache.org>.
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 attributes to the 
existing context?

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());
>          }
> 
> 
> 

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

Posted by "David H. DeWolf" <dd...@apache.org>.
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());
>          }
> 
> 
>