Class PropertiesJob

All Implemented Interfaces:
Serializable, Runnable, ArooaContextAware, ArooaSessionAware, Describable, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resettable, Stateful

public class PropertiesJob extends PropertiesJobBase implements Describable
See Also:

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 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 = London

 
This will display
 John Smith
 
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
 
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>
  • Constructor Details

    • PropertiesJob

      public PropertiesJob()
      Default Constructor.
  • Method Details

    • doWhenDeserialized

      protected void doWhenDeserialized()
      Overrides:
      doWhenDeserialized in class PropertiesJobBase
    • setArooaContext

      public void setArooaContext(ArooaContext context)
      Specified by:
      setArooaContext in interface ArooaContextAware
      Overrides:
      setArooaContext in class BaseComponent
    • getArooaSession

      protected ArooaSession getArooaSession()
      Description copied from class: BaseComponent
      Allow sub classes access the the session.
      Overrides:
      getArooaSession in class BaseComponent
      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:
      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: Describable
      Provides the properties.
      Specified by:
      describe in interface Describable
      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)
      Reference Property:
      environment

      Description

      The prefix for environment variables.
      Required:
      No.
    • isSystem

      public boolean isSystem()
      Getter for system flag.
      Returns:
      The system flag.
    • setSystem

      public void setSystem(boolean system)
      Reference Property:
      system

      Description

      Set to true to set System properties rather than Oddjob properties.
      Required:
      No. Defaults to false
    • setInput

      public void setInput(InputStream input)
      Reference Property:
      input

      Description

      An input source for Properties.
      Required:
      No.
    • setFromXML

      public void setFromXML(boolean fromXML)
      Reference 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)
      Reference Property:
      values

      Description

      Properties defined as key value pairs.
      Required:
      No.
    • setSets

      public void setSets(int index, Properties props)
      Reference 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)
      Reference 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)
      Reference 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)
      Reference 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)
      Reference Property:
      override

      Description

      Properties of this job will override any previously set.
      Required:
      No. Default is false.