Package org.oddjob.values.properties
Class PropertiesJob
- All Implemented Interfaces:
Serializable,Runnable,ArooaContextAware,ArooaSessionAware,Describable,Forceable,PropertyChangeNotifier,Iconic,LogEnabled,Resettable,Stateful
- See Also:
- As Property name/value Pairs in the values property of this job.
- By defining the environment attribute to be the prefix to which all environment variables will be appended as properties.
- By using the sets property to provide a number of addition property sets which are likely to be a reference to properties defined elsewhere.
- By defining the Input property to be a File/Resource or some other type of input.
Description
Creates properties that can used to configure other jobs.There are four ways to set properties:
If the substitute property is true, property values 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>
Defining a property using substitution. This is the same example as
previously but it is the properties job doing the substitution not
the Oddjob framework. The value of snack.favourite is escaped because we
want ${fruit.favourite} passed into the properties job. If the property
was defined in a file it would not need to be escaped like this.
<oddjob>
<job>
<sequential>
<jobs>
<properties substitute="true">
<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>
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>
The properties file contains:
# properties for test someones.name = John Smith someones.name.title = Mr. someones.address = LondonThis will display
John SmithOverriding 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
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>
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds the property lookup to the session.describe()Provides the properties.protected voidprotected intexecute()Execute this job.protected ArooaSessionAllow sub classes access the the session.Getter for environment prefix.Getter for extract.protected PropertyLookupSubclasses can override the lookup.Getter for prefix.getSets(int index) Indexed getter for sets.booleanGetter for fromXML.booleanAre the properties override properties.booleanGetter for substitute.booleanisSystem()Getter for system flag.protected voidonReset()Allow sub classes to do something on reset.voidsetArooaContext(ArooaContext context) voidsetEnvironment(String environment) voidsetExtract(String extract) voidsetFromXML(boolean fromXML) voidsetInput(InputStream input) voidsetOverride(boolean override) voidvoidsetSets(int index, Properties props) voidsetSubstitute(boolean substitute) voidsetSystem(boolean system) voidMethods inherited from class org.oddjob.values.properties.PropertiesJobBase
addPropertyLookup, getProperties, onDestroy, onInitialised, setPropertiesMethods inherited from class org.oddjob.framework.extend.SimpleJob
fireDestroyedState, force, getStateChanger, hardReset, iconHelper, isStop, onStop, run, sleep, softReset, stateHandler, stopMethods inherited from class org.oddjob.framework.extend.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toStringMethods inherited from class org.oddjob.framework.extend.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, iconForId, initialise, lastStateEvent, onConfigured, removeIconListener, removePropertyChangeListener, removeStateListener, save, 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
-
Constructor Details
-
PropertiesJob
public PropertiesJob()Default Constructor.
-
-
Method Details
-
doWhenDeserialized
protected void doWhenDeserialized()- Overrides:
doWhenDeserializedin classPropertiesJobBase
-
setArooaContext
- Specified by:
setArooaContextin interfaceArooaContextAware- Overrides:
setArooaContextin classBaseComponent
-
getArooaSession
Description copied from class:BaseComponentAllow sub classes access the the session.- Overrides:
getArooaSessionin classBaseComponent- Returns:
- A session. Will never be null once a component is initialised within Oddjob. May be null if otherwise if the session hasn't been set.
-
createPropertyLookup
protected void createPropertyLookup()Adds the property lookup to the session.- Overrides:
createPropertyLookupin classPropertiesJobBase
-
getLookup
Description copied from class:PropertiesJobBaseSubclasses can override the lookup.- Overrides:
getLookupin classPropertiesJobBase- Returns:
-
execute
Description copied from class:SimpleJobExecute this job.- Specified by:
executein classSimpleJob- Returns:
- 0 if the job is complete, anything else otherwise.
- Throws:
IOExceptionArooaConversionException
-
describe
Description copied from interface:DescribableProvides the properties.- Specified by:
describein interfaceDescribable- Returns:
- A map of property values. Must not be null.
-
onReset
protected void onReset()Description copied from class:SimpleJobAllow sub classes to do something on reset.- Overrides:
onResetin classPropertiesJobBase
-
getEnvironment
Getter for environment prefix.- Returns:
- The environment prefix. May be null.
-
setEnvironment
- Reference Property:
- environment
- Required:
- No.
Description
The prefix for environment variables. -
isSystem
public boolean isSystem()Getter for system flag.- Returns:
- The system flag.
-
setSystem
public void setSystem(boolean system) - Reference Property:
- system
- Required:
- No. Defaults to false
Description
Set to true to set System properties rather than Oddjob properties. -
setInput
- Reference Property:
- input
- Required:
- No.
Description
An input source for Properties. -
setFromXML
public void setFromXML(boolean fromXML) - Reference Property:
- fromXML
- Required:
- No, default to false.
Description
If the input for the properties is in XML format. -
isFromXML
public boolean isFromXML()Getter for fromXML.- Returns:
- true/false.
-
setValues
- Reference Property:
- values
- Required:
- No.
Description
Properties defined as key value pairs. -
setSets
- Reference Property:
- sets
- Required:
- No.
Description
Extra properties to be merged into the overall property set. -
getSets
Indexed getter for sets.- Parameters:
index- The index.- Returns:
- The properites.
-
setSubstitute
public void setSubstitute(boolean substitute) - Reference Property:
- substitute
- Required:
- No.
Description
Use substitution for the values of ${} type properties. -
isSubstitute
public boolean isSubstitute()Getter for substitute.- Returns:
- true/false.
-
getExtract
Getter for extract.- Returns:
- The extract prefix or null.
-
setExtract
- Reference Property:
- extract
- Required:
- No.
Description
Extract this prefix form property names. Filters out properties that do not begin with this prefix. -
getPrefix
Getter for prefix.- Returns:
- The appending prefix or null.
-
setPrefix
- Reference Property:
- prefix
- Required:
- No.
Description
Append this prefix to property names. -
isOverride
public boolean isOverride()Description copied from class:PropertiesJobBaseAre the properties override properties.- Specified by:
isOverridein classPropertiesJobBase- Returns:
-
setOverride
public void setOverride(boolean override) - Reference Property:
- override
- Required:
- No. Default is false.
Description
Properties of this job will override any previously set.
-