• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 org.apache.velocity.Template;
23 import org.apache.velocity.app.event.EventCartridge;
24 import org.apache.velocity.runtime.resource.Resource;
25 import org.apache.velocity.util.introspection.IntrospectionCacheData;
26 
27 import java.util.List;
28 
29 /**
30  * This is an abstract internal-use-only context implementation to be
31  * used as a subclass for other internal-use-only contexts that wrap
32  * other internal-use-only contexts.
33  *
34  * We use this context to make it easier to chain an existing context
35  * as part of a new context implementation.  It just delegates everything
36  * to the inner/parent context. Subclasses then only need to override
37  * the methods relevant to them.
38  *
39  * @author Nathan Bubna
40  * @version $Id: ChainedInternalContextAdapter.java 685724 2008-08-13 23:12:12Z nbubna $
41  * @since 1.6
42  */
43 public abstract class ChainedInternalContextAdapter implements InternalContextAdapter
44 {
45     /** the parent context */
46     protected InternalContextAdapter wrappedContext = null;
47 
48     /**
49      * CTOR, wraps an ICA
50      * @param inner context
51      */
ChainedInternalContextAdapter(InternalContextAdapter inner)52     public ChainedInternalContextAdapter(InternalContextAdapter inner)
53     {
54         wrappedContext = inner;
55     }
56 
57     /**
58      * Return the inner / user context.
59      * @return The inner / user context.
60      */
61     @Override
getInternalUserContext()62     public Context getInternalUserContext()
63     {
64         return wrappedContext.getInternalUserContext();
65     }
66 
67     /**
68      * @see org.apache.velocity.context.InternalWrapperContext#getBaseContext()
69      */
70     @Override
getBaseContext()71     public InternalContextAdapter getBaseContext()
72     {
73         return wrappedContext.getBaseContext();
74     }
75 
76     /**
77      * Retrieves from parent context.
78      *
79      * @param key name of item to get
80      * @return  stored object or null
81      */
82     @Override
get(String key)83     public Object get(String key)
84     {
85         return wrappedContext.get(key);
86     }
87 
88     /**
89      * Put method also stores values in parent context
90      *
91      * @param key name of item to set
92      * @param value object to set to key
93      * @return old stored object
94      */
95     @Override
put(String key, Object value)96     public Object put(String key, Object value)
97     {
98         /*
99          * just put in the local context
100          */
101         return wrappedContext.put(key, value);
102     }
103 
104     /**
105      * @see org.apache.velocity.context.Context#containsKey(java.lang.String)
106      */
107     @Override
containsKey(String key)108     public boolean containsKey(String key)
109     {
110         return wrappedContext.containsKey(key);
111     }
112 
113     /**
114      * @see org.apache.velocity.context.Context#getKeys()
115      */
116     @Override
getKeys()117     public String[] getKeys()
118     {
119         return wrappedContext.getKeys();
120     }
121 
122     /**
123      * @see org.apache.velocity.context.Context#remove(java.lang.String)
124      */
125     @Override
remove(String key)126     public Object remove(String key)
127     {
128         return wrappedContext.remove(key);
129     }
130 
131     /**
132      * @see org.apache.velocity.context.InternalHousekeepingContext#pushCurrentTemplateName(java.lang.String)
133      */
134     @Override
pushCurrentTemplateName(String s)135     public void pushCurrentTemplateName(String s)
136     {
137         wrappedContext.pushCurrentTemplateName(s);
138     }
139 
140     /**
141      * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentTemplateName()
142      */
143     @Override
popCurrentTemplateName()144     public void popCurrentTemplateName()
145     {
146         wrappedContext.popCurrentTemplateName();
147     }
148 
149     /**
150      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentTemplateName()
151      */
152     @Override
getCurrentTemplateName()153     public String getCurrentTemplateName()
154     {
155         return wrappedContext.getCurrentTemplateName();
156     }
157 
158     /**
159      * @see org.apache.velocity.context.InternalHousekeepingContext#getTemplateNameStack()
160      */
161     @Override
getTemplateNameStack()162     public String[] getTemplateNameStack()
163     {
164         return wrappedContext.getTemplateNameStack();
165     }
166 
167     /**
168      * @see org.apache.velocity.context.InternalHousekeepingContext#pushCurrentMacroName(java.lang.String)
169      */
170     @Override
pushCurrentMacroName(String s)171     public void pushCurrentMacroName(String s)
172     {
173         wrappedContext.pushCurrentMacroName(s);
174     }
175 
176     /**
177      * @see org.apache.velocity.context.InternalHousekeepingContext#popCurrentMacroName()
178      */
179     @Override
popCurrentMacroName()180     public void popCurrentMacroName()
181     {
182         wrappedContext.popCurrentMacroName();
183     }
184 
185     /**
186      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroName()
187      */
188     @Override
getCurrentMacroName()189     public String getCurrentMacroName()
190     {
191         return wrappedContext.getCurrentMacroName();
192     }
193 
194     /**
195      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentMacroCallDepth()
196      */
197     @Override
getCurrentMacroCallDepth()198     public int getCurrentMacroCallDepth()
199     {
200         return wrappedContext.getCurrentMacroCallDepth();
201     }
202 
203     /**
204      * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroNameStack()
205      */
206     @Override
getMacroNameStack()207     public String[] getMacroNameStack()
208     {
209         return wrappedContext.getMacroNameStack();
210     }
211 
212     /**
213      * @see org.apache.velocity.context.InternalHousekeepingContext#icacheGet(java.lang.Object)
214      */
215     @Override
icacheGet(Object key)216     public IntrospectionCacheData icacheGet(Object key)
217     {
218         return wrappedContext.icacheGet(key);
219     }
220 
221     /**
222      * @see org.apache.velocity.context.InternalHousekeepingContext#icachePut(java.lang.Object, org.apache.velocity.util.introspection.IntrospectionCacheData)
223      */
224     @Override
icachePut(Object key, IntrospectionCacheData o)225     public void icachePut(Object key, IntrospectionCacheData o)
226     {
227         wrappedContext.icachePut(key, o);
228     }
229 
230     /**
231      * @see org.apache.velocity.context.InternalHousekeepingContext#setMacroLibraries(List)
232      */
233     @Override
setMacroLibraries(List<Template> macroLibraries)234     public void setMacroLibraries(List<Template> macroLibraries)
235     {
236         wrappedContext.setMacroLibraries(macroLibraries);
237     }
238 
239     /**
240      * @see org.apache.velocity.context.InternalHousekeepingContext#getMacroLibraries()
241      */
242     @Override
getMacroLibraries()243     public List<Template> getMacroLibraries()
244     {
245         return wrappedContext.getMacroLibraries();
246     }
247 
248     /**
249      * @see org.apache.velocity.context.InternalEventContext#attachEventCartridge(org.apache.velocity.app.event.EventCartridge)
250      */
251     @Override
attachEventCartridge(EventCartridge ec)252     public EventCartridge attachEventCartridge(EventCartridge ec)
253     {
254         return wrappedContext.attachEventCartridge(ec);
255     }
256 
257     /**
258      * @see org.apache.velocity.context.InternalEventContext#getEventCartridge()
259      */
260     @Override
getEventCartridge()261     public EventCartridge getEventCartridge()
262     {
263         return wrappedContext.getEventCartridge();
264     }
265 
266 
267     /**
268      * @see org.apache.velocity.context.InternalHousekeepingContext#setCurrentResource(org.apache.velocity.runtime.resource.Resource)
269      */
270     @Override
setCurrentResource(Resource r)271     public void setCurrentResource(Resource r)
272     {
273         wrappedContext.setCurrentResource(r);
274     }
275 
276     /**
277      * @see org.apache.velocity.context.InternalHousekeepingContext#getCurrentResource()
278      */
279     @Override
getCurrentResource()280     public Resource getCurrentResource()
281     {
282         return wrappedContext.getCurrentResource();
283     }
284 }
285