`
zhang_xzhi_xjtu
  • 浏览: 527077 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

jbpm的教程的例子之一 HelloWorld.

阅读更多
重新改了一下jbpm的教程的第一个例子,希望对刚接触jbpm的人有帮助。

HelloWorldProcess.xml

<process-definition name='helloProcess'>

<event type="node-enter">
<script>
System.out.println("this script is entering node "+node);
</script>
</event>


<start-state >
<transition to='start' />
</start-state>

<state name='start'>
<transition to='end' />
</state>

<end-state name='end' />

</process-definition>


TestHelloWorldProcess.java

public class TestHelloWorldProcess {

private static Log log = LogFactory.getLog(TestHelloWorldProcess.class);

/**
* pd's name.
*/
private static String pdName = "helloProcess";
/**
* pd's definition xml's file path.
*/
private static String filePath = "HelloWorldProcess.xml";

/**
* One JbpmConfiguration can have many JbpmContexts.
*/
private static JbpmConfiguration jbpmConfiguration = JbpmConfiguration
.getInstance();

private static JbpmContext getJbpmContext() {
JbpmContext context = jbpmConfiguration.getCurrentJbpmContext();
if (context == null)
context = jbpmConfiguration.createJbpmContext();
return context;

}

/**
* Deploy ProcessDefinition.
*/
private static long deployProcessDefinition() {

JbpmContext jbpmContext = getJbpmContext();
try {
// parse ProcessDefinition from .xml file.
ProcessDefinition processDefinition = ProcessDefinition
.parseXmlResource(filePath);
// deploy ProcessDefinition to db.
jbpmContext.deployProcessDefinition(processDefinition);

return processDefinition.getId();

} finally {
jbpmContext.close();
}
}

/**
* Create new ProcessInstance.
*/
private static long createProcessInstance() {
JbpmContext jbpmContext = getJbpmContext();

try {
GraphSession gSession = jbpmContext.getGraphSession();
ProcessDefinition pd = gSession.findLatestProcessDefinition(pdName);
ProcessInstance processInstance = new ProcessInstance(pd);
jbpmContext.save(processInstance);
return processInstance.getId();

} finally {
jbpmContext.close();
}
}

private static void triggerProcess1(long piId) {

JbpmContext jbpmContext = getJbpmContext();
try {

ProcessInstance processInstance = jbpmContext
.getProcessInstance(piId);

// After construction, the process execution has one main path
// of execution (=the root token).
Token token = processInstance.getRootToken();

// Let's start the process execution, leaving the start-state
// over its default transition.
// The signal method will block until the process execution
// enters a wait state.
token.signal();

jbpmContext.save(token);
jbpmContext.save(processInstance);

} finally {
jbpmContext.close();
}
}

private static void triggerProcess2(long piId) {

JbpmContext jbpmContext = getJbpmContext();
try {
ProcessInstance processInstance = jbpmContext
.getProcessInstance(piId);

Token token = processInstance.getRootToken();

token.signal();
jbpmContext.save(token);
jbpmContext.save(processInstance);
} finally {
jbpmContext.close();
}
}

private static void deleteProcessDefinition(long pdId) {
JbpmContext jbpmContext = getJbpmContext();
try {
GraphSession gSession = jbpmContext.getGraphSession();
gSession.deleteProcessDefinition(pdId);
} finally {
jbpmContext.close();
}
}

public static void main(String[] args) {
DOMConfigurator.configure("config\\LogConfig.xml");
long pdId = deployProcessDefinition();
long piId = createProcessInstance();
triggerProcess1(piId);
triggerProcess2(piId);
deleteProcessDefinition(pdId);
}
}
分享到:
评论
2 楼 zhang_xzhi_xjtu 2009-09-28  
elvishehai 写道
有没有源码.

有,但是没有办法上传。也没有办法发mail。
1 楼 elvishehai 2009-09-28  
有没有源码.

相关推荐

Global site tag (gtag.js) - Google Analytics