AbstractContext (Velocity 1.7 API)
Keywords: org.apache.velocity.context.AbstractContext class

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.velocity.context
Class AbstractContext

    java.lang.Object
      org.apache.velocity.context.InternalContextBase
          org.apache.velocity.context.AbstractContext

All Implemented Interfaces:
  Context, InternalEventContext, org.apache.velocity.context.InternalHousekeepingContext

Direct Known Subclasses:
  VelocityContext

public abstract class AbstractContext
extends org.apache.velocity.context.InternalContextBase
implements Context

This class is the abstract base class for all conventional Velocity Context implementations. Simply extend this class and implement the abstract routines that access your preferred storage method. Takes care of context chaining. Also handles / enforces policy on null keys and values :

- Null keys and values are accepted and basically dropped.
- If you place an object into the context with a null key, it will be ignored and logged.
- If you try to place a null into the context with any key, it will be dropped and logged.

The default implementation of this for application use is org.apache.velocity.VelocityContext. All thanks to Fedor for the chaining idea.

Version:
  $Id: AbstractContext.java 732250 2009-01-07 07:37:10Z byron $
Author:
  Geir Magnusson Jr., Fedor Karpelevitch, Jason van Zyl

Constructor Summary
`AbstractContext()` default CTOR
`AbstractContext(Context inner)` Chaining constructor accepts a Context argument.

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.
`Context` | `getChainedContext()` returns innerContext if one is chained
`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()`
`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()` get the current macro name stack
`Object[]` | `getTemplateNameStack()` get the current template name stack
`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
`abstract boolean` | `internalContainsKey(Object key)` Implement to determine if a key is in the storage.
`abstract Object` | `internalGet(String key)` Implement to return a value from the context storage.
`abstract Object[]` | `internalGetKeys()` Implement to return an object array of key strings from your storage.
`abstract Object` | `internalPut(String key, Object value)` Implement to put a value into the context storage.
`abstract Object` | `internalRemove(Object key)` I mplement to remove an item from your storage.
`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

### AbstractContext

    public AbstractContext()

  default CTOR

### AbstractContext

    public AbstractContext(Context inner)

  Chaining constructor accepts a Context argument. It will relay get() operations into this Context in the even the 'local' get() returns null.

Parameters:
  `inner` - context to be chained

Method Detail

### internalGet

    public abstract Object internalGet(String key)

  Implement to return a value from the context storage.
  The implementation of this method is required for proper operation of a Context implementation in general Velocity use.

  Parameters:
    `key` - key whose associated value is to be returned
  Returns:
    object stored in the context

### internalPut

    public abstract Object internalPut(String key,
                                       Object value)

  Implement to put a value into the context storage.
  The implementation of this method is required for proper operation of a Context implementation in general Velocity use.

  Parameters:
    `key` - key with which to associate the value
    `value` - value to be associated with the key
  Returns:
    previously stored value if exists, or null

### internalContainsKey

    public abstract boolean internalContainsKey(Object key)

  Implement to determine if a key is in the storage.
  Currently, this method is not used internally by the Velocity engine.

  Parameters:
    `key` - key to test for existance
  Returns:
    true if found, false if not

### internalGetKeys

    public abstract Object[] internalGetKeys()

  Implement to return an object array of key strings from your storage.
  Currently, this method is not used internally by the Velocity engine.

  Returns:
    array of keys

### internalRemove

    public abstract Object internalRemove(Object key)

  I mplement to remove an item from your storage.
  Currently, this method is not used internally by the Velocity engine.

  Parameters:
    `key` - key to remove
  Returns:
    object removed if exists, else null

### put

    public Object put(String key,
                      Object value)

  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:
    Object that was replaced in the the Context if applicable or null if not.

### get

    public Object get(String key)

  Gets the value corresponding to the provided key from the context. Supports the chaining context mechanism. If the 'local' context doesn't have the value, we try to get it from the chained context.

  Specified by:
    `get` in interface `Context`
  Parameters:
    `key` - The name of the desired value.
  Returns:
    The value corresponding to the provided key or null if the key param is null.

### containsKey

    public boolean containsKey(Object key)

  Indicates whether the specified key is in the context. Provided for debugging purposes.

  Specified by:
    `containsKey` in interface `Context`
  Parameters:
    `key` - The key to look for.
  Returns:
    true if the key is in the context, false if not.

