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:37:01 UTC
svn commit: r616494 - in
/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles:
context/BasicAttributeContext.java impl/BasicTilesContainer.java
Author: apetrelli
Date: Tue Jan 29 11:36:57 2008
New Revision: 616494
URL: http://svn.apache.org/viewvc?rev=616494&view=rev
Log:
TILES-242
Deprecated static methods in BasicAttributeContext.
Modified:
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/impl/BasicTilesContainer.java
Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java?rev=616494&r1=616493&r2=616494&view=diff
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/BasicAttributeContext.java Tue Jan 29 11:36:57 2008
@@ -261,7 +261,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()) {
@@ -276,7 +278,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 =
@@ -296,7 +302,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);
@@ -308,6 +316,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/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?rev=616494&r1=616493&r2=616494&view=diff
==============================================================================
--- 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 Tue Jan 29 11:36:57 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);
}
}