craigmcc 01/08/13 14:16:01
Added: workflow/src/java/org/apache/commons/workflow/base
BaseActivity.java BaseContext.java BaseScope.java
BaseStep.java
Log:
Initial check-in of the workflow management system proposal.
Revision Changes Path
1.1
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseActivity.java
Index: BaseActivity.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseActivity.java,v
1.1 2001/08/13 21:16:01 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/08/13 21:16:01 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.workflow.base;
import org.apache.commons.workflow.Activity;
import org.apache.commons.workflow.Step;
/**
* <p><strong>BaseActivity</strong> is a convenient base class for more
* sophisticated <code>Activity</code> implementations. It includes
* management of the static relationships of Steps to each other as part
* of an owning Activity.</p>
*
* @version $Revision: 1.1 $ $Date: 2001/08/13 21:16:01 $
* @author Craig R. McClanahan
*/
public class BaseActivity implements Activity {
// ----------------------------------------------------- Instance Variables
/**
* The first Step associated with this Activity.
*/
protected Step firstStep = null;
/**
* The last Step associated with this Activity.
*/
protected Step lastStep = null;
// ------------------------------------------------------------- Properties
/**
* Return the first Step associated with this Activity.
*/
public Step getFirstStep() {
return (this.firstStep);
}
/**
* Return the last Step associated with this Activity.
*/
public Step getLastStep() {
return (this.lastStep);
}
// --------------------------------------------------------- Public Methods
/**
* Add a new Step to the end of the sequence of Steps associated with
* this Activity.
*
* @param step The new step to be added
*/
public void addStep(Step step) {
if (firstStep == null) {
step.setPreviousStep(null);
step.setNextStep(null);
firstStep = step;
lastStep = step;
} else {
step.setPreviousStep(lastStep);
step.setNextStep(null);
lastStep.setNextStep(step);
lastStep = step;
}
}
}
1.1
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java
Index: BaseContext.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseContext.java,v
1.1 2001/08/13 21:16:01 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/08/13 21:16:01 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.workflow.base;
import java.util.EmptyStackException;
import org.apache.commons.collections.ArrayStack;
import org.apache.commons.workflow.Activity;
import org.apache.commons.workflow.Context;
import org.apache.commons.workflow.Step;
import org.apache.commons.workflow.StepException;
import org.apache.commons.workflow.Scope;
/**
* <strong>BaseContext</strong> is a basic <code>Context</code> implementation
* that can serve as a convenient base class for more sophisticated
* <code>Context</code> implementations.
*
* <p><strong>WARNING</strong> - No synchronization is performed within this
* class. If it is used in a multiple thread environment, callers must
* take suitable precations.</p>
*
* @version $Revision: 1.1 $ $Date: 2001/08/13 21:16:01 $
* @author Craig R. McClanahan
*/
public class BaseContext implements Context {
// ----------------------------------------------------------- Constructors
/**
* Construct a new BaseContext with all default values.
*/
public BaseContext() {
super();
names[LOCAL_SCOPE] = "local";
scopes[LOCAL_SCOPE] = new BaseScope();
}
// ----------------------------------------------------- Instance Variables
/**
* The <code>Activity</code> that we are associated with and executing
* <code>Steps</code> from (if any).
*/
protected Activity activity = null;
/**
* The set of names associated with the registered <code>Scopes</code>.
*/
protected String names[] = new String[MAX_SCOPES];
/**
* The <code>Step</code> that will be executed first the next time that
* <code>execute()</code> is called. This is maintained dynamically as
* execution proceeds, much like the "next instruction pointer" of a
* CPU tracks what instruction will be executed next.
*/
protected Step nextStep = null;
/**
* The set of <code>Scopes</code> that have been associated with
* this Context. When initially created, every Context has a
* Scope attached to identifier LOCAL_SCOPE already created.
*/
protected Scope scopes[] = new Scope[MAX_SCOPES];
/**
* The evaluation stack of nameless objects being processed.
*/
protected ArrayStack stack = new ArrayStack();
/**
* The suspension flag. If this is set when a particular <code>Step</code>
* returns, control will be returned from our <code>execute()</code>
* method to allow interaction with the rest of the application. The
* next time that <code>execute()</code> is called, execution will
* resume with the next scheduled step.
*/
protected boolean suspend = false;
// --------------------------------------------------- Scope Access Methods
// These methods provide Steps with the ability to get and set arbitrary
// objects in arbitrary scopes. When a scope is not mentioned explicitly,
// either LOCAL_SCOPE will be used, or scopes will be searched in
// increasing order of their identifiers, as specified in the various
// method descriptions.
/**
* Does a bean with the specified key exist in any specified scope?
* Scopes will be searched in ascending order of their identifiers,
* starting with LOCAL_SCOPE.
*
* @param key Key of the bean to be searched for (cannot be null)
*/
public boolean contains(String key) {
for (int i = 0; i < MAX_SCOPES; i++) {
if (scopes[i] == null)
continue;
if (scopes[i].containsKey(key))
return (true);
}
return (false);
}
/**
* Does a bean with the specified key exist in the specified scope?
*
* @param key Key of the bean to be searched for (cannot be null)
* @param scope Identifier of the scope to be returned.
*/
public boolean contains(String key, int scope) {
if (scopes[scope] == null)
return (false);
else
return (scopes[scope].containsKey(key));
}
/**
* Return the bean associated with the specified key, if it exists in
* any scope. Scopes will be searched in increasing order of their
* identifiers, starting with LOCAL_SCOPE. If the underlying Scope
* allows null values, a <code>null</code> return will be ambiguous.
* Therefore, you can use the <code>contains()</code> method to determine
* whether the key actually exists.
*
* @param key Key of the bean to be retrieved (cannot be null)
*/
public Object get(String key) {
for (int i = 0; i < MAX_SCOPES; i++) {
if (scopes[i] == null)
continue;
Object bean = scopes[i].get(key);
if (bean != null)
return (bean);
}
return (null);
}
/**
* Return the bean associated with the specified key, if it exists in
* the specified scope. If the underlying Scope allows null values,
* a <code>null</code> return will be ambiguous. Therefore, you can
* use the <code>contains()</code> method to determine whether the
* key actually exists.
*
* @param key Key of the bean to be searched for
* @param scope Identifier of the scope to be searched
*/
public Object get(String key, int scope) {
if (scopes[scope] == null)
return (null);
else
return (scopes[scope].get(key));
}
/**
* Store the specified bean under the specified key, in local scope,
* replacing any previous value for that key. Any previous value will
* be returned.
*
* @param key Key of the bean to be stored (cannot be null)
* @param value Value of the bean to be stored
*/
public Object put(String key, Object value) {
return (scopes[LOCAL_SCOPE].put(key, value));
}
/**
* Store the specified bean under the specified key, in the specified
* scope, replacing any previous value for that key. Any previous value
* will be returned.
*
* @param key Key of the bean to be stored (cannot be null)
* @param value Value of the bean to be stored
* @param scope Identifier of the scope to use for storage
*/
public Object put(String key, Object value, int scope) {
if (scopes[scope] == null)
return (null);
else
return (scopes[scope].put(key, value));
}
/**
* Remove any existing value for the specified key, in any scope.
* Scopes will be searched in ascending order of their identifiers,
* starting with LOCAL_SCOPE. Any previous value for this key will
* be returned.
*
* @param key Key of the bean to be removed
*/
public Object remove(String key) {
return (scopes[LOCAL_SCOPE].remove(key));
}
/**
* Remove any existing value for the specified key, from the specified
* scope. Any previous value for this key will be returned.
*
* @param key Key of the bean to be removed
* @param scope Scope the bean to be removed from
*/
public Object remove(String key, int scope) {
if (scopes[scope] == null)
return (null);
else
return (scopes[scope].remove(key));
}
// --------------------------------------------- Scope Registration Methods
// These methods provide capabilities to register and retrieve
// Scope implementations. Workflow engine implementations will
// register desired scopes when they create Context instances.
/**
* Register a Scope implementation under the specified identifier.
* It is not legal to replace the LOCAL_SCOPE implementation that is
* provided by the Context implementation.
*
* @param scope Scope identifier to register under
* @param name Scope name to register under
* @param impl Scope implementation to be registered (or null to
* remove a previous registration)
* @exception IllegalArgumentException if you attempt to register
* or deregister the local scope
*/
public void addScope(int scope, String name, Scope impl) {
if (scope == LOCAL_SCOPE)
throw new IllegalArgumentException("Cannot replace local scope");
if (impl == null) {
names[scope] = null;
scopes[scope] = null;
} else {
names[scope] = name;
scopes[scope] = impl;
}
}
/**
* Return the Scope implementation registered for the specified
* identifier, if any; otherwise, return <code>null</code>.
*
* @param scope Scope identifier to select
*/
public Scope getScope(int scope) {
return (scopes[scope]);
}
/**
* Return the Scope identifier registered for the specified
* name, if any; otherwise, return <code>-1</code>.
*
* @param name Scope name to select
*/
public int getScopeId(String name) {
for (int i = 0; i < names.length; i++) {
if (names[i] == null)
continue;
if (names[i].equals(name))
return (i);
}
return (-1);
}
// ----------------------------------------------- Evaluation Stack Methods
/**
* Clear the evaluation stack.
*/
public void clear() {
stack.clear();
}
/**
* Return the top item from the evaluation stack without removing it.
*
* @exception EmptyStackException if the stack is empty
*/
public Object peek() throws EmptyStackException {
return (stack.peek());
}
/**
* Pop and return the top item from the evaluation stack.
*
* @exception EmptyStackException if the stack is empty
*/
public Object pop() throws EmptyStackException {
return (stack.pop());
}
/**
* Push a new item onto the top of the evaluation stack.
*
* @param item New item to be pushed
*/
public void push(Object item) {
stack.push(item);
}
// ---------------------------------------------- Dynamic Execution Methods
// These methods are used to request the dynamic execution of the
// Steps related to a particular Activity.
/**
* <p>Execute the <code>Step</code> currently identified as the next
* step, and continue execution until there is no next step, or until
* the <code>suspend</code> property has been set to true.
*
* @exception StepException if an exception is thrown by the
* <code>execute()</code> method of a Step we have executed
* @exception IllegalStateException if there is no defined next step
* (either because there is no Activity, or because we have already
* completed all the steps of this activity)
*/
public void execute() throws StepException {
// Do we actually have a next step to be performed
if (activity == null)
throw new IllegalStateException("No Activity has been selected");
else if (nextStep == null)
throw new IllegalStateException("Activity has been completed");
// Reset the suspend flag until set by another step
suspend = false;
// Perform execution until suspended or completed
while (true) {
if (suspend)
break; // Suspend set by a Step
if (nextStep == null)
break; // We have completed this Activity
Step thisStep = nextStep;
nextStep = thisStep.getNextStep();
thisStep.execute(this);
}
}
/**
* <p>Return the <code>Activity</code> we will be executing when the
* <code>execute()</code> method is called, if any.</p>
*/
public Activity getActivity() {
return (this.activity);
}
/**
* <p>Set the <code>Activity</code> to be executed, and make the first
* defined <code>Step</code> within this <code>Activity</code> the next
* action to be performed by <code>execute()</code>.</p>
*
* <p>If <code>null</code> is passed, any currently associated Activity
* will be released, and the evaluation stack will be cleared.</p>
*
* <p><strong>WARNING</strong> - This will have to become more sophisticated
* in order to support calling nested Activities.</p>
*
* @param activity The new Activity to be executed, or <code>null</code>
* to release resources
*/
public void setActivity(Activity activity) {
if (activity == null) {
this.activity = null;
this.nextStep = null;
clear();
} else {
this.activity = activity;
this.nextStep = activity.getFirstStep();
}
}
/**
* <p>Return the <code>Step</code> that will be executed the next time
* that <code>execute()</code> is called, if any.</p>
*/
public Step getNextStep() {
return (this.nextStep);
}
/**
* <p>Set the <code>Step</code> that will be executed the next time
* that <code>execute()</code> is called. This is called by a
* <code>Step</code> that wants to perform branching based on some
* calculated results.</p>
*
* @param nextStep The next Step to be executed
*
* @exception IllegalArgumentException if the specified Step is not
* part of the current Activity
*/
public void setNextStep(Step nextStep) {
if (this.activity != nextStep.getActivity())
throw new IllegalArgumentException
("Step is not part of the current Activity");
this.nextStep = nextStep;
}
/**
* <p>Return the suspend flag.</p>
*/
public boolean getSuspend() {
return (this.suspend);
}
/**
* <p>Set the suspend flag. This is called by a <code>Step</code> that
* wants to signal the <code>Context</code> to return control to the
* caller of the <code>execute()</code> method before executing the
* next <code>Step</code> in the current activity.</p>
*
* @param suspend The new suspend flag
*/
public void setSuspend(boolean suspend) {
this.suspend = suspend;
}
}
1.1
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseScope.java
Index: BaseScope.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseScope.java,v
1.1 2001/08/13 21:16:01 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/08/13 21:16:01 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.workflow.base;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.commons.workflow.Scope;
import org.apache.commons.workflow.ScopeListener;
import org.apache.commons.workflow.util.ScopeSupport;
/**
* <strong>BaseScope</strong> is a basic <code>Scope</code> implementation
* that maintains its bean collection in an in-memory HashMap. This can
* also serve as a convenient base class for more sophisticated
* <code>Scope</code> implementations.
*
* <p><strong>WARNING</strong> - No synchronization is performed within this
* class. If it is used in a multiple thread environment, callers must
* take suitable precations.</p>
*
* @version $Revision: 1.1 $ $Date: 2001/08/13 21:16:01 $
* @author Craig R. McClanahan
*/
public class BaseScope implements Scope {
// ----------------------------------------------------- Instance Variables
/**
* The HashMap that contains our registered keys and beans.
*/
protected HashMap map = new HashMap();
/**
* The event listener support object for this <code>Scope</code>.
*/
protected ScopeSupport support = new ScopeSupport(this);
// ------------------------------------------------------------ Map Methods
/**
* Remove all beans from this Map and call <code>scopeCleared() on
* all registered <code>ScopeListeners</code>.
*/
public void clear() {
map.clear();
support.fireScopeCleared();
}
/**
* Return <code>true</code> if this map contains the specified key.
*
* @param key Key to be looked up
*/
public boolean containsKey(Object key) {
return (map.containsKey(key));
}
/**
* Return <code>true</code> if this map contains the specified value.
*
* @param value Value to be looked up
*/
public boolean containsValue(Object value) {
return (map.containsValue(value));
}
/**
* Return a set view of the mappings contained in this map.
*/
public Set entrySet() {
return (map.entrySet());
}
/**
* Compare the specified object with this map for equality.
*
* @param object Object to be compared
*/
public boolean equals(Object object) {
return (map.equals(object));
}
/**
* Return the value to which this map maps the specified key.
*
* @param key Key to be looked up
*/
public Object get(Object key) {
return (get((String) key));
}
/**
* Return the value to which this map maps the specified key.
*
* @param key Key to be looked up
*/
public Object get(String key) {
return (map.get(key));
}
/**
* Return the hash code value for this map.
*/
public int hashCode() {
return (map.hashCode());
}
/**
* Return <code>true</code> if this map is empty.
*/
public boolean isEmpty() {
return (map.isEmpty());
}
/**
* Return a set view of the keys contained in this map.
*/
public Set keySet() {
return (map.keySet());
}
/**
* Add or replace the bean associated with the specified key.
*
* @param key Key with which the new value should be associated
* (cannot be null)
* @param bean Bean to be associated with this key (cannot be null)
*/
public Object put(Object key, Object bean) {
return (put((String) key, 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 <code>beanAdded()</code> on all registered
* listeners after the add is done. If an old bean was replaced,
* call <code>beanReplaced()</code> (passing the old value in the event)
* on all registered <code>ScopeListeners</code> after the removal
* is done. If a bean was replaced, the old value is also returned;
* otherwise <code>null</code> is returned.
*
* @param key Key with which the new value should be associated
* (cannot be null)
* @param bean Bean to be associated with this key (cannot be null)
*
* @exception IllegalArgumentException if <code>key</code> or
* <code>bean</code> is null
*/
public Object put(String key, Object bean) {
if (key == null)
throw new IllegalArgumentException("Key cannot be null");
if (bean == null)
throw new IllegalArgumentException("Value cannot be null");
Object old = get(key);
if (map.containsKey(key)) {
map.put(key, bean);
support.fireBeanReplaced(key, old);
} else {
map.put(key, bean);
support.fireBeanAdded(key, bean);
}
return (old);
}
/**
* Copy all of the mappings from the specified map into this map,
* firing appropriate <code>beanAdded()</code> and
* <code>beanReplaced()</code> events along the way.
*
* @param in Map whose contents are to be added
*/
public void putAll(Map in) {
Iterator keys = in.keySet().iterator();
while (keys.hasNext()) {
Object key = keys.next();
put(key, in.get(key));
}
}
/**
* Remove the bean associated with the specified key (if any), and return
* the old value if removed.
*
* @param key Key of the bean to remove (cannot be null)
*/
public Object remove(Object key) {
return (remove((String) key));
}
/**
* Remove the bean associated with the specified key (if any). If such
* a bean is found and removed, call <code>beanRemoved()</code> on all
* registered <code>ScopeListeners</code> after the removal is done.
* Return the old value (if any); otherwise return <code>null</code>.
*
* @param key Key of the bean to remove (cannot be null)
*
* @exception IllegalArgumentException if <code>key</code> is null
*/
public Object remove(String key) {
if (map.containsKey(key)) {
Object old = map.remove(key);
support.fireBeanRemoved(key, old);
return (old);
}
return (null);
}
/**
* Return the number of key-value mappings in this map.
*/
public int size() {
return (map.size());
}
/**
* Return a Collection view of the values contained in this map.
*/
public Collection values() {
return (map.values());
}
// ------------------------------------------------- Event Listener Methods
/**
* Add a listener that is notified each time beans are added,
* replaced, or removed in this scope.
*
* @param listener The ScopeListener to be added
*/
public void addScopeListener(ScopeListener listener) {
support.addScopeListener(listener);
}
/**
* Remove a listener that is notified each time beans are added,
* replaced, or removed in this scope.
*
* @param listener The ScopeListener to be removed
*/
public void removeScopeListener(ScopeListener listener) {
support.removeScopeListener(listener);
}
}
1.1
jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseStep.java
Index: BaseStep.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseStep.java,v
1.1 2001/08/13 21:16:01 craigmcc Exp $
* $Revision: 1.1 $
* $Date: 2001/08/13 21:16:01 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.workflow.base;
import org.apache.commons.workflow.Activity;
import org.apache.commons.workflow.Context;
import org.apache.commons.workflow.Step;
import org.apache.commons.workflow.StepException;
/**
* <p><strong>BaseStep</strong> is a convenient base class for more sophisticated
* <code>Step</code> implementations. It includes management of the static
* relationships of Steps to each other, and to their owning Activity, but
* requires the implementation to provide an <code>execute()</code> method.
*
* @version $Revision: 1.1 $ $Date: 2001/08/13 21:16:01 $
* @author Craig R. McClanahan
*/
public abstract class BaseStep implements Step {
// ----------------------------------------------------- Instance Variables
/**
* The Activity that owns this Step.
*/
protected Activity activity = null;
/**
* The unique identifier (within this Activity) of this Step.
*/
protected String id = null;
/**
* The next Step in our associated Activity.
*/
protected Step nextStep = null;
/**
* The previous Step in our associated Activity.
*/
protected Step previousStep = null;
// ------------------------------------------------------------- Properties
/**
* Return the Activity that owns this Step.
*/
public Activity getActivity() {
return (this.activity);
}
/**
* Set the Activity that owns this Step.
*
* @param activity The new owning Activity
*/
public void setActivity(Activity activity) {
this.activity = activity;
}
/**
* Return the unique identifier (within this Activity) of this Step.
*/
public String getId() {
return (this.id);
}
/**
* Set the unique identifier (within this Activity) of this Step.
*
* @param id The new unique identifier
*/
public void setId(String id) {
this.id = id;
}
/**
* Return the next Step in our associated Activity.
*/
public Step getNextStep() {
return (this.nextStep);
}
/**
* Set the next Step in our associated Activity.
*
* @param nextStep The new next Step
*/
public void setNextStep(Step nextStep) {
this.nextStep = nextStep;
}
/**
* Return the previous Step in our associated Activity.
*/
public Step getPreviousStep() {
return (this.previousStep);
}
/**
* Set the previous Step in our associated Activity.
*
* @param previousStep The new previous Step
*/
public void setPreviousStep(Step previousStep) {
this.previousStep = previousStep;
}
// --------------------------------------------------------- Public Methods
/**
* Perform the executable actions related to this Step, in the context of
* the specified Context.
*
* @param context The Context that is tracking our execution state
*
* @exception StepException if a processing error has occurred
*/
public abstract void execute(Context context) throws StepException;
}