Class Oddjob
- All Implemented Interfaces:
Serializable,Runnable,ArooaContextAware,ArooaSessionAware,ConfigurationOwner,BeanDirectoryOwner,Describer,Forceable,PropertyChangeNotifier,Iconic,Loadable,LogEnabled,Resettable,Stateful,Stoppable,Structural
- Author:
- Rob Gordon
- See Also:
- job
- The top level job. This is the single job that Oddjob runs. This property is optional but Oddjob won't do much if a job for it to run isn't supplied. This is the Oddjob root's only writeable property and is write only.
- file
- The path of the configuration file that Oddjob has loaded. Read Only.
- dir
- The path of the configuration file's directory. Read Only.
- args
- An array of arguments passed in on the command line or from a parent Oddjob. See below. Read Only.
- services
- Provides access to Oddjobs underlying services. Used by the frameworks automatic configuration mechanism to configure the properties of jobs that are documented as set automatically. May be ignored for every day use. Read Only.
Description
The starting point for a hierarchy of jobs. The Oddjob job creates and runs a job hierarchy by processing a supplied configuration.Oddjob creates a 'root' job on which to create the hierarchy. Through this root Oddjob aquires the first job to run and also exposes some of it's own properties for the jobs in the configuration to use. The root job's properties are:
For these properties to be accessible the root oddjob must be given an id.
As can be seen from the examples, the author uses the id 'this'
but the choice is arbitrary.
An Oddjob job allows an Oddjob instance to be created within an existing Oddjob configuration. This way complicated processes can be created in manageable and separately testable units.
Properties of jobs in a nested Oddjob can be accessed using the notation ${nested-oddjob-id/job-id.property} where nested-oddjob-id is the id in the outer configuration, not the inner one. Saving Oddjob's State
The persister property on a nested Oddjob will allow it's state to
be saved. See the
User Guide
for more information on how to set a persister.
Customising Oddjob
Oddjob's descriptorFactory and classLoader properties
allow bespoke components and
types to be used. The
developer guide
is all about writing custom job's for Oddjob.
Example
Hello World with Oddjob. Oddjob is configured to run theEchoJob job.
<oddjob>
<job>
<echo id="echo">Hello World</echo>
</job>
</oddjob>
Using an argument passed into Oddjob that may or may not be set.
<oddjob id="this">
<job>
<sequential>
<jobs>
<state:if xmlns:state="http://rgordon.co.uk/oddjob/state">
<jobs>
<check value="${this.args[0]}"/>
<properties>
<values>
<value key="our.file.name" value="${this.args[0]}"/>
</values>
</properties>
<input>
<requests>
<input-text prompt="File Name?" property="our.file.name"/>
</requests>
</input>
</jobs>
</state:if>
<echo>File Name is ${our.file.name}</echo>
</jobs>
</sequential>
</job>
</oddjob>
Nesting Oddjob. Note how the dir property of the
Oddjob root is used as the path of the nested configuration file.
<oddjob id="this">
<job>
<sequential>
<jobs>
<oddjob id="nested" file="${this.dir}/HelloWorld.xml"/>
<echo>Nested job said: ${nested/echo.text}</echo>
</jobs>
</sequential>
</job>
</oddjob>
The nested job is the first example:
<oddjob>
<job>
<echo id="echo">Hello World</echo>
</job>
</oddjob>
This example also shows how a property within the nested file can be
accessed within the parent configuration.A nested Oddjob with one argument passed to the child.
<oddjob id="this">
<job>
<oddjob id="nested" file="${this.dir}/EchoArg.xml">
<args>
<list>
<values>
<value value="Hello World"/>
</values>
</list>
</args>
</oddjob>
</job>
</oddjob>
And EchoArg.xml:
<oddjob id="this">
<job>
<echo id="echo">${this.args[0]}</echo>
</job>
</oddjob>
A nested Oddjob with a property past to the child.
<oddjob id="this">
<job>
<oddjob id="nested" file="${this.dir}/EchoProperty.xml">
<properties>
<properties>
<values>
<value key="our.greeting" value="Hello World"/>
</values>
</properties>
</properties>
</oddjob>
</job>
</oddjob>
And EchoProperty.xml:
<oddjob id="this">
<job>
<echo id="echo">${our.greeting}</echo>
</job>
</oddjob>
Unlike the properties of jobs, free format properties like this can't be
accessed using the nested convention.
${nested/our.greeting} DOES NOT WORK!
This may be fixed in future versions.Using export to pass values to a nested Oddjob.
<oddjob>
<job>
<sequential>
<jobs>
<folder>
<jobs>
<echo id="secret">I'm a secret job</echo>
</jobs>
</folder>
<oddjob id="inner">
<export>
<value key="secret" value="${secret}"/>
</export>
<configuration>
<arooa:configuration xmlns:arooa="http://rgordon.co.uk/oddjob/arooa">
<xml>
<xml>
<oddjob>
<job>
<run job="${secret}"/>
</job>
</oddjob>
</xml>
</xml>
</arooa:configuration>
</configuration>
</oddjob>
</jobs>
</sequential>
</job>
</oddjob>
Here a job is exported into a nested Oddjob. The
exported object is actually a ValueType. The value is converted back
to the job when the job property of the run job is set. Expressions such
as ${secret.text} are not valid (because value does not have a
text property!). Even ${secret.value.text} will not work because
of value wraps the job in yet another layer of complexity.Examples elsewhere.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassThe object which is the Oddjob root.static classProvide anArooaBeanDescriptorfor the root Oddjob bean. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ArooaElementThe document root for an Oddjob configuration file.Fields inherited from class org.oddjob.framework.extend.StructuralJob
childHelper, destroy, stop, structuralState -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOwnerStateListener(OwnerStateListener listener) Add a listener.Describe a bean.protected voidexecute()Execute this job.String[]getArgs()Return a class loader.Getter.getDir()GettergetFile()Getter.protected StateOperatorSubclasses must provide theStateOperatorthat will decide how to evaluate the children's state.Getter.org.oddjob.Oddjob.ResetGetter for last reset.Getter forOddjobExecutorsthat have been given to this instance of Oddjob.Getter forOddjobServices.Getter.booleanPerform a hard reset.booleanIs the component currently loadable.voidload()Load the component.protected voidSubclasses override this method to clear up resources.Get theBeanDirectory.Provide aConfigurationSession.voidremoveOwnerStateListener(OwnerStateListener listener) Remove a listener.Get the design factory for the configuration.Get the root element.voidvoidsetClassLoader(ClassLoader classLoader) voidsetConfiguration(ArooaConfiguration config) Setter for configuration.voidsetDescriptorFactory(ArooaDescriptorFactory descriptorFactory) Setter.voidsetExport(String key, ArooaValue value) Setter.voidvoidsetInheritance(OddjobInheritance inheritance) Setter.voidsetInputHandler(InputHandler inputHandler) Setter.voidsetOddjobExecutors(OddjobExecutors executors) Setter.voidsetOddjobServices(OddjobServices oddjobServices) Allow for injection ofOddjobServicesvoidsetPersister(OddjobPersister persister) voidsetProperties(Properties properties) Setter.booleanPerform a soft reset on the job.toString()Override toString.voidunload()Unload the component.Methods inherited from class org.oddjob.framework.extend.StructuralJob
addStructuralListener, fireDestroyedState, force, getStateChanger, iconHelper, isStop, onHardReset, onReset, onSoftReset, onStop, postStop, removeStructuralListener, run, startChildStateReflector, stateHandler, stop, stopChildStateReflector, waitForChildrenOnStopMethods inherited from class org.oddjob.framework.extend.BasePrimary
configure, getName, logger, logger, loggerName, save, setNameMethods inherited from class org.oddjob.framework.extend.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSessionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
-
Field Details
-
ODDJOB_ELEMENT
The document root for an Oddjob configuration file.
-
-
Constructor Details
-
Oddjob
public Oddjob()Only constructor.
-
-
Method Details
-
setFile
- Parameters:
file- The file name.- Reference Property:
- file
- Required:
- No.
Description
The name of the configuration file. to configure this oddjob. -
getFile
-
setConfiguration
Setter for configuration.- Parameters:
config-
-
setClassLoader
- Reference Property:
- classLoader
- Required:
- No.
Description
The classLoader to use when loading the configuration. This classloader will also be made available to child components that inject a classloader. This might not always be what is required as this classloader defaults to the application classloader not the Oddball classloader that will have loaded an Oddball component. This might be changed in future versions of Oddjob.See also
URLClassLoaderType -
getClassLoader
Return a class loader. If one has not been set return the class loader which loaded this class.- Returns:
- A classLoader.
-
provideConfigurationSession
Description copied from interface:ConfigurationOwnerProvide aConfigurationSession.- Specified by:
provideConfigurationSessionin interfaceConfigurationOwner- Returns:
- A
ConfigurationSession. May be null if no session is available.
-
addOwnerStateListener
Description copied from interface:ConfigurationOwnerAdd a listener.- Specified by:
addOwnerStateListenerin interfaceConfigurationOwner- Parameters:
listener-
-
removeOwnerStateListener
Description copied from interface:ConfigurationOwnerRemove a listener.- Specified by:
removeOwnerStateListenerin interfaceConfigurationOwner- Parameters:
listener-
-
rootDesignFactory
Description copied from interface:ConfigurationOwnerGet the design factory for the configuration. If this is null the Oddjob Explorer won't show a DesignInside action.Note that this is a
SerializableDesignFactoryso that this interface can be represented remotely.- Specified by:
rootDesignFactoryin interfaceConfigurationOwner- Returns:
- A DesignFactory. Must not be null if a
ConfigurationSessionis available.
-
rootElement
Description copied from interface:ConfigurationOwnerGet the root element.- Specified by:
rootElementin interfaceConfigurationOwner- Returns:
- The root element of the configuration. Must not be null if
a
ConfigurationSessionis available.
-
getInitialStateOp
Description copied from class:StructuralJobSubclasses must provide theStateOperatorthat will decide how to evaluate the children's state.- Specified by:
getInitialStateOpin classStructuralJob<Object>- Returns:
- A State Operator. Must not be null.
-
isLoadable
public boolean isLoadable()Description copied from interface:LoadableIs the component currently loadable.- Specified by:
isLoadablein interfaceLoadable- Returns:
- true if the component can be loaded, false otherwise.
- Reference Property:
- loadable
- Required:
- Read only.
Description
Can Oddjob be loaded. Used by the Load/Unload actions. -
load
public void load()Description copied from interface:LoadableLoad the component. -
execute
Description copied from class:StructuralJobExecute this job.- Specified by:
executein classStructuralJob<Object>- Throws:
Exception- If the unexpected occurs.
-
unload
public void unload()Description copied from interface:LoadableUnload the component. -
onDestroy
protected void onDestroy()Description copied from class:BaseComponentSubclasses override this method to clear up resources. This is called by the framework before child elements have been destroyed.- Overrides:
onDestroyin classStructuralJob<Object>
-
softReset
public boolean softReset()Description copied from class:StructuralJobPerform a soft reset on the job.- Specified by:
softResetin interfaceResettable- Overrides:
softResetin classStructuralJob<Object>- Returns:
- true if successful.
-
hardReset
public boolean hardReset()Perform a hard reset. The super method is overridden so as not to reset the child but destroy them.- Specified by:
hardResetin interfaceResettable- Overrides:
hardResetin classStructuralJob<Object>- Returns:
- true if successful.
-
getPersister
- Returns:
- Returns the persister.
-
setPersister
- Parameters:
persister- The persister to set.
-
provideBeanDirectory
Description copied from interface:BeanDirectoryOwnerGet theBeanDirectory. This method may return null if the BeanDirectory isn't available.- Specified by:
provideBeanDirectoryin interfaceBeanDirectoryOwner- Returns:
- The
BeanDirectoryor null.
-
describe
Description copied from interface:DescriberDescribe a bean. -
getLastReset
public org.oddjob.Oddjob.Reset getLastReset()Getter for last reset.- Returns:
-
getArgs
- Returns:
- Returns the args.
-
setArgs
- Parameters:
args- The args to set.
-
getExport
Getter- Parameters:
key- The key.- Returns:
- A value.
-
setExport
Setter.- Parameters:
key-value-
-
getProperties
Getter.- Returns:
- Properties, if set, or null.
-
setProperties
Setter.- Parameters:
properties- Optional properties.
-
getInheritance
Getter.- Returns:
- Inheritance property.
-
setInheritance
Setter.- Parameters:
inheritance- Inheritance property.
-
getDir
- Returns:
- The directory path.
- Reference Property:
- dir
- Required:
- R/O
Description
The name of the directory the configuration file is in. -
getVersion
- Returns:
- The version.
- Reference Property:
- version
Description
This Oddjob's version. -
getDescriptorFactory
Getter.- Returns:
- An ArooaDescriptorFactory or null.
-
setDescriptorFactory
Setter.- Parameters:
descriptorFactory- And ArooaDescriptorFactory.
-
getOddjobExecutors
Getter forOddjobExecutorsthat have been given to this instance of Oddjob. This getter does not expose the internal executors.- Returns:
- OddjobExecutors or null.
-
setOddjobExecutors
Setter.- Parameters:
executors- OddjobExecutors
-
getOddjobServices
Getter forOddjobServices.- Returns:
-
setOddjobServices
Allow for injection ofOddjobServices- Parameters:
oddjobServices-
-
toString
Description copied from class:BasePrimaryOverride toString.- Overrides:
toStringin classBasePrimary
-
getInputHandler
Getter.- Returns:
- An InputHandler.
-
setInputHandler
Setter.- Parameters:
inputHandler- An InputHandler.
-