org.oddjob
Class Oddjob

java.lang.Object
  extended byorg.oddjob.framework.BaseComponent
      extended byorg.oddjob.framework.BasePrimary
          extended byorg.oddjob.framework.StructuralJob
              extended byorg.oddjob.Oddjob
All Implemented Interfaces:
Iconic, Resetable, java.lang.Runnable, Stateful, Stoppable, Structural

public class Oddjob
extends StructuralJob
implements Structural, Stoppable

Read a configuration, creates child jobs and executes them.

Description:
The starting point for a hierarchy of jobs. The Oddjob job creates and runs a job hierarchy by processing a supplied configuration file.

An Oddjob job allows an Oddjob instance to be created within an existing Oddjob configuration. This way complicated processes can be created in managable and separately testable units.

An Oddjob job can be visualised as having two sides. One side is in the configuration that creates the Oddjob. The other side is in the configuration that the Oddjob job creates and runs. An Oddjob can have two different ids - that which identifies it in the outer and that which identifies it in the inner configuration files. An Oddjob job should only have it's properties set in the outer configuration file. To enforce this the top level <oddjob> element only supports the id attribute.

The args property allows arguments to be passed into a nested Oddjob from the the outer oddjob or from the command line.

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.

Oddjob has serveral properties to support registering bespoke jobs types, and property proxies. An example would be

 ...
   <oddjob name="Nested Oddjob"
             file="nested.xml">
     <componentType>
       <value name="myjob" value="com.mycomp.ProcessingJob"/>
     </componentType>
   </oddjob>
 ...
 
The file nested.xml can then contain something like.
 <oddjob>
   <myjob/>
 </oddjob>
 
The classpath that the nested Oddjob will use can also be configured.
Example:
A simple nested Oddjob with one argument.
 <oddjob id="this">
   <oddjob file="${this.dir}/nested.xml">
     <args>
       <value value="apples"/>
     </args>
   </oddjob> 
 <l;/oddjob>
 
Oddjob with database persistance.
 <oddjob file="${this.dir}\job.oddjob.persist.xml"
         name="A Database Persisted Oddjob">
   <persister>
     <sqlPersister>
       <connection driver="org.hsqldb.jdbcDriver"
             url="jdbc:hsqldb:hsql://localhost:11002/ojdb" username="sa"/>
     </sqlPersister>
   </persister>
 </oddjob>
 
Author:
Rob Gordon

Nested Class Summary
 class Oddjob.OddjobHandler
          Need our own handler to get the id element.
 class Oddjob.Root
          The object which is the Oddjob root.
 
Field Summary
static ConsoleArchive CONSOLE
           
static java.lang.String CONVERTER_PROPERTIES
           
static java.lang.String JOB_PROPERTIES
           
static java.lang.String PROXY_PROPERTIES
           
static java.lang.String TYPE_PROPERTIES
           
 
Fields inherited from class org.oddjob.framework.StructuralJob
childHelper
 
Fields inherited from class org.oddjob.framework.BasePrimary
stop
 
Fields inherited from class org.oddjob.framework.BaseComponent
changes, destroyed, iconHelper, location, lock, stateHandler
 
Constructor Summary
Oddjob()
           
 
Method Summary
protected  void execute()
          Execute this job.
 java.lang.Object[] getArgs()
           
 java.lang.Object getArgs(int index)
          Get the args by index.
 java.lang.ClassLoader getClassLoader()
          Return a class loader.
 void getClasspath(java.io.File[] files)
          Get the classpath files.
 java.io.File getDir()
           
 java.io.File getFile()
           
 ComponentPersister getPersister()
           
 java.lang.String getSubstitution()
           
 java.lang.String getVersion()
          Get this Oddjob version.
 void hardReset()
          Perform a hard reset.
 boolean isLoadOnly()
           
protected  void load()
          Load Oddjob from the configuration file.
 ArooaContext loadContext()
          A getter for Load context without a getter as this isn't a published property.
 java.lang.Object lookup(java.lang.String path)
          Lookup a component in the registry.
 void onDestroy()
          Destroy this component.
 void setArgs(int index, java.lang.Object arg)
          Set an arg by index.
 void setArgs(java.lang.Object[] args)
           
 void setClassLoader(java.lang.ClassLoader classLoader)
          Set a class loader.
 void setClasspath(java.io.File[] files)
          Set the classpath files.
 void setComponentType(java.lang.String name, java.lang.String className)
           
 void setConfig(java.io.File file)
           
 boolean setContext(ArooaContext context)
          Called during construction by the framework to allow a component access to the context that's creating it.
 void setFile(java.io.File file)
          Set the configuration file.
 void setInput(java.io.InputStream inputStream)
          Set the input stream to read configuration from.
 void setLoadOnly(boolean loadOnly)
          Set load only property.
 void setPersister(ComponentPersister persister)
           
 void setPropertyProxy(java.lang.String name, java.lang.String className)
           
 void setSubstitution(java.lang.String substitution)
           
 void setValueType(java.lang.String name, java.lang.String className)
           
 void softReset()
          Perform a soft reset.
 
Methods inherited from class org.oddjob.framework.StructuralJob
addStructuralListener, independant, removeStructuralListener, run, stop
 
Methods inherited from class org.oddjob.framework.BasePrimary
configurationComplete, getLogger, getName, logger, setJobStateReady, setLogger, setName, sleep, toString
 
