Oddjob's extension points.
In this section we take a look at
the many options for making our classes available to Oddjob. We'll
learn how to tell Oddjob to use nice short element names like
<copy>
and we'll learn how to write an Oddball which is an Oddjob plugin.
In the first instance Oddjob finds its classes...
-classpath option..jar in the lib directory..jar in the opt/lib directory.opt/classes directory.We can prove this by copying an example class:
$ mkdir opt/classes/org $ mkdir opt/classes/org/oddjob $ mkdir opt/classes/org/oddjob/devguide $ cp examples/classes/org/oddjob/devguide/HelloWorldJob.class opt/classes/org/oddjob/devguide $ java -jar run-oddjob.jar -f examples/devguide/hello1.xml Hello World!
How can we use our own XML elements instead of boring old
<bean> elements?
Provide an implementation of an
ArooaDescriptorFactory.
When Oddjob starts it has one of these factory things that scans the classpath
for any number of META-INF/arooa.xml XML files which it
expects to be able to parse to create another factory. It joins all these little
factories together and creates a big factory (For those that like design patterns
this is of course the classic Composite Pattern).
There's an example of one of these XML files in the examples directory called
helloperson-arooa.xml. It's for our HelloPersonJob example from the
previous section and it looks like this.
<arooa:descriptor xmlns:arooa="http://rgordon.co.uk/oddjob/arooa">
<components>
<arooa:bean-def element="hello" className="org.oddjob.devguide.HelloPersonJob"/>
</components>
<values>
<arooa:bean-def element="person" className="org.oddjob.devguide.Person"/>
</values>
</arooa:descriptor>
Now as Arooa is a Java Bean Framework, it probably comes as no surprise to
learn that this is Java Bean implementation of
an ArooaDescriptorFactory and it's parsed with... Arooa of course. See
<arooa:descriptor>
in the reference for more on how to configure this bean.
If we copy the descriptor:
$ cp examples/devguide/helloperson-arooa.xml examples/classes/META-INF/arooa.xml
We can modify our original configuration to become:
<oddjob>
<job>
<hello formal="true">
<person>
<person title="Mr" firstname="John" surname="Smith"/>
</person>
</hello>
</job>
</oddjob>
And run it:
$ java -jar run-oddjob.jar -cp examples/classes -f examples/devguide/helloperson2.xml Hello Mr Smith.
Once a component has been given an element to class mapping, Oddjob Designer will automatically create a form for it:
And for person too:
Ok, not pretty - but it can make a pleasant change from XML.
A nested Oddjob job within Oddjob can also be configured with it's own class loader and descriptor factory.
<oddjob id="this">
<job>
<oddjob file="${this.dir}/helloperson2.xml">
<descriptorFactory>
<import file="${this.dir}/helloperson-arooa.xml"/>
</descriptorFactory>
<classLoader>
<url-class-loader>
<files>
<file file="${this.dir}/../classes"/>
</files>
</url-class-loader>
</classLoader>
</oddjob>
</job>
</oddjob>
This does the same as the above. No classpath required.
$ java -jar run-oddjob.jar -f examples/devguide/helloperson-main.xml Hello Mr Smith.
The difference is that a new class loader is created and used to
load the HelloPersonJob class.
Oddballs are Oddjob's plugin architecture.
Oddballs extends the above features of Oddjob modularity by defining a recognised directory structure for deploying a set of job classes and their dependent libraries.
An Oddball is any directory in Oddjob's oddballs directory.
Oddballs find their classes...
.jar in the lib directory.classes directory.(Familiar to those who know Servlets. But there's no
web.xml, instead...)
When the Oddball loads it scans this classpath
for any number of META-INF/arooa.xml XML file from which it
creates it's ArooaDescriptorFactory.
Oddjob comes pre-installed with some Oddballs for Ant tasks, mail,
FTP, an HSQL database server,
and an optional Oddball, oj-spring
which is in the /opt/oddballs directory. To install an
Oddball simply move this to Oddjob's oddballs directory.
$ mv opt/oddballs/oj-spring oddballs
To un-install it, simply move it out of the oddballs
directory.