org.oddjob.values.properties
Class PropertiesJob

java.lang.Object
  extended by org.oddjob.framework.BaseComponent
      extended by org.oddjob.framework.BasePrimary
          extended by org.oddjob.framework.SimpleJob
              extended by org.oddjob.framework.SerializableJob
                  extended by org.oddjob.values.properties.PropertiesJobBase
                      extended by org.oddjob.values.properties.PropertiesJob
All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, Describeable, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful

public class PropertiesJob
extends PropertiesJobBase
implements Describeable

Description

Creates properties that can used to configure other jobs.

There are four ways to set properties:

  1. As Property name/value Pairs in the values property of this job.
  2. By defining the environment attribute to be the prefix to which all environment variables will be appended as properties.
  3. By using the sets property to provide a number of addition property sets which are likely to be a reference to properties defined elsewhere.
  4. By defining the Input property to be a File/Resource or some other type of input.
Combinations are possible and the order of evaluation is as above. Oddjob will do it's usual property substitution using previously defined property values if required.

If the substitute property is defined, property values within the input file will be evaluated for substitution.

The Properties job and PropertiesType type are very similar, the difference between them is that the job defines properties for Oddjob and the type provides properties for configuring a single job (which could be the sets property of the property job).

Example

Defining and using a property. Note the escape syntax for property expansion.
<oddjob>
  <job>
   <sequential>
    <jobs>
     <properties>
      <values>
       <value key="fruit.favourite" value="apple"/>
       <value key="snack.favourite" value="${fruit.favourite}"/>
      </values>
     </properties>
     <echo id="echo">$${snack.favourite} is ${snack.favourite}</echo>
    </jobs>
   </sequential>
  </job>
 </oddjob>

Example

Loading properties from a class path resource.
<oddjob>
    <job>
        <sequential>
            <jobs>
                <properties>
                    <input>
                        <resource resource="org/oddjob/values/properties/PropertiesJobTest1.properties"/>
                    </input>
                </properties>
                <echo id="echo">${someones.name}</echo>
            </jobs>
        </sequential>
    </job>
</oddjob>

Example

Overriding Properties. Normally setting a property is first come first set. Using the override property on the properties job makes the properties defined in that job take priority.
<oddjob>
  <job>
   <sequential>
    <jobs>
     <properties>
      <values>
       <value key="fruit.favourite" value="apple"/>
      </values>
     </properties>
     <echo id="echo1">$${fruit.favourite} is ${fruit.favourite}</echo>
     <properties>
      <values>
       <value key="fruit.favourite" value="pear"/>
      </values>
     </properties>
     <echo id="echo2">$${fruit.favourite} is ${fruit.favourite}</echo>
     <properties override="true">
      <values>
       <value key="fruit.favourite" value="banana"/>
      </values>
     </properties>
     <echo id="echo3">$${fruit.favourite} is ${fruit.favourite}</echo>
    </jobs>
   </sequential>
  </job>
 </oddjob>
This will display
 ${fuit.favourite} is apple
 ${fuit.favourite} is apple
 ${fuit.favourite} is banana
 

Example

Capturing Environment Variables. Note that the case sensitivity of environment variables is Operating System dependent. On Windows ${env.Path} and ${env.path} would also yield the same result. On Unix (generally) only ${env.PATH} will work.
<oddjob>
  <job>
    <sequential>
      <jobs>
        <properties id="props" environment="env"/>
        <echo id="echo-path">Path is ${env.PATH}</echo>
      </jobs>
    </sequential>
  </job>
</oddjob>
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.oddjob.framework.SimpleJob
stateHandler, stop
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Constructor Summary
PropertiesJob()
          Default Constructor.
 
Method Summary
protected  void createPropertyLookup()
          Adds the property lookup to the session.
 Map<String,String> describe()
          Provides the properties.
protected  int execute()
          Execute this job.
protected  ArooaSession getArooaSession()
           
 String getEnvironment()
          Getter for environment prefix.
 String getExtract()
          Getter for extract.
protected  PropertyLookup getLookup()
          Subclasses can override the lookup.
 String getPrefix()
          Getter for prefix.
 Properties getSets(int index)
          Indexed getter for sets.
 boolean isFromXML()
          Getter for fromXML.
 boolean isOverride()
          Are the properties override properties.
 boolean isSubstitute()
          Getter for substitute.