Methods inherited from class org.oddjob.framework.BaseComponent
addIconListener, addJobStateListener, addPropertyChangeListener, arooaRuntime, arooaRuntime, canHardReset, canSoftReset, configure, destroy, getLocation, iconForId, lastJobStateEvent, removeIconListener, removeJobStateListener, removePropertyChangeListener, setJobStateComplete, setJobStateException, setJobStateNotComplete
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.oddjob.Structural
addStructuralListener, removeStructuralListener
 
Methods inherited from interface org.oddjob.Stoppable
stop
 
Methods inherited from interface org.oddjob.Stateful
addJobStateListener, removeJobStateListener
 

Field Detail

JOB_PROPERTIES

public static final java.lang.String JOB_PROPERTIES
See Also:
Constant Field Values

CONVERTER_PROPERTIES

public static final java.lang.String CONVERTER_PROPERTIES
See Also:
Constant Field Values

PROXY_PROPERTIES

public static final java.lang.String PROXY_PROPERTIES
See Also:
Constant Field Values

TYPE_PROPERTIES

public static final java.lang.String TYPE_PROPERTIES
See Also:
Constant Field Values

CONSOLE

public static final ConsoleArchive CONSOLE
Constructor Detail

Oddjob

public Oddjob()
Method Detail

setFile

public void setFile(java.io.File file)
Set the configuration file.

Parameters:
file - The config file.

getFile

public java.io.File getFile()
Oddjob Property:
file
Description:
The name of the configuration file. to configure this oddjob.
Required:
R/O
Returns:
The file name.

getDir

public java.io.File getDir()
Oddjob Property:
dir
Description:
The name of the directory the configuration file is in.
Required:
R/O
Returns:
The directory path.

setConfig

public void setConfig(java.io.File file)

setInput

public void setInput(java.io.InputStream inputStream)
Set the input stream to read configuration from.

Parameters:
inputStream - The input stream.

setClassLoader

public void setClassLoader(java.lang.ClassLoader classLoader)
Set a class loader.

Parameters:
classLoader - The classLoader;

getClassLoader

public java.lang.ClassLoader getClassLoader()
Return a class loader. If one has not been set return the class loader which loaded this class.

Returns:
A classLoader.

setClasspath

public void setClasspath(java.io.File[] files)
Set the classpath files.

Parameters:
files - The files to set in the classpath.

getClasspath

public void getClasspath(java.io.File[] files)
Get the classpath files.

Returns:
The files in the classpath.

getSubstitution

public java.lang.String getSubstitution()
Returns:
Returns the substitution.

setSubstitution

public void setSubstitution(java.lang.String substitution)
Parameters:
substitution - The substitution to set.

setComponentType

public void setComponentType(java.lang.String name,
                             java.lang.String className)
Oddjob Property:
componentType
Description:
A mapped property for specifying additional component types.
Required:
No.

setValueType

public void setValueType(java.lang.String name,
                         java.lang.String className)
Oddjob Property:
valueType
Description:
A mapped property for specifying additional value types.
Required:
No.

setPropertyProxy

public void setPropertyProxy(java.lang.String name,
                             java.lang.String className)
Oddjob Property:
propertyProxy
Description:
A mapped property for specifying additional property proxies.
Required:
No.

setContext

public boolean setContext(ArooaContext context)
Description copied from class: BasePrimary
Called during construction by the framework to allow a component access to the context that's creating it.

If this method returns true then it is an independent component responsible for it's own configuration and won't have it's configuration linked to its parents.

Subclasses overriding this method should always call super.setContext().

Overrides:
setContext in class BasePrimary
Parameters:
context - The ArooaXMLContext.
Returns:
true/false depending on subClasses implementation of independent();

load

protected void load()
Load Oddjob from the configuration file.


execute

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

Specified by:
execute in class StructuralJob

onDestroy

public void onDestroy()
Description copied from class: StructuralJob
Destroy this component.

Overrides:
onDestroy in class StructuralJob

softReset

public void softReset()
Perform a soft reset. The super method is overridden so as not to reset the child.

Specified by:
softReset in interface Resetable
Overrides:
softReset in class StructuralJob

hardReset

public void hardReset()
Perform a hard reset. The super method is overridden so as not to reset the child but destroy them.

Specified by:
hardReset in interface Resetable
Overrides:
hardReset in class StructuralJob

getPersister

public ComponentPersister getPersister()
Returns:
Returns the persistin.

setPersister

public void setPersister(ComponentPersister persister)

lookup

public java.lang.Object lookup(java.lang.String path)
Lookup a component in the registry.

Parameters:
path - The path to the component
Returns:
The component or null if it doesn't exist.

isLoadOnly

public boolean isLoadOnly()
Returns:
Returns the loadOnly.

setLoadOnly

public void setLoadOnly(boolean loadOnly)
Set load only property.

Parameters:
loadOnly - true to load only, false to load and run.

getArgs

public java.lang.Object[] getArgs()
Returns:
Returns the args.

getArgs

public java.lang.Object getArgs(int index)
Get the args by index.

Parameters:
index - The index.
Returns:
The arg.

setArgs

public void setArgs(java.lang.Object[] args)
Parameters:
args - The args to set.

setArgs

public void setArgs(int index,
                    java.lang.Object arg)
Set an arg by index.

Parameters:
index - The index
arg - The arg.

loadContext

public ArooaContext loadContext()
A getter for Load context without a getter as this isn't a published property.

Returns:
Get the context used when Oddjob loaded the configuration file.

getVersion

public java.lang.String getVersion()
Get this Oddjob version.

Returns:
The version.