org.apache.velocity.context
Class InternalContextAdapterImpl

java.lang.Object
  extended by org.apache.velocity.context.InternalContextAdapterImpl
All Implemented Interfaces:
Context, InternalContextAdapter, InternalEventContext, InternalWrapperContext

public final class InternalContextAdapterImpl
extends 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 :

This class implements the two interfaces to ensure that all methods are supported. When adding to the interfaces, or adding more context functionality, the interface is the primary definition, so alter that first and then all classes as necessary. As of this writing, this would be the only class affected by changes to InternalContext This class ensures that an InternalContextBase is available for internal use. If an application constructs their own Context-implementing object w/o subclassing AbstractContext, it may be that support for InternalContext is not available. Therefore, InternalContextAdapter will create an InternalContextBase if necessary for this support. Note that if this is necessary, internal information such as node-cache data will be lost from use to use of the context. This may or may not be important, depending upon application.

Version:
$Id: InternalContextAdapterImpl.java 731266 2009-01-04 15:11:20Z byron $
Author:
Geir Magnusson Jr.

Constructor Summary
InternalContextAdapterImpl(Context c)
          CTOR takes a Context and wraps it, delegating all 'data' calls to it.
 
Method Summary
 EventCartridge attachEventCartridge(EventCartridge ec)
           
 boolean containsKey(Object key)
          Indicates whether the specified key is in the context.
 Object get(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 depth
 String getCurrentMacroName()
          get the current macro name
 Resource getCurrentResource()
          temporary fix to enable #include() to figure out current encoding.
 String getCurrentTemplateName()
          get the current template name
 EventCartridge getEventCartridge()
           
 Context getInternalUserContext()
          returns the user data context that we are wrapping
 Object[] getKeys()
          Get all the keys for the values in the context.
 List getMacroLibraries()
          Get the macro library list for the current template.
 Object[] getMacroNameStack()
          Returns the macro name stack in form of an array.
 Object[] getTemplateNameStack()
          Returns the template name stack in form of an array.
 IntrospectionCacheData icacheGet(Object key)
          returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key
 void icachePut(Object key, IntrospectionCacheData o)
          places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key
 Object localPut(String key, Object value)
          Allows callers to explicitly put objects in the local context.
 void popCurrentMacroName()
          remove the current macro name from stack
 void popCurrentTemplateName()
          remove the current template name from stack
 void pushCurrentMacroName(String s)
          set the current macro name on top of stack
 void pushCurrentTemplateName(String s)
          set the current template name on top of stack
 Object put(String key, Object value)
          Adds a name/value pair to the context.
 Object remove(Object key)
          Removes the value associated with the specified key from the context.
 void setCurrentResource(Resource r)
           
 void setMacroLibraries(List macroLibraries)
          Set the macro library list for the current template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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(String s)
set the current template name on top of stack

Parameters:
s - current template name
See Also:
InternalHousekeepingContext.pushCurrentTemplateName(java.lang.String)

popCurrentTemplateName

public void popCurrentTemplateName()
remove the current template name from stack

See Also:
InternalHousekeepingContext.popCurrentTemplateName()

getCurrentTemplateName

public String getCurrentTemplateName()
get the current template name

Returns:
String current template name
See Also:
InternalHousekeepingContext.getCurrentTemplateName()

getTemplateNameStack

public Object[] getTemplateNameStack()
Returns the template name stack in form of an array.

Returns:
Object[] with the template name stack contents.
See Also:
InternalHousekeepingContext.getTemplateNameStack()

pushCurrentMacroName

public void pushCurrentMacroName(String s)
set the current macro name on top of stack

Parameters:
s - current macro name
Since:
1.6
See Also:
InternalHousekeepingContext.pushCurrentMacroName(java.lang.String)

popCurrentMacroName

public void popCurrentMacroName()
remove the current macro name from stack

Since:
1.6
See Also:
InternalHousekeepingContext.popCurrentMacroName()

getCurrentMacroName

public String getCurrentMacroName()
get the current macro name

Returns:
String current macro name
Since:
1.6
See Also:
InternalHousekeepingContext.getCurrentMacroName()

getCurrentMacroCallDepth

public int getCurrentMacroCallDepth()
get the current macro call depth

Returns:
int current macro call depth
Since:
1.6
See Also:
InternalHousekeepingContext.getCurrentMacroCallDepth()

getMacroNameStack

public Object[] getMacroNameStack()
Returns the macro name stack in form of an array.

Returns:
Object[] with the macro name stack contents.
Since:
1.6
See Also:
InternalHousekeepingContext.getMacroNameStack()

icacheGet

public IntrospectionCacheData icacheGet(Object key)
returns an IntrospectionCache Data (@see IntrospectionCacheData) object if exists for the key

Parameters:
key - key to find in cache
Returns:
cache object
See Also:
InternalHousekeepingContext.icacheGet(java.lang.Object)

icachePut

public void icachePut(Object key,
                      IntrospectionCacheData o)
places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key

Parameters:
key - key
o - 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)
See Also:
InternalHousekeepingContext.setCurrentResource(org.apache.velocity.runtime.resource.Resource)

getCurrentResource

public Resource getCurrentResource()
temporary fix to enable #include() to figure out current encoding.

Returns:
The current resource.
See Also:
InternalHousekeepingContext.getCurrentResource()

setMacroLibraries

public void setMacroLibraries(List macroLibraries)
Set the macro library list for the current template.

Parameters:
macroLibraries - list of macro libraries to set
Since:
1.6
See Also:
InternalHousekeepingContext.setMacroLibraries(List)

getMacroLibraries

public List getMacroLibraries()
Get the macro library list for the current template.

Returns:
List of macro library names
Since:
1.6
See Also:
InternalHousekeepingContext.getMacroLibraries()

put

public Object put(String key,
                  Object value)
Description copied from interface: Context
Adds a name/value pair to the context.

Specified by:
put in interface Context
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 Object localPut(String key,
                       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 interface InternalWrapperContext
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 Object get(String key)
Description copied from interface: Context
Gets the value corresponding to the provided key from the context.

Specified by:
get in interface Context
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(Object key)
Description copied from interface: Context
Indicates whether the specified key is in the context.

Specified by:
containsKey in interface Context
Parameters:
key - The key to look for.
Returns:
Whether the key is in the context.
See Also:
Context.containsKey(java.lang.Object)

getKeys

public Object[] getKeys()
Description copied from interface: Context
Get all the keys for the values in the context.

Specified by:
getKeys in interface Context
Returns:
All the keys for the values in the context.
See Also:
Context.getKeys()

remove

public Object remove(Object key)
Description copied from interface: Context
Removes the value associated with the specified key from the context.

Specified by:
remove in interface Context
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 interface InternalWrapperContext
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 interface InternalWrapperContext
Returns:
The base context.

attachEventCartridge

public EventCartridge attachEventCartridge(EventCartridge ec)
Specified by:
attachEventCartridge in interface InternalEventContext
Returns:
The old EventCartridge.
See Also:
InternalEventContext.attachEventCartridge(org.apache.velocity.app.event.EventCartridge)

getEventCartridge

public EventCartridge getEventCartridge()
Specified by:
getEventCartridge in interface InternalEventContext
Returns:
The current EventCartridge.
See Also:
InternalEventContext.getEventCartridge()


Copyright © 2000-2010 The Apache Software Foundation. All Rights Reserved.