org.codehaus.plexus.context

Class DefaultContext

public class DefaultContext extends Object implements Context

Default implementation of Context. This implementation is a static hierarchial store. It has the normal get() and put methods. The hide method will hide a property. When a property has been hidden the containerContext will not search in the parent containerContext for the value.

Version: $Id: DefaultContext.java 6585 2007-07-04 17:37:22Z kenney $

Author: Avalon Development Team

Nested Class Summary
static classDefaultContext.Hidden
This class is only used as a marker in the map to indicate a hidden value.
Field Summary
MapcontextData
Context data.
static DefaultContext.HiddenHIDDEN_MAKER
Contextparent
Parent Context.
booleanreadOnly
Is the containerContext read only.
Constructor Summary
DefaultContext(Map contextData, Context parent)
Create a Context with specified data and parent.
DefaultContext(Map contextData)
Create a empty Context with specified data.
DefaultContext(Context parent)
Create a Context with specified parent.
DefaultContext()
Create a empty Context with no parent.
Method Summary
protected voidcheckWriteable()
Utility method to check if containerContext is writeable and if not throw exception.
booleancontains(Object key)
Returns true if the map or the parent map contains the key.
Objectget(Object key)
Returns the value of the key.
MapgetContextData()
Utility method to retrieve containerContext data
protected ContextgetParent()
Get parent containerContext if any.
voidhide(Object key)
Hides the item in the containerContext.
voidmakeReadOnly()
Make the containerContext read-only.
voidput(Object key, Object value)
Helper method for adding items to Context.

Field Detail

contextData

private Map contextData
Context data.

HIDDEN_MAKER

private static DefaultContext.Hidden HIDDEN_MAKER

parent

private Context parent
Parent Context.

readOnly

private boolean readOnly
Is the containerContext read only.

Constructor Detail

DefaultContext

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

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

DefaultContext

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

Parameters: contextData the containerContext 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 empty Context with no parent.

Method Detail

checkWriteable

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

Throws: java.lang.IllegalStateException if containerContext is read only

contains

public boolean contains(Object key)
Returns true if the map or the parent map contains the key.

Parameters: key The key to search for.

Returns: Returns true if the key was found.

get

public Object get(Object key)
Returns the value of the key. If the key can't be found it will throw a exception.

Parameters: key The key of the value to look up.

Returns: Returns

Throws: ContextException If the key doesn't exist.

getContextData

public Map getContextData()
Utility method to retrieve containerContext data

Returns: the containerContext data

getParent

protected Context getParent()
Get parent containerContext if any.

Returns: the parent Context (may be null)

hide

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

Parameters: key the items key

Throws: java.lang.IllegalStateException if containerContext is read only

makeReadOnly

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

put

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

Parameters: key the items key value the item

Throws: java.lang.IllegalStateException if containerContext is read only