[Home] [Index] [Previous] [Next]

The Descriptor

Overview

Oddjob looks for a descriptor file on the classpath. A descriptor file isn't necessary but if it finds one it will use it to when configuring jobs. The descriptor file name is META-INF/arooa.xml.

Example

Here's a descriptor that allows the job we saw in the previous section to be created without any dependency on Oddjob:

<arooa:descriptor xmlns:arooa="http://rgordon.co.uk/oddjob/arooa">
    <components>
        <arooa:bean-def element="my-job" className="org.oddjob.devguide.NoAnnotationsInJob">
            <properties>
                <arooa:property name="file" type="ATTRIBUTE"/>
                <arooa:property name="child" type="COMPONENT"/>
            </properties>
            <annotations>
                <arooa:annotation name="org.oddjob.arooa.life.Initialised" method="init"/>
                <arooa:annotation name="org.oddjob.arooa.life.Configured" method="configure"/>
                <arooa:annotation name="org.oddjob.arooa.life.Destroy" method="destroy"/>
                <arooa:annotation name="org.oddjob.framework.adapt.Run" method="go"/>
                <arooa:annotation name="org.oddjob.framework.adapt.Stop" method="halt"/>
                <arooa:annotation name="org.oddjob.framework.adapt.SoftReset" method="reset"/>
                <arooa:annotation name="org.oddjob.framework.adapt.HardReset" method="reset"/>
            </annotations>
        </arooa:bean-def>
    </components>
</arooa:descriptor>

Here's the Job without Annotations:

package org.oddjob.devguide;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class NoAnnotationsInJob {

    public File file;

    public final List<Object> children = new ArrayList<>();

    public void go() {
        System.out.println("Running");
        for (Object child : children) {
            if (child instanceof Runnable) {
                ((Runnable) child).run();
            }
        }
    }

    public void halt() {
        System.out.println("Stopping");
    }

    public void reset() {
        System.out.println("Resetting");
    }

    public void init() {
        System.out.println("Initialising we know we have children " + children );
    }

    public void configure() {
        System.out.println("Configured - we now know that file is " + file);
    }

    public void destroy() {
        System.out.println("Destroying - we still have " + file + " and " + children + " but not for long.");
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public void setChild(int index, Object child) {
        if (child == null) {
            this.children.remove(index);
        }
        else {
            this.children.add(index, child);
        }
    }

    @Override
    public String toString() {
        return "AnnotationsInJob";
    }
}

And its configuration:

<oddjob id="oddjob">
  <job>
    <my-job file="${oddjob.file}">
      <child>
        <echo>I'm a child job</echo>
      </child>
    </my-job>
  </job>
</oddjob>

[Home] [Index] [Previous] [Next]