protected  void onReset()
          Allow sub classes to do something on reset.
 void setArooaContext(ArooaContext context)
           
 void setEnvironment(String environment)
           
 void setExtract(String extract)
           
 void setFromXML(boolean fromXML)
           
 void setInput(InputStream input)
           
 void setOverride(boolean override)
           
 void setPrefix(String prefix)
           
 void setSets(int index, Properties props)
           
 void setSubstitute(boolean substitute)
           
 void setValues(String key, String value)
           
 
Methods inherited from class org.oddjob.values.properties.PropertiesJobBase
addPropertyLookup, getProperties, onDestroy, setProperties
 
Methods inherited from class org.oddjob.framework.SimpleJob
fireDestroyedState, force, getStateChanger, hardReset, onStop, run, sleep, softReset, 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, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
 

Constructor Detail

PropertiesJob

public PropertiesJob()
Default Constructor.

Method Detail

setArooaContext

public void setArooaContext(ArooaContext context)
Specified by:
setArooaContext in interface ArooaContextAware
Overrides:
setArooaContext in class PropertiesJobBase

getArooaSession

protected ArooaSession getArooaSession()
Overrides:
getArooaSession in class BaseComponent

createPropertyLookup

protected void createPropertyLookup()
Adds the property lookup to the session.

Overrides:
createPropertyLookup in class PropertiesJobBase

getLookup

protected PropertyLookup getLookup()
Description copied from class: PropertiesJobBase
Subclasses can override the lookup.

Overrides:
getLookup in class PropertiesJobBase
Returns:

execute

protected int execute()
               throws IOException,
                      ArooaConversionException
Description copied from class: SimpleJob
Execute this job.

Specified by:
execute in class SimpleJob
Returns:
0 if the job is complete, anything else otherwise.
Throws:
IOException
ArooaConversionException

describe

public Map<String,String> describe()
Description copied from interface: Describeable
Provides the properties.

Specified by:
describe in interface Describeable
Returns:
A map of property values. Must not be null.

onReset

protected void onReset()
Description copied from class: SimpleJob
Allow sub classes to do something on reset.

Overrides:
onReset in class PropertiesJobBase

getEnvironment

public String getEnvironment()
Getter for environment prefix.

Returns:
The environment prefix. May be null.

setEnvironment

public void setEnvironment(String environment)

Property: environment

Description: The prefix for environment variables.

Required: No.


setInput

public void setInput(InputStream input)

Property: input

Description: An input source for Properties.

Required: No.


setFromXML

public void setFromXML(boolean fromXML)

Property: fromXML

Description: If the input for the properties is in XML format.

Required: No, default to false.


isFromXML

public boolean isFromXML()
Getter for fromXML.

Returns:
true/false.

setValues

public void setValues(String key,
                      String value)

Property: values

Description: Properties defined as key value pairs.

Required: No.


setSets

public void setSets(int index,
                    Properties props)

Property: sets

Description: Extra properties to be merged into the overall property set.

Required: No.


getSets

public Properties getSets(int index)
Indexed getter for sets.

Parameters:
index - The index.
Returns:
The properites.

setSubstitute

public void setSubstitute(boolean substitute)

Property: substitute

Description: Use substitution for the values of ${} type properties.

Required: No.


isSubstitute

public boolean isSubstitute()
Getter for substitute.

Returns:
true/false.

getExtract

public String getExtract()
Getter for extract.

Returns:
The extract prefix or null.

setExtract

public void setExtract(String extract)

Property: extract

Description: Extract this prefix form property names. Filters out properties that do not begin with this prefix.

Required: No.


getPrefix

public String getPrefix()
Getter for prefix.

Returns:
The appending prefix or null.

setPrefix

public void setPrefix(String prefix)

Property: prefix

Description: Append this prefix to property names.

Required: No.


isOverride

public boolean isOverride()
Description copied from class: PropertiesJobBase
Are the properties override properties.

Specified by:
isOverride in class PropertiesJobBase
Returns:

setOverride

public void setOverride(boolean override)

Property: override

Description: Properties of this job will override any previously set.

Required: No. Default is false.