Package org.apache.velocity.context
Class InternalContextAdapterImpl
- java.lang.Object
-
- org.apache.velocity.context.InternalContextAdapterImpl
-
- All Implemented Interfaces:
Context
,InternalContextAdapter
,InternalEventContext
,InternalHousekeepingContext
,InternalWrapperContext
public final class InternalContextAdapterImpl extends java.lang.Object implements InternalContextAdapter
This adapter class is the container for all context types for internal use. The AST now uses this class rather than the app-level Context interface to allow flexibility in the future. Currently, we have two context interfaces which must be supported :- Context : used for application/template data access
- InternalHousekeepingContext : used for internal housekeeping and caching
- InternalWrapperContext : used for getting root cache context and other such.
- InternalEventContext : for event handling.
- Version:
- $Id: InternalContextAdapterImpl.java 731266 2009-01-04 15:11:20Z byron $
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Context
context
the user data Context that we are wrapping(package private) InternalHousekeepingContext
icb
the ICB we are wrapping.(package private) InternalEventContext
iec
The InternalEventContext that we are wrapping.
-
Constructor Summary
Constructors Constructor Description InternalContextAdapterImpl(Context c)
CTOR takes a Context and wraps it, delegating all 'data' calls to it.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EventCartridge
attachEventCartridge(EventCartridge ec)
boolean
containsKey(java.lang.Object key)
Indicates whether the specified key is in the context.java.lang.Object
get(java.lang.String key)
Gets the value corresponding to the provided key from the context.InternalContextAdapter
getBaseContext()
Returns the base context that we are wrapping.int
getCurrentMacroCallDepth()
get the current macro call depthjava.lang.String
getCurrentMacroName()
get the current macro nameResource
getCurrentResource()
temporary fix to enable #include() to figure out current encoding.java.lang.String
getCurrentTemplateName()
get the current template nameEventCartridge
getEventCartridge()
Context
getInternalUserContext()
returns the user data context that we are wrappingjava.lang.Object[]
getKeys()
Get all the keys for the values in the context.java.util.List
getMacroLibraries()
Get the macro library list for the current template.java.lang.Object[]
getMacroNameStack()
Returns the macro name stack in form of an array.java.lang.Object[]
getTemplateNameStack()
Returns the template name stack in form of an array.IntrospectionCacheData
icacheGet(java.lang.Object key)
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the keyvoid
icachePut(java.lang.Object key, IntrospectionCacheData o)
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified keyjava.lang.Object
localPut(java.lang.String key, java.lang.Object value)
Allows callers to explicitly put objects in the local context.void
popCurrentMacroName()
remove the current macro name from stackvoid
popCurrentTemplateName()
remove the current template name from stackvoid
pushCurrentMacroName(java.lang.String s)
set the current macro name on top of stackvoid
pushCurrentTemplateName(java.lang.String s)
set the current template name on top of stackjava.lang.Object
put(java.lang.String key, java.lang.Object value)
Adds a name/value pair to the context.java.lang.Object
remove(java.lang.Object key)
Removes the value associated with the specified key from the context.void
setCurrentResource(Resource r)
void
setMacroLibraries(java.util.List macroLibraries)
Set the macro library list for the current template.
-
-
-
Field Detail
-
context
Context context
the user data Context that we are wrapping
-
icb
InternalHousekeepingContext icb
the ICB we are wrapping. We may need to make one if the user data context implementation doesn't support one. The default AbstractContext-derived VelocityContext does, and it's recommended that people derive new contexts from AbstractContext rather than piecing things together
-
iec
InternalEventContext iec
The InternalEventContext that we are wrapping. If the context passed to us doesn't support it, no biggie. We don't make it for them - since its a user context thing, nothing gained by making one for them now
-
-
Constructor Detail
-
InternalContextAdapterImpl
public InternalContextAdapterImpl(Context c)
CTOR takes a Context and wraps it, delegating all 'data' calls to it. For support of internal contexts, it will create an InternalContextBase if need be.- Parameters:
c
-
-
-
Method Detail
-
pushCurrentTemplateName
public void pushCurrentTemplateName(java.lang.String s)
Description copied from interface:InternalHousekeepingContext
set the current template name on top of stack- Specified by:
pushCurrentTemplateName
in interfaceInternalHousekeepingContext
- Parameters:
s
- current template name- See Also:
InternalHousekeepingContext.pushCurrentTemplateName(java.lang.String)
-
popCurrentTemplateName
public void popCurrentTemplateName()
Description copied from interface:InternalHousekeepingContext
remove the current template name from stack- Specified by:
popCurrentTemplateName
in interfaceInternalHousekeepingContext
- See Also:
InternalHousekeepingContext.popCurrentTemplateName()
-
getCurrentTemplateName
public java.lang.String getCurrentTemplateName()
Description copied from interface:InternalHousekeepingContext
get the current template name- Specified by:
getCurrentTemplateName
in interfaceInternalHousekeepingContext
- Returns:
- String current template name
- See Also:
InternalHousekeepingContext.getCurrentTemplateName()
-
getTemplateNameStack
public java.lang.Object[] getTemplateNameStack()
Description copied from interface:InternalHousekeepingContext
Returns the template name stack in form of an array.- Specified by:
getTemplateNameStack
in interfaceInternalHousekeepingContext
- Returns:
- Object[] with the template name stack contents.
- See Also:
InternalHousekeepingContext.getTemplateNameStack()
-
pushCurrentMacroName
public void pushCurrentMacroName(java.lang.String s)
Description copied from interface:InternalHousekeepingContext
set the current macro name on top of stack- Specified by:
pushCurrentMacroName
in interfaceInternalHousekeepingContext
- Parameters:
s
- current macro name- Since:
- 1.6
- See Also:
InternalHousekeepingContext.pushCurrentMacroName(java.lang.String)
-
popCurrentMacroName
public void popCurrentMacroName()
Description copied from interface:InternalHousekeepingContext
remove the current macro name from stack- Specified by:
popCurrentMacroName
in interfaceInternalHousekeepingContext
- Since:
- 1.6
- See Also:
InternalHousekeepingContext.popCurrentMacroName()
-
getCurrentMacroName
public java.lang.String getCurrentMacroName()
Description copied from interface:InternalHousekeepingContext
get the current macro name- Specified by:
getCurrentMacroName
in interfaceInternalHousekeepingContext
- Returns:
- String current macro name
- Since:
- 1.6
- See Also:
InternalHousekeepingContext.getCurrentMacroName()
-
getCurrentMacroCallDepth
public int getCurrentMacroCallDepth()
Description copied from interface:InternalHousekeepingContext
get the current macro call depth- Specified by:
getCurrentMacroCallDepth
in interfaceInternalHousekeepingContext
- Returns:
- int current macro call depth
- Since:
- 1.6
- See Also:
InternalHousekeepingContext.getCurrentMacroCallDepth()
-
getMacroNameStack
public java.lang.Object[] getMacroNameStack()
Description copied from interface:InternalHousekeepingContext
Returns the macro name stack in form of an array.- Specified by:
getMacroNameStack
in interfaceInternalHousekeepingContext
- Returns:
- Object[] with the macro name stack contents.
- Since:
- 1.6
- See Also:
InternalHousekeepingContext.getMacroNameStack()
-
icacheGet
public IntrospectionCacheData icacheGet(java.lang.Object key)
Description copied from interface:InternalHousekeepingContext
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key- Specified by:
icacheGet
in interfaceInternalHousekeepingContext
- Parameters:
key
- key to find in cache- Returns:
- cache object
- See Also:
InternalHousekeepingContext.icacheGet(java.lang.Object)
-
icachePut
public void icachePut(java.lang.Object key, IntrospectionCacheData o)
Description copied from interface:InternalHousekeepingContext
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key- Specified by:
icachePut
in interfaceInternalHousekeepingContext
- Parameters:
key
- keyo
- IntrospectionCacheData object to place in cache- See Also:
InternalHousekeepingContext.icachePut(java.lang.Object, org.apache.velocity.util.introspection.IntrospectionCacheData)
-
setCurrentResource
public void setCurrentResource(Resource r)
- Specified by:
setCurrentResource
in interfaceInternalHousekeepingContext
- See Also:
InternalHousekeepingContext.setCurrentResource(org.apache.velocity.runtime.resource.Resource)
-
getCurrentResource
public Resource getCurrentResource()
Description copied from interface:InternalHousekeepingContext
temporary fix to enable #include() to figure out current encoding.- Specified by:
getCurrentResource
in interfaceInternalHousekeepingContext
- Returns:
- The current resource.
- See Also:
InternalHousekeepingContext.getCurrentResource()
-
setMacroLibraries
public void setMacroLibraries(java.util.List macroLibraries)
Description copied from interface:InternalHousekeepingContext
Set the macro library list for the current template.- Specified by:
setMacroLibraries
in interfaceInternalHousekeepingContext
- Parameters:
macroLibraries
- list of macro libraries to set- Since:
- 1.6
- See Also:
InternalHousekeepingContext.setMacroLibraries(List)
-
getMacroLibraries
public java.util.List getMacroLibraries()
Description copied from interface:InternalHousekeepingContext
Get the macro library list for the current template.- Specified by:
getMacroLibraries
in interfaceInternalHousekeepingContext
- Returns:
- List of macro library names
- Since:
- 1.6
- See Also:
InternalHousekeepingContext.getMacroLibraries()
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)
Description copied from interface:Context
Adds a name/value pair to the context.- Specified by:
put
in interfaceContext
- Parameters:
key
- The name to key the provided value with.value
- The corresponding value.- Returns:
- The old object or null if there was no old object.
- See Also:
Context.put(java.lang.String, java.lang.Object)
-
localPut
public java.lang.Object localPut(java.lang.String key, java.lang.Object value)
Description copied from interface:InternalWrapperContext
Allows callers to explicitly put objects in the local context. Objects added to the context through this method always end up in the top-level context of possible wrapped contexts.- Specified by:
localPut
in interfaceInternalWrapperContext
- Parameters:
key
- name of item to set.value
- object to set to key.- Returns:
- old stored object
- Since:
- 1.5
- See Also:
InternalWrapperContext.localPut(String, Object)
-
get
public java.lang.Object get(java.lang.String key)
Description copied from interface:Context
Gets the value corresponding to the provided key from the context.- Specified by:
get
in interfaceContext
- Parameters:
key
- The name of the desired value.- Returns:
- The value corresponding to the provided key.
- See Also:
Context.get(java.lang.String)
-
containsKey
public boolean containsKey(java.lang.Object key)
Description copied from interface:Context
Indicates whether the specified key is in the context.- Specified by:
containsKey
in interfaceContext
- Parameters:
key
- The key to look for.- Returns:
- Whether the key is in the context.
- See Also:
Context.containsKey(java.lang.Object)
-
getKeys
public java.lang.Object[] getKeys()
Description copied from interface:Context
Get all the keys for the values in the context.- Specified by:
getKeys
in interfaceContext
- Returns:
- All the keys for the values in the context.
- See Also:
Context.getKeys()
-
remove
public java.lang.Object remove(java.lang.Object key)
Description copied from interface:Context
Removes the value associated with the specified key from the context.- Specified by:
remove
in interfaceContext
- Parameters:
key
- The name of the value to remove.- Returns:
- The value that the key was mapped to, or
null
if unmapped. - See Also:
Context.remove(java.lang.Object)
-
getInternalUserContext
public Context getInternalUserContext()
returns the user data context that we are wrapping- Specified by:
getInternalUserContext
in interfaceInternalWrapperContext
- Returns:
- The internal user data context.
-
getBaseContext
public InternalContextAdapter getBaseContext()
Returns the base context that we are wrapping. Here, its this, but for other thing like VM related context contortions, it can be something else- Specified by:
getBaseContext
in interfaceInternalWrapperContext
- Returns:
- The base context.
-
attachEventCartridge
public EventCartridge attachEventCartridge(EventCartridge ec)
- Specified by:
attachEventCartridge
in interfaceInternalEventContext
- Returns:
- The old EventCartridge.
- See Also:
InternalEventContext.attachEventCartridge(org.apache.velocity.app.event.EventCartridge)
-
getEventCartridge
public EventCartridge getEventCartridge()
- Specified by:
getEventCartridge
in interfaceInternalEventContext
- Returns:
- The current EventCartridge.
- See Also:
InternalEventContext.getEventCartridge()
-
-