View Full Version : SWF instead of commons chain?
dmurat
May 15th, 2005, 04:51 AM
I'm very new to SWF, one night actually :), so forgive me if my question is already answered somewhere in docs. What I'm interested in is replacing apache common chain constructs with SWF. As I can see there is no real obstacle to apply SWF in non web environment, i.e. for supporting business logic implementation as a simple implementation of workflow engine.
Did anybody try something like this? If it is, can you supply some info about it?
Tnx
dmurat
May 18th, 2005, 06:33 PM
I don't know if it is only me, but I really see great potential for applying SWF on business logic field… Let me explain this a little. Recently I have done some work with commons chain. Isolation of business logic in small independent and focused parts call for creation of some kind business logic library which can be later combined easily (and declaratively) via chains. That seemed as a great idea at first but than I bumped at some obstacles down the road. I.e. very often there is a need for translation of parameters between commands (since they supposed to be totally in dependable of each other) and some branching mechanism (simple if) is also missing. I understand that commons chain is implementation of "Chain of responsibility" pattern, but still I will like those features.
One can also argue that I can simply use one of popular full featured open source business workflow engines such as OSWorkflow or JBoss jBPM. But they are almost always focused on complicated workflows with discontinuations and they always require some database. I don't really need this. I just want some simple workflow which can support one-pass execution of business logic commands with some nice add on features like branching and attribute mapping. Nothing more (and nothing less).
Then SWF comes along. It contains all mentioned features missing from commons chain, but it is focused primarily on web flow (al least that impression can be gained from available documentation). Nevertheless I was still done some investigation to see if SWF can be used as a simple workflow engine (maybe "micro workflow" term will be more appropriate) and fortunately it can :) Here is how:
Workflow and action definition:
<webflow id="sampleflow" start-state="sampleState">
<action-state id="sampleState">
<action bean="sampleActions"/>
<transition on="success" to="successState"/>
</action-state>
<end-state id="successState" view="dummy"/>
</webflow>
public class SampleAction implements Action {
public Event execute(final RequestContext p_context) {
System.out.println(p_context.getSourceEvent().getA ttribute("param1"));
p_context.getFlowScope().setAttribute("myparam", "myparam - flow output");
return new Event(this, "success");
}
}
Tester and applicationConfig definition:
public class Tester {
public static void main(final String[] p_args) {
ApplicationContext context = new ClassPathXmlApplicationContext("swfexperiments/applicationConfig.xml");
Flow flow = (Flow)context.getBean("sampleFlow");
FlowExecution flowExecution = new FlowExecutionImpl(flow);
Map eventParams = new HashMap();
eventParams.put("param1", "param1 - flow input");
Event startEvent = new Event(new Object(), "startEvent", eventParams);
Map model = flowExecution.start(startEvent).getModel();
System.out.println(model.get("myparam"));
}
}
<beans>
<bean id="sampleFlow" class="org.springframework.web.flow.config.XmlFlowFactory Bean">
<property name="location" value="classpath:swfexperiments/sampleFlow.xml"/>
</bean>
<bean id="sampleActions" class="swfexperiments.SampleAction" />
</beans>
And that’s it. Thank you SWF guys :)
klr8
May 23rd, 2005, 03:49 PM
As you already mention, SWF was not designed to be a general purpose workflow engine. However, it's flexibility will take you a long way for simple requirements. The new PR3 release also helps in making it easy to plug in custom State types and custom Transition classes.
Erwin
aerobot
Mar 23rd, 2006, 05:38 AM
SWF is more for managing the flow of web pages. Where commons chain is geared more toward business logic. For example, one step in a web flow might be to gather information about a user. The business logic to validate the user data gathered could be in a commons chain. (Depending on how complex a user validation is, you might not need a chain.)
I also wondered if you might find the information on replacement of the commons chain catalog with springframe useful. See my Technical Article / whitepaper HOW TO - merge Spring Framework and COMMONS Chain ( "Chain of Responsibility" ) (http://www.drummondsoftware.com/WhitePapers/SpringChain/SpringChain.htm)
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.