org.apache.lenya.workflow.impl
Class WorkflowInstanceImpl

java.lang.Object
  extended by org.apache.lenya.workflow.impl.WorkflowInstanceImpl
All Implemented Interfaces:
WorkflowInstance
Direct Known Subclasses:
WorkflowDocument

public abstract class WorkflowInstanceImpl
extends java.lang.Object
implements WorkflowInstance

Implementation of a workflow instance.


Constructor Summary
protected WorkflowInstanceImpl()
          Creates a new instance of WorkflowInstanceImpl.
 
Method Summary
 void addWorkflowListener(WorkflowListener listener)
          Adds a workflow listener.
protected  void fire(TransitionImpl transition)
          Invokes a transition.
 State getCurrentState()
          Returns the current state of this WorkflowInstance.
 Event[] getExecutableEvents(Situation situation)
          Returns the events that can be invoked in a certain situation.
protected  TransitionImpl getNextTransition(Event event)
          Returns the transition that would fire for a given event.
protected  State getState(java.lang.String id)
          Returns a workflow state for a given name.
 boolean getValue(java.lang.String variableName)
          Returns the current value of a variable.
protected  BooleanVariableInstance getVariableInstance(BooleanVariable variable)
          Returns the corresponding instance of a workflow variable.
 Workflow getWorkflow()
          Returns the workflow object of this instance.
protected abstract  WorkflowImpl getWorkflow(java.lang.String workflowName)
          Factory method to create a workflow object for a given identifier.
protected  WorkflowImpl getWorkflowImpl()
          Returns the workflow object of this instance.
protected  void initVariableInstances()
          Initializes the variable instances in the initial state.
 void invoke(Situation situation, Event event)
          Invoke an event on this workflow instance.
 boolean isSynchronized(Event event)
          Returns if the transition for a certain event is synchronized.
 void removeWorkflowListener(WorkflowListener listener)
          Removes a workflow listener.
protected  void setCurrentState(State state)
          Sets the current state of this instance.
protected  void setValue(java.lang.String variableName, boolean value)
          Sets the value of a state variable.
protected  void setWorkflow(java.lang.String workflowName)
          Sets the workflow of this instance.
protected  void setWorkflow(WorkflowImpl workflow)
          Sets the workflow of this instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkflowInstanceImpl

protected WorkflowInstanceImpl()
Creates a new instance of WorkflowInstanceImpl.

Method Detail

getWorkflow

public Workflow getWorkflow()
Returns the workflow object of this instance.

Specified by:
getWorkflow in interface WorkflowInstance
Returns:
A workflow object.

getWorkflowImpl

protected WorkflowImpl getWorkflowImpl()
Returns the workflow object of this instance.

Returns:
A workflow object.

getExecutableEvents

public Event[] getExecutableEvents(Situation situation)
                            throws WorkflowException
Returns the events that can be invoked in a certain situation.

Specified by:
getExecutableEvents in interface WorkflowInstance
Parameters:
situation - The situation to check.
Returns:
The events that can be invoked.
Throws:
WorkflowException - when something went wrong.

invoke

public void invoke(Situation situation,
                   Event event)
            throws WorkflowException
Invoke an event on this workflow instance.

Specified by:
invoke in interface WorkflowInstance
Parameters:
situation - The situation when the event was invoked.
event - The event that was invoked.
Throws:
WorkflowException - when the event may not be invoked.

getNextTransition

protected TransitionImpl getNextTransition(Event event)
                                    throws WorkflowException
Returns the transition that would fire for a given event.

Parameters:
event - The event.
Returns:
A transition.
Throws:
WorkflowException - if no single transition would fire.

fire

protected void fire(TransitionImpl transition)
             throws WorkflowException
Invokes a transition.

Parameters:
transition - The transition to invoke.
Throws:
WorkflowException - if something goes wrong.

setCurrentState

protected void setCurrentState(State state)
Sets the current state of this instance.

Parameters:
state - The state to set.

getCurrentState

public State getCurrentState()
Returns the current state of this WorkflowInstance.

Specified by:
getCurrentState in interface WorkflowInstance
Returns:
A state object.

setWorkflow

protected void setWorkflow(WorkflowImpl workflow)
Sets the workflow of this instance.

Parameters:
workflow - A workflow object.

setWorkflow

protected void setWorkflow(java.lang.String workflowName)
                    throws WorkflowException
Sets the workflow of this instance.

Parameters:
workflowName - The identifier of the workflow.
Throws:
WorkflowException - if something goes wrong.

getWorkflow

protected abstract WorkflowImpl getWorkflow(java.lang.String workflowName)
                                     throws WorkflowException
Factory method to create a workflow object for a given identifier.

Parameters:
workflowName - The workflow identifier.
Returns:
A workflow object.
Throws:
WorkflowException - when the workflow could not be created.

getState

protected State getState(java.lang.String id)
                  throws WorkflowException
Returns a workflow state for a given name.

Parameters:
id - The state id.
Returns:
A workflow object.
Throws:
WorkflowException - when the state was not found.

initVariableInstances

protected void initVariableInstances()
Initializes the variable instances in the initial state.


getVariableInstance

protected BooleanVariableInstance getVariableInstance(BooleanVariable variable)
                                               throws WorkflowException
Returns the corresponding instance of a workflow variable.

Parameters:
variable - A variable of the corresponding workflow.
Returns:
A variable instance object.
Throws:
WorkflowException - when the variable instance was not found.

getValue

public boolean getValue(java.lang.String variableName)
                 throws WorkflowException
Description copied from interface: WorkflowInstance
Returns the current value of a variable.

Specified by:
getValue in interface WorkflowInstance
Parameters:
variableName - A variable name.
Returns:
A boolean value.
Throws:
WorkflowException - when the variable does not exist.
See Also:
WorkflowInstance.getValue(java.lang.String)

setValue

protected void setValue(java.lang.String variableName,
                        boolean value)
                 throws WorkflowException
Sets the value of a state variable.

Parameters:
variableName - The variable name.
value - The value to set.
Throws:
WorkflowException - when the variable was not found.

addWorkflowListener

public void addWorkflowListener(WorkflowListener listener)
Description copied from interface: WorkflowInstance
Adds a workflow listener.

Specified by:
addWorkflowListener in interface WorkflowInstance
Parameters:
listener - The listener to add.
See Also:
WorkflowInstance.addWorkflowListener(org.apache.lenya.workflow.WorkflowListener)

removeWorkflowListener

public void removeWorkflowListener(WorkflowListener listener)
Description copied from interface: WorkflowInstance
Removes a workflow listener.

Specified by:
removeWorkflowListener in interface WorkflowInstance
Parameters:
listener - The listener to remove.
See Also:
WorkflowInstance.removeWorkflowListener(org.apache.lenya.workflow.WorkflowListener)

isSynchronized

public boolean isSynchronized(Event event)
                       throws WorkflowException
Description copied from interface: WorkflowInstance
Returns if the transition for a certain event is synchronized.

Specified by:
isSynchronized in interface WorkflowInstance
Parameters:
event - An event.
Returns:
A boolean value.
Throws:
WorkflowException
See Also:
WorkflowInstance.isSynchronized(org.apache.lenya.workflow.Event)


Copyright © 1999-2005 Apache Software Foundation. All Rights Reserved.