org.codehaus.plexus.context

## Class DefaultContext

- java.lang.Object
- - org.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. 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 8061 2009-01-19 23:33:12Z dain $
Author:
  Avalon Development Team

### Constructor Summary

Constructors
Constructor and Description
`DefaultContext()` Create an empty Context.
`DefaultContext(java.util.Map<java.lang.Object,java.lang.Object> contextData)` Create a Context with specified data.

### Method Summary

Methods
`protected void` `checkWriteable()` Utility method to check if containerContext is writeable and if not throw exception.
`boolean` `contains(java.lang.Object key)` Returns true if this context contains a value for the specified key.
`java.lang.Object` `get(java.lang.Object key)` Returns the value of the key.
`java.util.Map` `getContextData()` Utility method to retrieve containerContext data
`void` `hide(java.lang.Object key)` Hides the item in the containerContext.
`void` `makeReadOnly()` Make the containerContext read-only.
`void` `put(java.lang.Object key, java.lang.Object value)` Adds the item to the containerContext.
`java.lang.String` `toString()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### DefaultContext

    public DefaultContext()

Create an empty Context.

#### DefaultContext

    public DefaultContext(java.util.Map<java.lang.Object,java.lang.Object> contextData)

Create a Context with specified data. The specified data is copied into the context so any subsequent updates to supplied map are not reflected in this context. Additionally, changes to this context are not reflected in the specified map.

Parameters:
  `contextData` - the containerContext data

### Method Detail

#### contains

    public boolean contains(java.lang.Object key)

Description copied from interface: `Context`
Returns true if this context contains a value for the specified key.

Specified by:
  `contains` in interface `Context`
Parameters:
  `key` - the key to search
Returns:
  true if the key was found; false otherwise

#### get

    public java.lang.Object get(java.lang.Object key)
                         throws ContextException

Description copied from interface: `Context`
Returns the value of the key. If the key can't be found it will throw a exception.

Specified by:
  `get` in interface `Context`
Parameters:
  `key` - the key of the value to look up.
Returns:
  returns the value associated with the key
Throws:
  `ContextException` - if the key doesn't exist

#### put

    public void put(java.lang.Object key,
           java.lang.Object value)
             throws java.lang.IllegalStateException

Description copied from interface: `Context`
Adds the item to the containerContext.

Specified by:
  `put` in interface `Context`
Parameters:
  `key` - the key of the item
  `value` - the item
Throws:
  `java.lang.IllegalStateException` - if this context is read-only

#### hide

    public void hide(java.lang.Object key)
              throws java.lang.IllegalStateException

Description copied from interface: `Context`
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.

Specified by:
  `hide` in interface `Context`
Parameters:
  `key` - the items key
Throws:
  `java.lang.IllegalStateException` - if this context is read-only

#### getContextData

    public java.util.Map getContextData()

Utility method to retrieve containerContext data

Specified by:
  `getContextData` in interface `Context`
Returns:
  the containerContext data

#### makeReadOnly

    public void makeReadOnly()

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

Specified by:
  `makeReadOnly` in interface `Context`

#### checkWriteable

    protected void checkWriteable()
                           throws java.lang.IllegalStateException

Utility method to check if containerContext is writeable and if not throw exception.

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

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`