论坛首页 Java企业应用论坛

jbpm的教程的例子之一 HelloWorld.

浏览 4550 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (8) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-06-08   最后修改:2009-09-17
重新改了一下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);
}
}
   发表时间:2009-09-28  
有没有源码.
0 请登录后投票
   发表时间:2009-09-28  
elvishehai 写道
有没有源码.

有,但是没有办法上传。也没有办法发mail。
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics