org.codehaus.plexus.context
Class DefaultContext
java.lang.Object
org.codehaus.plexus.context.DefaultContext
- Context
public class DefaultContext
extends java.lang.Object
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 context will not search in the parent context for the value.
$Id: DefaultContext.java 1323 2004-12-20 23:00:59Z jvanzyl $private static class | DefaultContext.Hidden - This class is only used as a marker in the map to indicate a hidden value.
|
protected void | checkWriteable() - Utility method to check if context is writeable and if not throw exception.
|
boolean | contains(Object key) - Returns true if the map or the parent map contains the key.
|
Object | get(Object key) - Returns the value of the key.
|
protected Map | getContextData() - Utility method to retrieve context data.
|
protected Context | getParent() - Get parent context if any.
|
void | hide(Object key) - Hides the item in the context.
|
void | makeReadOnly() - Make the context read-only.
|
void | put(Object key, Object value) - Helper method for adding items to Context.
|
contextData
private Map contextData
Context data.
parent
private Context parent
Parent Context.
readOnly
private boolean readOnly
Is the context read only.
DefaultContext
public DefaultContext()
Create a empty Context with no parent.
DefaultContext
public DefaultContext(Map contextData)
Create a empty Context with specified data.
contextData
- the context data
DefaultContext
public DefaultContext(Map contextData,
Context parent)
Create a Context with specified data and parent.
contextData
- the context dataparent
- the parent Context (may be null)
DefaultContext
public DefaultContext(Context parent)
Create a Context with specified parent.
parent
- the parent Context (may be null)
checkWriteable
protected void checkWriteable()
throws IllegalStateException
Utility method to check if context is writeable and if not throw exception.
contains
public boolean contains(Object key)
Returns true if the map or the parent map contains the key.
- contains in interface Context
key
- The key to search for.
- Returns true if the key was found.
get
public Object get(Object key)
throws ContextException
Returns the value of the key. If the key can't be found it will throw a exception.
- get in interface Context
key
- The key of the value to look up.
getContextData
protected Map getContextData()
Utility method to retrieve context data.
getParent
protected Context getParent()
Get parent context if any.
- the parent Context (may be null)
hide
public void hide(Object key)
throws 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.
- hide in interface Context
makeReadOnly
public void makeReadOnly()
Make the context read-only.
Any attempt to write to the context via put()
will result in an IllegalStateException.
- makeReadOnly in interface Context
put
public void put(Object key,
Object value)
throws IllegalStateException
Helper method for adding items to Context.
- put in interface Context
key
- the items keyvalue
- the item