View Javadoc

1   package org.apache.velocity.context;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import java.util.List;
23  
24  import org.apache.velocity.app.event.EventCartridge;
25  import org.apache.velocity.runtime.resource.Resource;
26  import org.apache.velocity.util.introspection.IntrospectionCacheData;
27  
28  /**
29   * This is an abstract internal-use-only context implementation to be
30   * used as a subclass for other internal-use-only contexts that wrap
31   * other internal-use-only contexts.
32   *
33   * We use this context to make it easier to chain an existing context
34   * as part of a new context implementation.  It just delegates everything
35   * to the inner/parent context. Subclasses then only need to override
36   * the methods relevant to them.
37   *
38   * @author Nathan Bubna
39   * @version $Id: ChainedInternalContextAdapter.java 685724 2008-08-13 23:12:12Z nbubna $
40   * @since 1.6
41   */
42  public abstract class ChainedInternalContextAdapter implements InternalContextAdapter
43  {
44      /** the parent context */
45      protected InternalContextAdapter innerContext = null;
46      
47      /**
48       * CTOR, wraps an ICA
49       * @param inner context
50       */
51      public ChainedInternalContextAdapter(InternalContextAdapter inner)
52      {
53          innerContext = inner;
54      }
55      
56      /**
57       * Return the inner / user context.
58       * @return The inner / user context.
59       */
60      public Context getInternalUserContext()
61      {
62          return innerContext.getInternalUserContext();
63      }
64  
65      /**
66       * @see org.apache.velocity.context.InternalWrapperContext#getBaseContext()
67       */
68      public InternalContextAdapter getBaseContext()
69      {
70          return innerContext.getBaseContext();
71      }
72  
73      /**
74       * Retrieves from parent context.
75       *
76       * @param key name of item to get
77       * @return  stored object or null
78       */
79      public Object get(String key)
80      {
81          return innerContext.get(key);
82      }
83  
84      /**
85       * Put method also stores values in parent context
86       *
87       * @param key name of item to set
88       * @param value object to set to key
89       * @return old stored object
90       */
91      public Object put(String key, Object value)
92      {
93          /*
94           * just put in the local context
95           */
96          return innerContext.put(key, value);
97      }
98  
99      /**
100      * @see org.apache.velocity.context.Context#containsKey(java.lang.Object)
101      */
102     public boolean containsKey(Object key)
103     {
104         return innerContext.containsKey(key);
105     }
106 
107     /**
108      * @see org.apache.velocity.context.Context#getKeys()
109      */
110     public Object[] getKeys()
111     {
112         return innerContext.getKeys();
113     }
114 
115     /**
116      * @see org.apache.velocity.context.Context#remove(java.lang.Object)
117      */
118     public Object remove(Object key)
119     {
120         return innerContext.remove(key);
121     }
122 
123     /**
124      * @see org.apache.velocity.context.InternalHousekeepingContext#pushCurrentTemplateName(java.lang.String)
125      */
126     public void pushCurrentTemplateName(String s)
127     {
128         innerContext.pushCurrentTemplateName(s);
129     }
130 
131     /**
132      * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentTemplateName()
133      */
134     public void popCurrentTemplateName()
135     {
136         innerContext.popCurrentTemplateName();
137     }
138 
139     /**
140      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentTemplateName()
141      */
142     public String getCurrentTemplateName()
143     {
144         return innerContext.getCurrentTemplateName();
145     }
146 
147     /**
148      * @see org.apache.velocity.context.InternalHousekeepingContext#getTemplateNameStack()
149      */
150     public Object[] getTemplateNameStack()
151     {
152         return innerContext.getTemplateNameStack();
153     }
154 
155     /**
156      * @see org.apache.velocity.context.InternalHousekeepingContext#pushCurrentMacroName(java.lang.String)
157      */
158     public void pushCurrentMacroName(String s)
159     {
160         innerContext.pushCurrentMacroName(s);
161     }
162 
163     /**
164      * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentMacroName()
165      */
166     public void popCurrentMacroName()
167     {
168         innerContext.popCurrentMacroName();
169     }
170 
171     /**
172      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroName()
173      */
174     public String getCurrentMacroName()
175     {
176         return innerContext.getCurrentMacroName();
177     }
178 
179     /**
180      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroCallDepth()
181      */
182     public int getCurrentMacroCallDepth()
183     {
184         return innerContext.getCurrentMacroCallDepth();
185     }
186 
187     /**
188      * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroNameStack()
189      */
190     public Object[] getMacroNameStack()
191     {
192         return innerContext.getMacroNameStack();
193     }
194 
195     /**
196      * @see org.apache.velocity.context.InternalHousekeepingContext#icacheGet(java.lang.Object)
197      */
198     public IntrospectionCacheData icacheGet(Object key)
199     {
200         return innerContext.icacheGet(key);
201     }
202 
203     /**
204      * @see org.apache.velocity.context.InternalWrapperContext#localPut(java.lang.String,java.lang.Object)
205      */
206     public Object localPut(final String key, final Object value)
207     {
208         return innerContext.put(key, value);
209     }
210 
211     /**
212      * @see org.apache.velocity.context.InternalHousekeepingContext#icachePut(java.lang.Object, org.apache.velocity.util.introspection.IntrospectionCacheData)
213      */
214     public void icachePut(Object key, IntrospectionCacheData o)
215     {
216         innerContext.icachePut(key, o);
217     }
218 
219     /**
220      * @see org.apache.velocity.context.InternalHousekeepingContext#setMacroLibraries(List)
221      */
222     public void setMacroLibraries(List macroLibraries)
223     {
224         innerContext.setMacroLibraries(macroLibraries);
225     }
226     
227     /**
228      * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroLibraries()
229      */
230     public List getMacroLibraries()
231     {
232         return innerContext.getMacroLibraries();
233     }
234 
235     /**
236      * @see org.apache.velocity.context.InternalEventContext#attachEventCartridge(org.apache.velocity.app.event.EventCartridge)
237      */
238     public EventCartridge attachEventCartridge(EventCartridge ec)
239     {
240         return innerContext.attachEventCartridge(ec);
241     }
242 
243     /**
244      * @see org.apache.velocity.context.InternalEventContext#getEventCartridge()
245      */
246     public EventCartridge getEventCartridge()
247     {
248         return innerContext.getEventCartridge();
249     }
250 
251 
252     /**
253      * @see org.apache.velocity.context.InternalHousekeepingContext#setCurrentResource(org.apache.velocity.runtime.resource.Resource)
254      */
255     public void setCurrentResource(Resource r)
256     {
257         innerContext.setCurrentResource(r);
258     }
259 
260     /**
261      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentResource()
262      */
263     public Resource getCurrentResource()
264     {
265         return innerContext.getCurrentResource();
266     }
267 }