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 wrappedContext = null;
46      
47      /**
48       * CTOR, wraps an ICA
49       * @param inner context
50       */
51      public ChainedInternalContextAdapter(InternalContextAdapter inner)
52      {
53          wrappedContext = inner;
54      }
55      
56      /**
57       * Return the inner / user context.
58       * @return The inner / user context.
59       */
60      public Context getInternalUserContext()
61      {
62          return wrappedContext.getInternalUserContext();
63      }
64  
65      /**
66       * @see org.apache.velocity.context.InternalWrapperContext#getBaseContext()
67       */
68      public InternalContextAdapter getBaseContext()
69      {
70          return wrappedContext.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 wrappedContext.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 wrappedContext.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 wrappedContext.containsKey(key);
105     }
106 
107     /**
108      * @see org.apache.velocity.context.Context#getKeys()
109      */
110     public Object[] getKeys()
111     {
112         return wrappedContext.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 wrappedContext.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         wrappedContext.pushCurrentTemplateName(s);
129     }
130 
131     /**
132      * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentTemplateName()
133      */
134     public void popCurrentTemplateName()
135     {
136         wrappedContext.popCurrentTemplateName();
137     }
138 
139     /**
140      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentTemplateName()
141      */
142     public String getCurrentTemplateName()
143     {
144         return wrappedContext.getCurrentTemplateName();
145     }
146 
147     /**
148      * @see org.apache.velocity.context.InternalHousekeepingContext#getTemplateNameStack()
149      */
150     public Object[] getTemplateNameStack()
151     {
152         return wrappedContext.getTemplateNameStack();
153     }
154 
155     /**
156      * @see org.apache.velocity.context.InternalHousekeepingContext#pushCurrentMacroName(java.lang.String)
157      */
158     public void pushCurrentMacroName(String s)
159     {
160         wrappedContext.pushCurrentMacroName(s);
161     }
162 
163     /**
164      * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentMacroName()
165      */
166     public void popCurrentMacroName()
167     {
168         wrappedContext.popCurrentMacroName();
169     }
170 
171     /**
172      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroName()
173      */
174     public String getCurrentMacroName()
175     {
176         return wrappedContext.getCurrentMacroName();
177     }
178 
179     /**
180      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroCallDepth()
181      */
182     public int getCurrentMacroCallDepth()
183     {
184         return wrappedContext.getCurrentMacroCallDepth();
185     }
186 
187     /**
188      * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroNameStack()
189      */
190     public Object[] getMacroNameStack()
191     {
192         return wrappedContext.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 wrappedContext.icacheGet(key);
201     }
202 
203     /**
204      * @see org.apache.velocity.context.InternalHousekeepingContext#icachePut(java.lang.Object, org.apache.velocity.util.introspection.IntrospectionCacheData)
205      */
206     public void icachePut(Object key, IntrospectionCacheData o)
207     {
208         wrappedContext.icachePut(key, o);
209     }
210 
211     /**
212      * @see org.apache.velocity.context.InternalHousekeepingContext#setMacroLibraries(List)
213      */
214     public void setMacroLibraries(List macroLibraries)
215     {
216         wrappedContext.setMacroLibraries(macroLibraries);
217     }
218     
219     /**
220      * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroLibraries()
221      */
222     public List getMacroLibraries()
223     {
224         return wrappedContext.getMacroLibraries();
225     }
226 
227     /**
228      * @see org.apache.velocity.context.InternalEventContext#attachEventCartridge(org.apache.velocity.app.event.EventCartridge)
229      */
230     public EventCartridge attachEventCartridge(EventCartridge ec)
231     {
232         return wrappedContext.attachEventCartridge(ec);
233     }
234 
235     /**
236      * @see org.apache.velocity.context.InternalEventContext#getEventCartridge()
237      */
238     public EventCartridge getEventCartridge()
239     {
240         return wrappedContext.getEventCartridge();
241     }
242 
243 
244     /**
245      * @see org.apache.velocity.context.InternalHousekeepingContext#setCurrentResource(org.apache.velocity.runtime.resource.Resource)
246      */
247     public void setCurrentResource(Resource r)
248     {
249         wrappedContext.setCurrentResource(r);
250     }
251 
252     /**
253      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentResource()
254      */
255     public Resource getCurrentResource()
256     {
257         return wrappedContext.getCurrentResource();
258     }
259 }