org.apache.avalon.framework.context

Class DefaultContext

public class DefaultContext extends Object implements Context

Default implementation of Context. This implementation is a static hierarchial store.

Version: CVS $Revision: 1.25 $ $Date: 2003/02/11 15:58:40 $

Author: Avalon Development Team

Constructor Summary
DefaultContext(Map contextData, Context parent)
Create a Context with specified data and parent.
DefaultContext(Map contextData)
Create a Context with specified data.
DefaultContext(Context parent)
Create a Context with specified parent.
DefaultContext()
Create a Context with no parent.
Method Summary
protected voidcheckWriteable()
Utility method to check if context is writeable and if not throw exception.
Objectget(Object key)
Retrieve an item from the Context.
protected MapgetContextData()
Utility method to retrieve context data.
protected ContextgetParent()
Get parent context if any.
voidhide(Object key)
Hides the item in the context.
voidmakeReadOnly()
Make the context read-only.
voidput(Object key, Object value)
Helper method fo adding items to Context.

Constructor Detail

DefaultContext

public DefaultContext(Map contextData, Context parent)
Create a Context with specified data and parent.

Parameters: contextData the context data parent the parent Context (may be null)

DefaultContext

public DefaultContext(Map contextData)
Create a Context with specified data.

Parameters: contextData the context data

DefaultContext

public DefaultContext(Context parent)
Create a Context with specified parent.

Parameters: parent the parent Context (may be null)

DefaultContext

public DefaultContext()
Create a Context with no parent.

Method Detail

checkWriteable

protected final void checkWriteable()
Utility method to check if context is writeable and if not throw exception.

Throws: IllegalStateException if context is read only

get

public Object get(Object key)
Retrieve an item from the Context.

Parameters: key the key of item

Returns: the item stored in context

Throws: ContextException if item not present

getContextData

protected final Map getContextData()
Utility method to retrieve context data.

Returns: the context data

getParent

protected final Context getParent()
Get parent context if any.

Returns: the parent Context (may be null)

hide

public void hide(Object key)
Hides the item in the context. After remove(key) has been called, a get(key) will always fail, even if the parent context has such a mapping.

Parameters: key the items key

Throws: IllegalStateException if context is read only

makeReadOnly

public void makeReadOnly()
Make the context read-only. Any attempt to write to the context via put() will result in an IllegalStateException.

put

public void put(Object key, Object value)
Helper method fo adding items to Context.

Parameters: key the items key value the item

Throws: IllegalStateException if context is read only