01.08.2012 Views

Using Osworkflow in your Application

Using Osworkflow in your Application

Using Osworkflow in your Application

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

{<br />

}<br />

public static void ma<strong>in</strong>(Str<strong>in</strong>g[] args)<br />

{<br />

XmlBeanFactory beanFactory =new XmlBeanFactory(<br />

new ClassPathResource("osworkflow-spr<strong>in</strong>g-hibernate3.xml");<br />

Workflow workflow = (Workflow) beanFactory.getBean("workflow");<br />

try<br />

{<br />

workflow.<strong>in</strong>itialize("example", 100, null);<br />

} catch (Exception e)<br />

{<br />

e.pr<strong>in</strong>tStackTrace();<br />

}<br />

}<br />

This example <strong>in</strong>itializes the Spr<strong>in</strong>g BeanFactory, and then gets a workflow<br />

bean. Note that the code is us<strong>in</strong>g the Workflow <strong>in</strong>terface and never calls the<br />

actual BasicWorkflow implementation. This really decouples our code from the<br />

implementation details, leav<strong>in</strong>g more room for the more important th<strong>in</strong>gs such as<br />

bus<strong>in</strong>ess logic.<br />

This code is much simpler than the other versions shown before. You don't have to<br />

care about creat<strong>in</strong>g or look<strong>in</strong>g up DataSource, OSWorkflow Configuration, and<br />

SessionFactory or <strong>in</strong>stantiat<strong>in</strong>g new Workflow implementations. We also get rid of<br />

the workflows.xml fi le by unit<strong>in</strong>g all under the same XML fi le.<br />

Transaction Support <strong>in</strong> Spr<strong>in</strong>g<br />

Before we use Spr<strong>in</strong>g and OSWorkfl ow <strong>in</strong> production, we must defi ne some<br />

important th<strong>in</strong>gs such as transactions.<br />

Spr<strong>in</strong>g's transaction manager can use different strategies, such as JTA global<br />

transactions, JDBC local transactions, or no transactions at all.<br />

JTA is a standard J2EE API capable of creat<strong>in</strong>g and synchroniz<strong>in</strong>g<br />

transactions across different systems. Most of the popular J2EE<br />

application servers, such as JBoss, <strong>in</strong>clude a JTA subsystem.<br />

The Spr<strong>in</strong>g conta<strong>in</strong>er can also make use of AOP. AOP is a new programm<strong>in</strong>g<br />

technique, which simplifi es the programm<strong>in</strong>g of applications by factor<strong>in</strong>g out cross<br />

concerns such as logg<strong>in</strong>g code, transaction handl<strong>in</strong>g code, etc.<br />

[ 90 ]

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

Saved successfully!

Ooh no, something went wrong!