Class DefaultContext

java.lang.Object
org.apache.avalon.framework.context.DefaultContext
All Implemented Interfaces:
Serializable, org.apache.avalon.framework.context.Context

public class DefaultContext extends Object implements org.apache.avalon.framework.context.Context, Serializable
Default implementation of Context. This implementation is a static hierarchial store.
Version:
$Id: DefaultContext.java 35590 2004-08-02 09:48:59 -0500 (Mon, 02 Aug 2004) niclas $
Author:
Avalon Development Team
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final DefaultContext.Hidden
     
    private final Map
     
    private final org.apache.avalon.framework.context.Context
     
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a Context with no parent.
    DefaultContext(Map contextData)
    Create a Context with specified data.
    DefaultContext(Map contextData, org.apache.avalon.framework.context.Context parent)
    Create a Context with specified data and parent.
    DefaultContext(org.apache.avalon.framework.context.Context parent)
    Create a Context with specified parent.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected final void
    Utility method to check if context is writeable and if not throw exception.
    boolean
    Check for equality between two DefaultContext objects.
    get(Object key)
    Retrieve an item from the Context.
    protected final Map
    Utility method to retrieve context data.
    protected final org.apache.avalon.framework.context.Context
    Get parent context if any.
    int
     
    void
    hide(Object key)
    Hides the item in the context.
    void
    Make the context read-only.
    void
    put(Object key, Object value)
    Helper method fo adding items to Context.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • HIDDEN_MAKER

      private static final DefaultContext.Hidden HIDDEN_MAKER
    • m_contextData

      private final Map m_contextData
    • m_parent

      private final org.apache.avalon.framework.context.Context m_parent
    • m_readOnly

      private boolean m_readOnly
  • Constructor Details

    • DefaultContext

      public DefaultContext(Map contextData, org.apache.avalon.framework.context.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(Map contextData)
      Create a Context with specified data.
      Parameters:
      contextData - the context data
    • DefaultContext

      public DefaultContext(org.apache.avalon.framework.context.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 Details

    • get

      public Object get(Object key) throws org.apache.avalon.framework.context.ContextException
      Retrieve an item from the Context.
      Specified by:
      get in interface org.apache.avalon.framework.context.Context
      Parameters:
      key - the key of item
      Returns:
      the item stored in context
      Throws:
      org.apache.avalon.framework.context.ContextException - if item not present
    • put

      public void put(Object key, Object value) throws IllegalStateException
      Helper method fo adding items to Context.
      Parameters:
      key - the items key
      value - the item
      Throws:
      IllegalStateException - if context is read only
    • 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.
      Parameters:
      key - the items key
      Throws:
      IllegalStateException - if context is read only
    • getContextData

      protected final Map getContextData()
      Utility method to retrieve context data.
      Returns:
      the context data
    • getParent

      protected final org.apache.avalon.framework.context.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 final void checkWriteable() throws IllegalStateException
      Utility method to check if context is writeable and if not throw exception.
      Throws:
      IllegalStateException - if context is read only
    • equals

      public boolean equals(Object o)
      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.
      Overrides:
      equals in class Object
      Since:
      4.5
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object