Top Description Inners Fields Constructors Methods
org.apache.avalon.framework.context

public Class DefaultContext

extends Object
implements Context, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.avalon.framework.context.Context
Imports
java.io.Serializable, java.util.Hashtable, .Map

Default implementation of Context. This implementation is a static hierarchial store.
Author
Avalon Development Team
Version
$Id: DefaultContext.java 506231 2007-02-12 02:36:54Z crossley $

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final DefaultContext.Hidden
private final Map<K, V>
private final Context
private boolean

Constructor Summary

AccessConstructor and Description
public
DefaultContext(final Map<K, V>
the context data
contextData
,
final Context
the parent Context (may be null)
parent
)

Create a Context with specified data and parent.

public
DefaultContext(final Map<K, V>
the context data
contextData
)

Create a Context with specified data.

public
DefaultContext(final Context
the parent Context (may be null)
parent
)

Create a Context with specified parent.

public
DefaultContext()

Create a Context with no parent.

Method Summary

Modifier and TypeMethod and Description
protected final void
checkWriteable()

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

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Check for equality between two DefaultContext objects.
public Object

Returns:

the item stored in context
get
(final Object
the key of item
key
)

Implements org.apache.avalon.framework.context.Context.get.

Retrieve an item from the Context.
protected final Map<K, V>

Returns:

the context data
getContextData
()

Utility method to retrieve context data.

protected final Context

Returns:

the parent Context (may be null)
getParent
()

Get parent context if any.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public void
hide(final Object
the items key
key
)

Hides the item in the context.

public void
makeReadOnly()

Make the context read-only.

public void
put(final Object
the items key
key
,
final Object
the item
value
)

Helper method fo adding items to Context.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

HIDDEN_MAKERback to summary
private static final DefaultContext.Hidden HIDDEN_MAKER
m_contextDataback to summary
private final Map<K, V> m_contextData
m_parentback to summary
private final Context m_parent
m_readOnlyback to summary
private boolean m_readOnly

Constructor Detail

DefaultContextback to summary
public DefaultContext(final Map<K, V> contextData, final Context parent)

Create a Context with specified data and parent.

Parameters
contextData:Map<K, V>

the context data

parent:Context

the parent Context (may be null)

DefaultContextback to summary
public DefaultContext(final Map<K, V> contextData)

Create a Context with specified data.

Parameters
contextData:Map<K, V>

the context data

DefaultContextback to summary
public DefaultContext(final Context parent)

Create a Context with specified parent.

Parameters
parent:Context

the parent Context (may be null)

DefaultContextback to summary
public DefaultContext()

Create a Context with no parent.

Method Detail

checkWriteableback to summary
protected final void checkWriteable() throws IllegalStateException

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

Exceptions
IllegalStateException:
if context is read only
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Check for equality between two DefaultContext objects.

Equality is said to be true if, and only if, the following criteria are met;

  • They are both of the same class.
  • They both have the same parent.
  • The content of the context map are identical, i.e HashMap.equals()
  • The have the same readOnly state.
Parameters
o:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Since
4.5
getback to summary
public Object get(final Object key) throws ContextException

Implements org.apache.avalon.framework.context.Context.get.

Retrieve an item from the Context.

Parameters
key:Object

the key of item

Returns:Object

the item stored in context

Exceptions
ContextException:
if item not present
getContextDataback to summary
protected final Map<K, V> getContextData()

Utility method to retrieve context data.

Returns:Map<K, V>

the context data

getParentback to summary
protected final Context getParent()

Get parent context if any.

Returns:Context

the parent Context (may be null)

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

hideback to summary
public void hide(final 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.

Parameters
key:Object

the items key

Exceptions
IllegalStateException:
if context is read only
makeReadOnlyback to summary
public void makeReadOnly()

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

putback to summary
public void put(final Object key, final Object value) throws IllegalStateException

Helper method fo adding items to Context.

Parameters
key:Object

the items key

value:Object

the item

Exceptions
IllegalStateException:
if context is read only
org.apache.avalon.framework.context back to summary

private final Class DefaultContext.Hidden

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Hiddenback to summary
private Hidden()