01.08.2012 Views

Using Osworkflow in your Application

Using Osworkflow in your Application

Using Osworkflow in your Application

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Us<strong>in</strong>g</strong> OSWorkfl ow <strong>in</strong> <strong>your</strong> <strong>Application</strong><br />

The Object Registry—BeanFactory<br />

S pr<strong>in</strong>g uses the concept of a BeanFactory. This BeanFactory is an application-wide<br />

registry and manages components. It is responsible for <strong>in</strong>stantiat<strong>in</strong>g and <strong>in</strong>ject<strong>in</strong>g<br />

objects and their dependencies.<br />

OSWorkfl ow can be <strong>in</strong>tegrated with the Spr<strong>in</strong>g conta<strong>in</strong>er as a bean <strong>in</strong> the<br />

BeanFactory. In this way you can declaratively manage OSWorkfl ow dependencies.<br />

In addition to this native <strong>in</strong>tegration, OSWorkfl ow can utilize Spr<strong>in</strong>g-managed beans<br />

for Functions, Conditions, and other components.<br />

The current Spr<strong>in</strong>g version supported by OSWorkfl ow is 2.0. To download the<br />

Spr<strong>in</strong>g Framework, go to www.spr<strong>in</strong>gframework.org. To <strong>in</strong>clude Spr<strong>in</strong>g <strong>in</strong> <strong>your</strong><br />

application, just put the spr<strong>in</strong>g.jar fi le <strong>in</strong> the classpath. For each module you<br />

use, several different third-party libraries are required; <strong>in</strong> this example, only the<br />

hibernate3.jar fi le is needed.<br />

The Spr<strong>in</strong>g BeanFactory's beans are usually defi ned <strong>in</strong> an XML fi le called<br />

BeanFactory.xml. This fi le must reside <strong>in</strong> the classpath and conta<strong>in</strong>s each bean and<br />

its dependencies declarations. A sample BeanFactory.xml fi le is as follows:<br />

<br />

<br />

<br />

<br />

<br />

1000<br />

<br />

<br />

<br />

The beans tag is the root element of the XML; all bean tags must be nested <strong>in</strong>side it.<br />

The bean tag declares a new bean <strong>in</strong>side the BeanFactory. The id attribute serves as a<br />

unique identifi er <strong>in</strong>side the BeanFactory and the class attribute marks the Java class<br />

to be <strong>in</strong>stantiated by refl ection.<br />

The property tag tells Spr<strong>in</strong>g to set a value to the JavaBean name attribute, <strong>in</strong> this<br />

case salary. The value element nested <strong>in</strong>side the property tag defi nes the value<br />

to be set, <strong>in</strong> this case 1000. This value can be converted automatically by Spr<strong>in</strong>g,<br />

depend<strong>in</strong>g on the type of the target JavaBean property.<br />

Note that the Spr<strong>in</strong>g convention is to create only once <strong>in</strong>stance per<br />

component—a s<strong>in</strong>gleton model. To override this behavior, you must set<br />

the bean element's s<strong>in</strong>gleton attribute to false.<br />

[ 86 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!