Running Oddjob from Code.
It's Hello World of course:
String xml = "<oddjob>" + " <job>" + " <echo id='hello-job'>Hello World</echo>" + " </job>" + "</oddjob>"; Oddjob oddjob = new Oddjob(); oddjob.setConfiguration(new XMLConfiguration("EMBEDDED XML", xml)); oddjob.run();
And that's it.
With three lines of code it's possible to get at all Objects that have been registered within Oddjob with their id attribute. Because three lines of code seemed a bit much a utility class OddjobLookup was created.
We can now get there in one line thus:
String greeting = new OddjobLookup(oddjob).lookup("hello-job.text", String.class);
By providing the property type, Oddjob will do the conversion for us. There is also a lookup method that doesn't take the second argument and returns the raw Object
And when you've finished with Oddjob we mustn't forget to clear those resources:
If you don't do this, it's possible that threads will be left running.