org.codehaus.plexus.context
Class DefaultContext

java.lang.Object
  extended byorg.codehaus.plexus.context.DefaultContext
All Implemented Interfaces:
Context

public class DefaultContext
extends java.lang.Object
implements Context

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

Version:
CVS $Revision: 1.4 $ $Date: 2003/12/19 04:09:48 $
Author:
Avalon Development Team

Nested Class Summary
private static class DefaultContext.Hidden
           
 
Field Summary
private  java.util.Map contextData
          Context data.
private static DefaultContext.Hidden HIDDEN_MAKER
           
private  Context parent
          Parent Context.
private  boolean readOnly
          Is the context read only.
 
Constructor Summary
DefaultContext()
          Create a Context with no parent.
DefaultContext(Context parent)
          Create a Context with specified parent.
DefaultContext(java.util.Map contextData)
          Create a Context with specified data.
DefaultContext(java.util.Map contextData, Context parent)
          Create a Context with specified data and parent.
 
Method Summary
protected  void checkWriteable()
          Utility method to check if context is writeable and if not throw exception.
 java.lang.Object get(java.lang.Object key)
           
protected  java.util.Map getContextData()
          Utility method to retrieve context data.
protected  Context getParent()
          Get parent context if any.
 void hide(java.lang.Object key)
          Hides the item in the context.
 void makeReadOnly()
          Make the context read-only.
 void put(java.lang.Object key, java.lang.Object value)
          Helper method fo adding items to Context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HIDDEN_MAKER

private static DefaultContext.Hidden HIDDEN_MAKER

contextData

private java.util.Map contextData
Context data.


parent

private Context parent
Parent Context.


readOnly

private boolean readOnly
Is the context read only.

Constructor Detail

DefaultContext

public DefaultContext(java.util.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(java.util.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

get

public java.lang.Object get(java.lang.Object key)
                     throws ContextException
Specified by:
get in interface Context
Throws:
ContextException

put

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

Parameters:
key - the items key
value - the item
Throws:
java.lang.IllegalStateException - if context is read only

hide

public void hide(java.lang.Object key)
          throws java.lang.IllegalStateException
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:
java.lang.IllegalStateException - if context is read only

getContextData

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

Returns:
the context data

getParent

protected Context getParent()
Get parent context if any.

Returns:
the parent Context (may be null)

makeReadOnly

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


checkWriteable

protected void checkWriteable()
                       throws java.lang.IllegalStateException
Utility method to check if context is writeable and if not throw exception.

Throws:
java.lang.IllegalStateException - if context is read only