### getKeys

    public Object[] getKeys()

  Get all the keys for the values in the context

  Specified by:
    `getKeys` in interface `Context`
  Returns:
    Object[] of keys in the Context. Does not return keys in chained context.

### remove

    public Object remove(Object key)

  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.

### getChainedContext

    public Context getChainedContext()

  returns innerContext if one is chained

  Returns:
    Context if chained, `null` if not

### pushCurrentTemplateName

    public void pushCurrentTemplateName(String s)

  set the current template name on top of stack

  Specified by:
    `pushCurrentTemplateName` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Parameters:
    `s` - current template name

### popCurrentTemplateName

    public void popCurrentTemplateName()

  remove the current template name from stack

  Specified by:
    `popCurrentTemplateName` in interface `org.apache.velocity.context.InternalHousekeepingContext`

### getCurrentTemplateName

    public String getCurrentTemplateName()

  get the current template name

  Specified by:
    `getCurrentTemplateName` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Returns:
    String current template name

### getTemplateNameStack

    public Object[] getTemplateNameStack()

  get the current template name stack

  Specified by:
    `getTemplateNameStack` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Returns:
    Object[] with the template name stack contents.

### pushCurrentMacroName

    public void pushCurrentMacroName(String s)

  set the current macro name on top of stack

  Specified by:
    `pushCurrentMacroName` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Parameters:
    `s` - current macro name

### popCurrentMacroName

    public void popCurrentMacroName()

  remove the current macro name from stack

  Specified by:
    `popCurrentMacroName` in interface `org.apache.velocity.context.InternalHousekeepingContext`

### getCurrentMacroName

    public String getCurrentMacroName()

  get the current macro name

  Specified by:
    `getCurrentMacroName` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Returns:
    String current macro name

### getCurrentMacroCallDepth

    public int getCurrentMacroCallDepth()

  get the current macro call depth

  Specified by:
    `getCurrentMacroCallDepth` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Returns:
    int current macro call depth

### getMacroNameStack

    public Object[] getMacroNameStack()

  get the current macro name stack

  Specified by:
    `getMacroNameStack` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Returns:
    Object[] with the macro name stack contents.

### icacheGet

    public IntrospectionCacheData icacheGet(Object key)

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

  Specified by:
    `icacheGet` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Parameters:
    `key` - key to find in cache
  Returns:
    cache object

### icachePut

    public void icachePut(Object key,
                          IntrospectionCacheData o)

  places an IntrospectionCache Data (@see IntrospectionCacheData) element in the cache for specified key

  Specified by:
    `icachePut` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Parameters:
    `key` - key
    `o` - IntrospectionCacheData object to place in cache

### setCurrentResource

    public void setCurrentResource(Resource r)

  Specified by:
    `setCurrentResource` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Parameters:
    `r` -
  See Also:
    `InternalHousekeepingContext.setCurrentResource(org.apache.velocity.runtime.resource.Resource)`

### getCurrentResource

    public Resource getCurrentResource()

  Description copied from interface: `org.apache.velocity.context.InternalHousekeepingContext`
  temporary fix to enable #include() to figure out current encoding.

  Specified by:
    `getCurrentResource` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Returns:
    The current resource.
  See Also:
    `InternalHousekeepingContext.getCurrentResource()`

### setMacroLibraries

    public void setMacroLibraries(List macroLibraries)

  Description copied from interface: `org.apache.velocity.context.InternalHousekeepingContext`
  Set the macro library list for the current template.

  Specified by:
    `setMacroLibraries` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Parameters:
    `macroLibraries` - list of macro libraries to set
  See Also:
    `InternalHousekeepingContext.setMacroLibraries(List)`

### getMacroLibraries

    public List getMacroLibraries()

  Description copied from interface: `org.apache.velocity.context.InternalHousekeepingContext`
  Get the macro library list for the current template.

  Specified by:
    `getMacroLibraries` in interface `org.apache.velocity.context.InternalHousekeepingContext`
  Returns:
    List of macro library names
  See Also:
    `InternalHousekeepingContext.getMacroLibraries()`

### attachEventCartridge

    public EventCartridge attachEventCartridge(EventCartridge ec)

  Specified by:
    `attachEventCartridge` in interface `InternalEventContext`
  Parameters:
    `ec` -
  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()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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