Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | 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, InternalHousekeepingContext, java.io.Serializable

Direct Known Subclasses:
  VelocityContext

public abstract class AbstractContext
extends InternalContextBase
implements Context, java.io.Serializable

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,v 1.8 2001/10/22 03:53:23 jon Exp $
Author:
  Geir Magnusson Jr., Fedor Karpelevitch, Jason van Zyl
See Also:
  Serialized Form

Field Summary
`private Context` | `innerContext` the chained Context if any

Fields inherited from class org.apache.velocity.context.InternalContextBase
`currentResource, eventCartridge, introspectionCache, templateNameStack`

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

Method Summary
`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.
`Context` | `getChainedContext()` returns innerContext if one is chained
`java.lang.Object[]` | `getKeys()` Get all the keys for the values in the context
`abstract boolean` | `internalContainsKey(java.lang.Object key)` Implement to determine if a key is in the storage.
`abstract java.lang.Object` | `internalGet(java.lang.String key)` Implement to return a value from the context storage.
`abstract java.lang.Object[]` | `internalGetKeys()` Implement to return an object array of key strings from your storage.
`abstract java.lang.Object` | `internalPut(java.lang.String key, java.lang.Object value)` Implement to put a value into the context storage.
`abstract java.lang.Object` | `internalRemove(java.lang.Object key)` I mplement to remove an item from your storage.
`java.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.

Methods inherited from class org.apache.velocity.context.InternalContextBase
`attachEventCartridge, getCurrentResource, getCurrentTemplateName, getEventCartridge, getTemplateNameStack, icacheGet, icachePut, popCurrentTemplateName, pushCurrentTemplateName, setCurrentResource`

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### innerContext

    private Context innerContext

  the chained Context if any

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 java.lang.Object internalGet(java.lang.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 java.lang.Object internalPut(java.lang.String key,
                                                 java.lang.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(java.lang.Object key)

  Implement to determine if a key is in the storage.
  Currently, this method is not used internally by the Velocity core.
  Parameters:
    `key` - key to test for existance
  Returns:
    true if found, false if not

### internalGetKeys

    public abstract java.lang.Object[] internalGetKeys()

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

### internalRemove

    public abstract java.lang.Object internalRemove(java.lang.Object key)

  I mplement to remove an item from your storage.
  Currently, this method is not used internally by the Velocity core.
  Parameters:
    `key` - key to remove
  Returns:
    object removed if exists, else null

### put

    public java.lang.Object put(java.lang.String key,
                                java.lang.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 java.lang.Object get(java.lang.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(java.lang.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 java.lang.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 java.lang.Object remove(java.lang.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

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

Copyright © 2003 Apache Software Foundation. All Rights Reserved.