Package org.codehaus.plexus.context
Class DefaultContext
java.lang.Object
org.codehaus.plexus.context.DefaultContext
- All Implemented Interfaces:
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.- Author:
- Avalon Development Team
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an empty Context.DefaultContext(Map<Object, Object> contextData) Create a Context with specified data. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidUtility method to check if containerContext is writeable and if not throw exception.booleanReturns true if this context contains a value for the specified key.Returns the value of the key.Utility method to retrieve containerContext datavoidHides the item in the containerContext.voidMake the containerContext read-only.voidAdds the item to the containerContext.toString()
-
Constructor Details
-
DefaultContext
public DefaultContext()Create an empty Context. -
DefaultContext
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 Details
-
contains
Description copied from interface:ContextReturns true if this context contains a value for the specified key. -
get
Description copied from interface:ContextReturns the value of the key. If the key can't be found it will throw a exception.- Specified by:
getin interfaceContext- 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
Description copied from interface:ContextAdds the item to the containerContext.- Specified by:
putin interfaceContext- Parameters:
key- the key of the itemvalue- the item- Throws:
IllegalStateException- if this context is read-only
-
hide
Description copied from interface:ContextHides 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:
hidein interfaceContext- Parameters:
key- the items key- Throws:
IllegalStateException- if this context is read-only
-
getContextData
Utility method to retrieve containerContext data- Specified by:
getContextDatain interfaceContext- 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:
makeReadOnlyin interfaceContext
-
checkWriteable
Utility method to check if containerContext is writeable and if not throw exception.- Throws:
IllegalStateException- if containerContext is read only
-
toString
-