org.oddjob.state
Class IfJob
java.lang.Object
org.oddjob.framework.BaseComponent
org.oddjob.framework.BasePrimary
org.oddjob.framework.StructuralJob<Object>
org.oddjob.state.IfJob
- All Implemented Interfaces:
- Serializable, Runnable, ArooaContextAware, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful, Stoppable, Structural
public class IfJob
- extends StructuralJob<Object>
- implements Runnable, Stateful, Resetable, Structural, Stoppable
Description
This job implements an if/then/else logic. This job can contain
any number of child jobs. The first job is taken to be the condition.
If the resulting state matches the given state the second job is
executed. If it doesn't then the third job is executed, (if it exists).
The completion state is that of the then or else job. If either don't
exist then the Job is flagged as complete.
If any more than three jobs are provided the extra jobs are ignored.
Example
If a file exists.
<oddjob id="this" xmlns:state="http://rgordon.co.uk/oddjob/state">
<job>
<state:if>
<jobs>
<exists name="Check File Exists" file="${this.dir}/data/some.txt"/>
<echo id="then" name="Echo to Console">File Exists</echo>
<echo id="else" name="Echo to Console">File Doesn't Exist</echo>
</jobs>
</state:if>
</job>
</oddjob>
Example
An example showing lots of if's. All these if's go to COMPLETE state
when run.
<oddjob>
<job>
<sequential xmlns:state="http://rgordon.co.uk/oddjob/state">
<jobs>
<state:if>
<jobs>
<echo>Hello</echo>
<echo>Good Bye</echo>
</jobs>
</state:if>
<state:if>
<jobs>
<state:flag name="Exception" state="EXCEPTION"/>
<state:flag name="Unexpected 1" state="EXCEPTION"/>
<echo>No Hello</echo>
</jobs>
</state:if>
<state:if>
<jobs>
<echo>Only Hello</echo>
</jobs>
</state:if>
<state:if state="!COMPLETE">
<jobs>
<state:flag name="Exception" state="EXCEPTION"/>
<echo>No Hello</echo>
</jobs>
</state:if>
<state:if state="!COMPLETE">
<jobs>
<echo>Hello</echo>
<state:flag name="Unexpected 2" state="EXCEPTION"/>
</jobs>
</state:if>
<state:if state="!EXCEPTION">
<jobs>
<echo>Hello</echo>
<echo>Good Bye</echo>
<state:flag name="Unexpected 3" state="EXCEPTION"/>
</jobs>
</state:if>
</jobs>
</sequential>
</job>
</oddjob>
- See Also:
- Serialized Form
- Author:
- Rob Gordon
|
Constructor Summary |
IfJob()
|
| Methods inherited from class org.oddjob.framework.StructuralJob |
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, onDestroy, onReset, onStop, removeStructuralListener, run, softReset, startChildStateReflector, stateHandler, stop |
| Methods inherited from class org.oddjob.framework.BaseComponent |
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSession |
| Methods inherited from interface java.lang.Runnable |
run |
IfJob
public IfJob()
getState
public StateCondition getState()
- Getter for state.
- Returns:
- The state.
setState
public void setState(StateCondition state)
Property: state
Description: The state to check against.
Required: No, defaults to COMPLETE.
setJobs
public void setJobs(int index,
Runnable job)
Property: jobs
Description: The child jobs.
Required: At least one.
getStateOp
protected StateOperator getStateOp()
- Specified by:
getStateOp in class StructuralJob<Object>
execute
protected void execute()
- Description copied from class:
StructuralJob
- Execute this job.
- Specified by:
execute in class StructuralJob<Object>