org.apache.commons.workflow.base
Class BaseScope

java.lang.Object
  extended byorg.apache.commons.workflow.base.BaseScope
All Implemented Interfaces:
java.util.Map, org.apache.commons.workflow.Scope
Direct Known Subclasses:
HttpSessionScope, ServletContextScope, ServletRequestScope

public class BaseScope
extends java.lang.Object
implements org.apache.commons.workflow.Scope

BaseScope is a basic Scope implementation that maintains its bean collection in an in-memory HashMap. This can also serve as a convenient base class for more sophisticated Scope implementations.

WARNING - No synchronization is performed within this class. If it is used in a multiple thread environment, callers must take suitable precations.

Version:
$Revision: 1.6 $ $Date: 2004/02/28 03:35:54 $

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  java.util.HashMap map
          The HashMap that contains our registered keys and beans.
protected  ScopeSupport support
          The event listener support object for this Scope.
 
Constructor Summary
BaseScope()
           
 
Method Summary
 void addScopeListener(org.apache.commons.workflow.ScopeListener listener)
          Add a listener that is notified each time beans are added, replaced, or removed in this scope.
 void clear()
          Remove all beans from this Map and call scopeCleared() on all registered ScopeListeners.
 boolean containsKey(java.lang.Object key)
          Return true if this map contains the specified key.
 boolean containsValue(java.lang.Object value)
          Return true if this map contains the specified value.
 java.util.Set entrySet()
          Return a set view of the mappings contained in this map.
 boolean equals(java.lang.Object object)
          Compare the specified object with this map for equality.
 java.lang.Object get(java.lang.Object key)
          Return the value to which this map maps the specified key.
 java.lang.Object get(java.lang.String key)
          Return the value to which this map maps the specified key.
 int hashCode()
          Return the hash code value for this map.
 boolean isEmpty()
          Return true if this map is empty.
 java.util.Set keySet()
          Return a set view of the keys contained in this map.
 java.lang.Object put(java.lang.Object key, java.lang.Object bean)
          Add or replace the bean associated with the specified key.
 java.lang.Object put(java.lang.String key, java.lang.Object bean)
          Add the specified bean, associated with the specified key, to this scope and replace any previous bean associated with this key.
 void putAll(java.util.Map in)
          Copy all of the mappings from the specified map into this map, firing appropriate beanAdded() and beanReplaced() events along the way.
 java.lang.Object remove(java.lang.Object key)
          Remove the bean associated with the specified key (if any), and return the old value if removed.
 java.lang.Object remove(java.lang.String key)
          Remove the bean associated with the specified key (if any).
 void removeScopeListener(org.apache.commons.workflow.ScopeListener listener)
          Remove a listener that is notified each time beans are added, replaced, or removed in this scope.
 int size()
          Return the number of key-value mappings in this map.
 java.util.Collection values()
          Return a Collection view of the values contained in this map.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

protected java.util.HashMap map
The HashMap that contains our registered keys and beans.


support

protected ScopeSupport support
The event listener support object for this Scope.

Constructor Detail

BaseScope

public BaseScope()
Method Detail

clear

public void clear()
Remove all beans from this Map and call scopeCleared() on all registered ScopeListeners.

Specified by:
clear in interface org.apache.commons.workflow.Scope

containsKey

public boolean containsKey(java.lang.Object key)
Return true if this map contains the specified key.

Specified by:
containsKey in interface java.util.Map
Parameters:
key - Key to be looked up

containsValue

public boolean containsValue(java.lang.Object value)
Return true if this map contains the specified value.

Specified by:
containsValue in interface java.util.Map
Parameters:
value - Value to be looked up

entrySet

public java.util.Set entrySet()
Return a set view of the mappings contained in this map.

Specified by:
entrySet in interface java.util.Map

equals

public boolean equals(java.lang.Object object)
Compare the specified object with this map for equality.

Specified by:
equals in interface java.util.Map
Parameters:
object - Object to be compared

get

public java.lang.Object get(java.lang.Object key)
Return the value to which this map maps the specified key.

Specified by:
get in interface java.util.Map
Parameters:
key - Key to be looked up

get

public java.lang.Object get(java.lang.String key)
Return the value to which this map maps the specified key.

Parameters:
key - Key to be looked up

hashCode

public int hashCode()
Return the hash code value for this map.

Specified by:
hashCode in interface java.util.Map

isEmpty

public boolean isEmpty()
Return true if this map is empty.

Specified by:
isEmpty in interface java.util.Map

keySet

public java.util.Set keySet()
Return a set view of the keys contained in this map.

Specified by:
keySet in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object bean)
Add or replace the bean associated with the specified key.

Specified by:
put in interface java.util.Map
Parameters:
key - Key with which the new value should be associated (cannot be null)
bean - Bean to be associated with this key (cannot be null)

put

public java.lang.Object put(java.lang.String key,
                            java.lang.Object bean)
Add the specified bean, associated with the specified key, to this scope and replace any previous bean associated with this key. If the bean was added, call beanAdded() on all registered listeners after the add is done. If an old bean was replaced, call beanReplaced() (passing the old value in the event) on all registered ScopeListeners after the removal is done. If a bean was replaced, the old value is also returned; otherwise null is returned.

Specified by:
put in interface org.apache.commons.workflow.Scope
Parameters:
key - Key with which the new value should be associated (cannot be null)
bean - Bean to be associated with this key (cannot be null)
Throws:
java.lang.IllegalArgumentException - if key or bean is null

putAll

public void putAll(java.util.Map in)
Copy all of the mappings from the specified map into this map, firing appropriate beanAdded() and beanReplaced() events along the way.

Specified by:
putAll in interface java.util.Map
Parameters:
in - Map whose contents are to be added

remove

public java.lang.Object remove(java.lang.Object key)
Remove the bean associated with the specified key (if any), and return the old value if removed.

Specified by:
remove in interface java.util.Map
Parameters:
key - Key of the bean to remove (cannot be null)

remove

public java.lang.Object remove(java.lang.String key)
Remove the bean associated with the specified key (if any). If such a bean is found and removed, call beanRemoved() on all registered ScopeListeners after the removal is done. Return the old value (if any); otherwise return null.

Specified by:
remove in interface org.apache.commons.workflow.Scope
Parameters:
key - Key of the bean to remove (cannot be null)
Throws:
java.lang.IllegalArgumentException - if key is null

size

public int size()
Return the number of key-value mappings in this map.

Specified by:
size in interface java.util.Map

values

public java.util.Collection values()
Return a Collection view of the values contained in this map.

Specified by:
values in interface java.util.Map

addScopeListener

public void addScopeListener(org.apache.commons.workflow.ScopeListener listener)
Add a listener that is notified each time beans are added, replaced, or removed in this scope.

Specified by:
addScopeListener in interface org.apache.commons.workflow.Scope
Parameters:
listener - The ScopeListener to be added

removeScopeListener

public void removeScopeListener(org.apache.commons.workflow.ScopeListener listener)
Remove a listener that is notified each time beans are added, replaced, or removed in this scope.

Specified by:
removeScopeListener in interface org.apache.commons.workflow.Scope
Parameters:
listener - The ScopeListener to be removed


Copyright © 2001-2005 The Apache Software Foundation. All Rights Reserved.