1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.tiles.context;
23
24 import java.util.Map;
25 import java.util.Stack;
26
27 import org.apache.tiles.Attribute;
28 import org.apache.tiles.AttributeContext;
29
30 /***
31 * Deprecated implementation for <code>AttributeContext</code>, maintained
32 * for compatibility reasons.
33 *
34 * @version $Rev: 784215 $ $Date: 2009-06-12 19:36:13 +0200 (ven, 12 giu 2009) $
35 * @deprecated Use {@link org.apache.tiles.BasicAttributeContext}.
36 */
37 @Deprecated
38 public class BasicAttributeContext extends
39 org.apache.tiles.BasicAttributeContext {
40
41 /***
42 * Name used to store attribute context stack.
43 */
44 private static final String ATTRIBUTE_CONTEXT_STACK =
45 "org.apache.tiles.AttributeContext.STACK";
46
47 /***
48 * Constructor.
49 */
50 public BasicAttributeContext() {
51 super();
52 }
53
54 /***
55 * Constructor.
56 * Create a context and set specified attributes.
57 *
58 * @param attributes Attributes to initialize context.
59 */
60 public BasicAttributeContext(Map<String, Attribute> attributes) {
61 super(attributes);
62 }
63
64 /***
65 * Copy constructor.
66 *
67 * @param context The constructor to copy.
68 */
69 public BasicAttributeContext(AttributeContext context) {
70 super(context);
71 }
72
73 /***
74 * Copy constructor.
75 *
76 * @param context The constructor to copy.
77 */
78 public BasicAttributeContext(BasicAttributeContext context) {
79 super(context);
80 }
81
82 /***
83 * Get attribute context from request.
84 *
85 * @param tilesContext current Tiles application context.
86 * @return BasicAttributeContext or null if context is not found.
87 * @deprecated Use {@link org.apache.tiles.TilesContainer#getAttributeContext(Object...)}.
88 */
89 @Deprecated
90 public static AttributeContext getContext(TilesRequestContext tilesContext) {
91 Stack<AttributeContext> contextStack = getContextStack(tilesContext);
92 if (!contextStack.isEmpty()) {
93 return contextStack.peek();
94 } else {
95 return null;
96 }
97 }
98
99 /***
100 * Returns the context stack.
101 *
102 * @param tilesContext The Tiles context object to use.
103 * @return The needed stack of contexts.
104 * @deprecated Use {@link org.apache.tiles.TilesContainer#getAttributeContext(Object...)},
105 * {@link org.apache.tiles.TilesContainer#startContext(Object...)} or
106 * {@link org.apache.tiles.TilesContainer#endContext(Object...)}.
107 */
108 @Deprecated
109 @SuppressWarnings("unchecked")
110 public static Stack<AttributeContext> getContextStack(TilesRequestContext tilesContext) {
111 Stack<AttributeContext> contextStack =
112 (Stack<AttributeContext>) tilesContext.getRequestScope().get(
113 BasicAttributeContext.ATTRIBUTE_CONTEXT_STACK);
114 if (contextStack == null) {
115 contextStack = new Stack<AttributeContext>();
116 tilesContext.getRequestScope().put(BasicAttributeContext.ATTRIBUTE_CONTEXT_STACK,
117 contextStack);
118 }
119
120 return contextStack;
121 }
122
123 /***
124 * Pushes a context object in the stack.
125 *
126 * @param context The context to push.
127 * @param tilesContext The Tiles context object to use.
128 * @deprecated Use {@link org.apache.tiles.TilesContainer#startContext(Object...)}.
129 */
130 @Deprecated
131 public static void pushContext(AttributeContext context,
132 TilesRequestContext tilesContext) {
133 Stack<AttributeContext> contextStack = getContextStack(tilesContext);
134 contextStack.push(context);
135 }
136
137 /***
138 * Pops a context object out of the stack.
139 *
140 * @param tilesContext The Tiles context object to use.
141 * @return The popped context object.
142 * @deprecated Use {@link org.apache.tiles.TilesContainer#endContext(Object...)}.
143 */
144 @Deprecated
145 public static AttributeContext popContext(TilesRequestContext tilesContext) {
146 Stack<AttributeContext> contextStack = getContextStack(tilesContext);
147 return contextStack.pop();
148 }
149 }