|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.workflow.base.BaseContext
public class BaseContext
BaseContext is a basic Context
implementation
that can serve as a convenient base class for more sophisticated
Context
implementations.
WARNING - No synchronization is performed within this class. If it is used in a multiple thread environment, callers must take suitable precations.
Field Summary | |
---|---|
protected Activity |
activity
The Activity that we are associated with and executing
Steps from (if any). |
protected BaseContextBean |
bean
The bean representing the information about this Context made visible through JXPath. |
protected org.apache.commons.collections.ArrayStack |
calls
The suspended "next step" Step for each in-progress Activity that has issued a call() to execute a subordinate Activity. |
protected String[] |
names
The set of names associated with the registered Scopes . |
protected Step |
nextStep
The Step that will be executed first the next time that
execute() is called. |
protected Scope[] |
scopes
The set of Scopes that have been associated with
this Context. |
protected org.apache.commons.collections.ArrayStack |
stack
The evaluation stack of nameless objects being processed. |
protected org.apache.commons.collections.ArrayStack |
state
The BlockState stack of BlockState objects used to manage iteration. |
protected ContextSupport |
support
The event listener support object for this Context . |
protected boolean |
suspend
The suspension flag. |
Fields inherited from interface org.apache.commons.workflow.Context |
---|
LOCAL_SCOPE, MAX_SCOPES |
Constructor Summary | |
---|---|
BaseContext()
Construct a new BaseContext with all default values. |
Method Summary | |
---|---|
void |
addContextListener(ContextListener listener)
Add a listener that is notified each time beans are added, replaced, or removed in this context. |
void |
addScope(int scope,
String name,
Scope impl)
Register a Scope implementation under the specified identifier. |
void |
call(Activity activity)
Save the execution state (ie the currently assigned next step) of the Activity we are currently executing, and begin executing the specified Activity. |
void |
clear()
Clear the evaluation stack. |
void |
clearBlockState()
Clear the BlockState stack. |
boolean |
contains(String key)
Return true if a bean with the specified key exist in any specified scope. |
boolean |
contains(String key,
int scope)
Does a bean with the specified key exist in the specified scope? |
void |
execute()
Execute the Step currently identified as the next
step, and continue execution until there is no next step, or until
the suspend property has been set to true. |
Object |
get(String key)
Return the bean associated with the specified key, if it exists in any scope. |
Object |
get(String key,
int scope)
Return the bean associated with the specified key, if it exists in the specified scope. |
Activity |
getActivity()
Return the Activity we will be executing when the
execute() method is called, if any. |
Step[] |
getCalls()
Return the set of pending Step executions that are pending because of calls to subordinate Activities have occurred. |
org.apache.commons.jxpath.JXPathContext |
getJXPathContext()
Return the JXPathContext object that represents a unified namespace covering all of our registered Scopes . |
Scope |
getLocal()
Return the Scope instance for our local Scope as a simple property. |
Step |
getNextStep()
Return the Step that will be executed the next time
that execute() is called, if any. |
Scope |
getScope(int scope)
Return the Scope implementation registered for the specified identifier, if any; otherwise, return null . |
Scope |
getScope(String name)
Return the Scope implementation registered for the specified name, if any; otherwise, return null . |
int |
getScopeId(String name)
Return the Scope identifier registered for the specified name, if any; otherwise, return -1 . |
boolean |
getSuspend()
Return the suspend flag. |
boolean |
isEmpty()
Is the evaluation stack currently empty? |
boolean |
isEmptyBlockState()
Is the BlockState stack currently empty? |
Object |
peek()
Return the top item from the evaluation stack without removing it. |
BlockState |
peekBlockState()
Return the top item from the BlockState stack without removing it. |
Object |
pop()
Pop and return the top item from the evaluation stack. |
BlockState |
popBlockState()
Pop and return the top item from the BlockState stack. |
void |
push(Object item)
Push a new item onto the top of the evaluation stack. |
void |
pushBlockState(BlockState item)
Push a new item onto the top of the BlockState stack. |
Object |
put(String key,
Object value)
Store the specified bean under the specified key, in local scope, replacing any previous value for that key. |
Object |
put(String key,
Object value,
int scope)
Store the specified bean under the specified key, in the specified scope, replacing any previous value for that key. |
Object |
remove(String key)
Remove any existing value for the specified key, in any scope. |
Object |
remove(String key,
int scope)
Remove any existing value for the specified key, from the specified scope. |
void |
removeContextListener(ContextListener listener)
Remove a listener that is notified each time beans are added, replaced, or removed in this context. |
void |
setActivity(Activity activity)
Set the Activity to be executed, and make the first
defined Step within this Activity the next
action to be performed by execute() . |
void |
setNextStep(Step nextStep)
Set the Step that will be executed the next time
that execute() is called. |
void |
setSuspend(boolean suspend)
Set the suspend flag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Activity activity
Activity
that we are associated with and executing
Steps
from (if any).
protected BaseContextBean bean
protected org.apache.commons.collections.ArrayStack calls
call()
to execute a subordinate Activity.
protected String[] names
Scopes
.
protected Step nextStep
Step
that will be executed first the next time that
execute()
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 Scope[] scopes
Scopes
that have been associated with
this Context. When initially created, every Context has a
Scope attached to identifier LOCAL_SCOPE already created.
protected org.apache.commons.collections.ArrayStack stack
protected org.apache.commons.collections.ArrayStack state
protected ContextSupport support
Context
.
protected boolean suspend
Step
returns, control will be returned from our execute()
method to allow interaction with the rest of the application. The
next time that execute()
is called, execution will
resume with the next scheduled step.
Constructor Detail |
---|
public BaseContext()
Method Detail |
---|
public boolean contains(String key)
contains
in interface Context
key
- Key of the bean to be searched for (cannot be null)public boolean contains(String key, int scope)
contains
in interface Context
key
- Key of the bean to be searched for (cannot be null)scope
- Identifier of the scope to be returned.public Object get(String key)
null
return will be ambiguous.
Therefore, you can use the contains()
method to determine
whether the key actually exists.
get
in interface Context
key
- Key of the bean to be retrieved (cannot be null)public Object get(String key, int scope)
null
return will be ambiguous. Therefore, you can
use the contains()
method to determine whether the
key actually exists.
get
in interface Context
key
- Key of the bean to be searched forscope
- Identifier of the scope to be searchedpublic Object put(String key, Object value)
put
in interface Context
key
- Key of the bean to be stored (cannot be null)value
- Value of the bean to be storedpublic Object put(String key, Object value, int scope)
put
in interface Context
key
- Key of the bean to be stored (cannot be null)value
- Value of the bean to be storedscope
- Identifier of the scope to use for storagepublic Object remove(String key)
remove
in interface Context
key
- Key of the bean to be removedpublic Object remove(String key, int scope)
remove
in interface Context
key
- Key of the bean to be removedscope
- Scope the bean to be removed frompublic void addScope(int scope, String name, Scope impl)
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.
In addition to registering the new Scope such that it can be
accessed dirctly via calls like Context.get(String,int)
,
the Scope impl
object will also be added to the LOCAL
Scope under the same name. This makes possible a single unified
namespace of all accessible objects that can be navigated by
expression languages.
addScope
in interface Context
scope
- Scope identifier to register undername
- Scope name to register underimpl
- Scope implementation to be registered (or null to
remove a previous registration)
IllegalArgumentException
- if you attempt to register
or deregister the local scopepublic Scope getLocal()
public Scope getScope(int scope)
null
.
getScope
in interface Context
scope
- Scope identifier to selectpublic Scope getScope(String name)
null
.
getScope
in interface Context
name
- Scope name to selectpublic int getScopeId(String name)
-1
.
getScopeId
in interface Context
name
- Scope name to selectpublic void clear()
clear
in interface Context
public boolean isEmpty()
isEmpty
in interface Context
public Object peek() throws EmptyStackException
peek
in interface Context
EmptyStackException
- if the stack is emptypublic Object pop() throws EmptyStackException
pop
in interface Context
EmptyStackException
- if the stack is emptypublic void push(Object item)
push
in interface Context
item
- New item to be pushedpublic void clearBlockState()
clearBlockState
in interface Context
public boolean isEmptyBlockState()
isEmptyBlockState
in interface Context
public BlockState peekBlockState() throws EmptyStackException
peekBlockState
in interface Context
EmptyStackException
- if the stack is emptypublic BlockState popBlockState() throws EmptyStackException
popBlockState
in interface Context
EmptyStackException
- if the stack is emptypublic void pushBlockState(BlockState item)
pushBlockState
in interface Context
item
- New item to be pushedpublic void call(Activity activity)
Save the execution state (ie the currently assigned next step) of the Activity we are currently executing, and begin executing the specified Activity. When that Activity exits (either normally or by throwing an exception), the previous Activity will be resumed where it left off.
call
in interface Context
activity
- The Activity to be calledpublic void execute() throws StepException
Execute the Step
currently identified as the next
step, and continue execution until there is no next step, or until
the suspend
property has been set to true. Upon
completion of an activity, any execution state that was saved to due
to utilizing the call()
method will be restored, and
the saved Activity execution shall be resumed.
execute
in interface Context
StepException
- if an exception is thrown by the
execute()
method of a Step we have executed
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 Activity getActivity()
Return the Activity
we will be executing when the
execute()
method is called, if any.
getActivity
in interface Context
public Step[] getCalls()
public org.apache.commons.jxpath.JXPathContext getJXPathContext()
Scopes
.
getJXPathContext
in interface Context
public Step getNextStep()
Return the Step
that will be executed the next time
that execute()
is called, if any.
getNextStep
in interface Context
public boolean getSuspend()
Return the suspend flag.
getSuspend
in interface Context
public void setActivity(Activity activity)
Set the Activity
to be executed, and make the first
defined Step
within this Activity
the next
action to be performed by execute()
.
If null
is passed, any currently associated Activity
will be released, and the evaluation stack and nested call state
stack will be cleared.
WARNING - This will have to become more sophisticated in order to support calling nested Activities.
setActivity
in interface Context
activity
- The new Activity to be executed, or null
to release resourcespublic void setNextStep(Step nextStep)
Set the Step
that will be executed the next time
that execute()
is called. This is called by a
Step
that wants to perform branching based on some
calculated results.
setNextStep
in interface Context
nextStep
- The next Step to be executed
IllegalArgumentException
- if the specified Step is not
part of the current Activitypublic void setSuspend(boolean suspend)
Set the suspend flag. This is called by a Step
that
wants to signal the Context
to return control to the
caller of the execute()
method before executing the
next Step
in the current activity.
setSuspend
in interface Context
suspend
- The new suspend flagpublic void addContextListener(ContextListener listener)
addContextListener
in interface Context
listener
- The ContextListener to be addedpublic void removeContextListener(ContextListener listener)
removeContextListener
in interface Context
listener
- The ContextListener to be removed
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |