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 2008/01/29 20:40:36 UTC

svn commit: r616498 - in /tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles: context/BasicAttributeContext.java impl/BasicTilesContainer.java

Author: apetrelli
Date: Tue Jan 29 11:40:35 2008
New Revision: 616498

URL: http://svn.apache.org/viewvc?rev=616498&view=rev
Log:
TILES-242
Merge from trunk to TILES_2_0_X branch.
Deprecated static methods in BasicAttributeContext.

Modified:
    tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
    tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java

Modified: tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java?rev=616498&r1=616497&r2=616498&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java Tue Jan 29 11:40:35 2008
@@ -178,7 +178,9 @@
      * @param tilesContext current Tiles application context.
      * @return BasicAttributeContext or null if context is not found or an
      *         jspException is present in the request.
+     * @deprecated Use {@link TilesContainer#getAttributeContext(Object...)}.
      */
+    @Deprecated
     public static AttributeContext getContext(TilesRequestContext tilesContext) {
         Stack<AttributeContext> contextStack = getContextStack(tilesContext);
         if (!contextStack.isEmpty()) {
@@ -193,7 +195,11 @@
      *
      * @param tilesContext The Tiles context object to use.
      * @return The needed stack of contexts.
+     * @deprecated Use {@link TilesContainer#getAttributeContext(Object...)},
+     * {@link TilesContainer#startContext(Object...)} or
+     * {@link TilesContainer#endContext(Object...)}.
      */
+    @Deprecated
     @SuppressWarnings("unchecked")
     public static Stack<AttributeContext> getContextStack(TilesRequestContext tilesContext) {
         Stack<AttributeContext> contextStack =
@@ -213,7 +219,9 @@
      *
      * @param context The context to push.
      * @param tilesContext The Tiles context object to use.
+     * @deprecated Use {@link TilesContainer#startContext(Object...)}.
      */
+    @Deprecated
     public static void pushContext(AttributeContext context,
             TilesRequestContext tilesContext) {
         Stack<AttributeContext> contextStack = getContextStack(tilesContext);
@@ -225,6 +233,7 @@
      *
      * @param tilesContext The Tiles context object to use.
      * @return The popped context object.
+     * @deprecated Use {@link TilesContainer#endContext(Object...)}.
      */
     public static AttributeContext popContext(TilesRequestContext tilesContext) {
         Stack<AttributeContext> contextStack = getContextStack(tilesContext);

Modified: tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
URL: http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java?rev=616498&r1=616497&r2=616498&view=diff
==============================================================================
--- tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java (original)
+++ tiles/framework/branches/TILES_2_0_X/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java Tue Jan 29 11:40:35 2008
@@ -47,6 +47,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.Stack;
 import java.util.StringTokenizer;
 
 /**
@@ -74,6 +75,12 @@
     private static final String LEGACY_DEFINITIONS_CONFIG = "definitions-config";
 
     /**
+     * Name used to store attribute context stack.
+     */
+    private static final String ATTRIBUTE_CONTEXT_STACK =
+        "org.apache.tiles.AttributeContext.STACK";
+
+    /**
      * Log instance for all BasicTilesContainer
      * instances.
      */
@@ -404,16 +411,75 @@
     }
 
     /**
+     * Returns the context stack.
+     *
+     * @param tilesContext The Tiles context object to use.
+     * @return The needed stack of contexts.
+     */
+    @SuppressWarnings("unchecked")
+    protected Stack<AttributeContext> getContextStack(TilesRequestContext tilesContext) {
+        Stack<AttributeContext> contextStack =
+            (Stack<AttributeContext>) tilesContext
+                .getRequestScope().get(ATTRIBUTE_CONTEXT_STACK);
+        if (contextStack == null) {
+            contextStack = new Stack<AttributeContext>();
+            tilesContext.getRequestScope().put(ATTRIBUTE_CONTEXT_STACK,
+                    contextStack);
+        }
+
+        return contextStack;
+    }
+
+    /**
+     * Pushes a context object in the stack.
+     *
+     * @param context The context to push.
+     * @param tilesContext The Tiles context object to use.
+     */
+    protected void pushContext(AttributeContext context,
+            TilesRequestContext tilesContext) {
+        Stack<AttributeContext> contextStack = getContextStack(tilesContext);
+        contextStack.push(context);
+    }
+
+    /**
+     * Pops a context object out of the stack.
+     *
+     * @param tilesContext The Tiles context object to use.
+     * @return The popped context object.
+     */
+    protected AttributeContext popContext(TilesRequestContext tilesContext) {
+        Stack<AttributeContext> contextStack = getContextStack(tilesContext);
+        return contextStack.pop();
+    }
+
+    /**
+     * Get attribute context from request.
+     *
+     * @param tilesContext current Tiles application context.
+     * @return BasicAttributeContext or null if context is not found or an
+     *         jspException is present in the request.
+     */
+    protected AttributeContext getContext(TilesRequestContext tilesContext) {
+        Stack<AttributeContext> contextStack = getContextStack(tilesContext);
+        if (!contextStack.isEmpty()) {
+            return contextStack.peek();
+        } else {
+            return null;
+        }
+    }
+
+    /**
      * Returns the current attribute context.
      *
      * @param tilesContext The request context to use.
      * @return The current attribute context.
      */
     private AttributeContext getAttributeContext(TilesRequestContext tilesContext) {
-        AttributeContext context = BasicAttributeContext.getContext(tilesContext);
+        AttributeContext context = getContext(tilesContext);
         if (context == null) {
             context = new BasicAttributeContext();
-            BasicAttributeContext.pushContext(context, tilesContext);
+            pushContext(context, tilesContext);
         }
         return context;
     }
@@ -439,7 +505,7 @@
      */
     private AttributeContext startContext(TilesRequestContext tilesContext) {
         AttributeContext context = new BasicAttributeContext();
-        BasicAttributeContext.pushContext(context, tilesContext);
+        pushContext(context, tilesContext);
         return context;
     }
 
@@ -449,7 +515,7 @@
      * @param tilesContext The request context to use.
      */
     private void endContext(TilesRequestContext tilesContext) {
-        BasicAttributeContext.popContext(tilesContext);
+        popContext(tilesContext);
     }
 
     /**
@@ -479,7 +545,7 @@
             throw new NoSuchPreparerException("Preparer '" + preparerName + " not found");
         }
 
-        AttributeContext attributeContext = BasicAttributeContext.getContext(context);
+        AttributeContext attributeContext = getContext(context);
 
         preparer.execute(context, attributeContext);
     }
@@ -520,7 +586,7 @@
         AttributeContext originalContext = getAttributeContext(request);
         BasicAttributeContext subContext = new BasicAttributeContext(originalContext);
         subContext.addMissing(definition.getAttributes());
-        BasicAttributeContext.pushContext(subContext, request);
+        pushContext(subContext, request);
 
         try {
             if (definition.getPreparer() != null) {
@@ -543,7 +609,7 @@
             // TODO it would be nice to make the preparerInstance throw a more specific
             throw new TilesException(e.getMessage(), e);
         } finally {
-            BasicAttributeContext.popContext(request);
+            popContext(request);
         }
     }