org.oddjob.state
Class IfJob

java.lang.Object
  extended by org.oddjob.framework.BaseComponent
      extended by org.oddjob.framework.BasePrimary
          extended by org.oddjob.framework.StructuralJob<Object>
              extended by org.oddjob.state.IfJob
All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, 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

Field Summary
 
Fields inherited from class org.oddjob.framework.StructuralJob
childHelper, childStateReflector, stateHandler, stop, structuralState
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Constructor Summary
IfJob()
           
 
Method Summary
protected  void execute()
          Execute this job.
protected  StateOperator getInitialStateOp()
          Subclasses must provide the StateOperator that will decide how to evaluate the children's state.
 StateCondition getState()
          Getter for state.
 void setJobs(int index, Object job)
           
 void setState(StateCondition state)
           
 
Methods inherited from class org.oddjob.framework.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, hardReset, isStop, onDestroy, onReset, onStop, removeStructuralListener, run, softReset, startChildStateReflector, stateHandler, stop
 
Methods inherited from class org.oddjob.framework.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toString
 
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 class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 
Methods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
 
Methods inherited from interface org.oddjob.Resetable
hardReset, softReset
 
Methods inherited from interface org.oddjob.Structural
addStructuralListener, removeStructuralListener
 
Methods inherited from interface org.oddjob.Stoppable
stop
 

Constructor Detail

IfJob

public IfJob()
Method Detail

getState

public StateCondition getState()
Getter for state.

Returns:
The state.

setState

public void setState(StateCondition state)

Property: state

Description: The state condition to check against. See the Oddjob User guide for a full list of state conditions.

Required: No, defaults to COMPLETE.


setJobs

public void setJobs(int index,
                    Object job)

Property: jobs

Description: The child jobs.

Required: At least one.


getInitialStateOp

protected StateOperator getInitialStateOp()
Description copied from class: StructuralJob
Subclasses must provide the StateOperator that will decide how to evaluate the children's state.

Specified by:
getInitialStateOp in class StructuralJob<Object>
Returns:
A State Operator. Must not be null.

execute

protected void execute()
Description copied from class: StructuralJob
Execute this job.

Specified by:
execute in class StructuralJob<Object>