Difference between revisions of "Examples: Advanced"
From OpenKM Documentation
(→Process definition) |
|||
Line 28: | Line 28: | ||
<end-state name="end"></end-state> | <end-state name="end"></end-state> | ||
</process-definition> | </process-definition> | ||
+ | </source> | ||
+ | |||
+ | == Process handlers == | ||
+ | <source lang="java"> | ||
+ | package com.openkm; | ||
+ | |||
+ | import org.jbpm.graph.exe.ExecutionContext; | ||
+ | import org.jbpm.graph.node.DecisionHandler; | ||
+ | |||
+ | public class VerifyNumber implements DecisionHandler { | ||
+ | private static final long serialVersionUID = 1L; | ||
+ | |||
+ | @Override | ||
+ | public String decide(ExecutionContext executionContext) throws Exception { | ||
+ | String numberStr = (String) executionContext.getContextInstance().getVariable("number"); | ||
+ | String guessStr = (String) executionContext.getContextInstance().getVariable("guess"); | ||
+ | Integer number; | ||
+ | |||
+ | if (numberStr != null) number = Integer.valueOf(numberStr); else number = 10; | ||
+ | Integer guess = Integer.valueOf(guessStr); | ||
+ | |||
+ | if (guess > number) { | ||
+ | System.out.println("Too high!"); | ||
+ | return "no"; | ||
+ | } else if (guess < number) { | ||
+ | System.out.println("Too low!"); | ||
+ | return "no"; | ||
+ | } else { | ||
+ | System.out.println("Great!"); | ||
+ | return "yes"; | ||
+ | } | ||
+ | } | ||
+ | } | ||
</source> | </source> | ||
Revision as of 10:36, 26 January 2010
Process image
Process definition
<?xml version="1.0" encoding="UTF-8"?>
<process-definition xmlns="urn:jbpm.org:jpdl-3.2" name="advanced">
<start-state name="start">
<transition to="task-node"></transition>
</start-state>
<task-node name="task-node">
<task name="guess_a_number">
<assignment actor-id="monkiki"></assignment>
<event type="task-create">
<script>taskInstance.start();</script>
</event>
</task>
<transition to="decision"></transition>
</task-node>
<decision name="decision">
<handler class="com.openkm.VerifyNumber"></handler>
<transition to="task-node" name="no"></transition>
<transition to="end" name="yes"></transition>
</decision>
<end-state name="end"></end-state>
</process-definition>
Process handlers
package com.openkm;
import org.jbpm.graph.exe.ExecutionContext;
import org.jbpm.graph.node.DecisionHandler;
public class VerifyNumber implements DecisionHandler {
private static final long serialVersionUID = 1L;
@Override
public String decide(ExecutionContext executionContext) throws Exception {
String numberStr = (String) executionContext.getContextInstance().getVariable("number");
String guessStr = (String) executionContext.getContextInstance().getVariable("guess");
Integer number;
if (numberStr != null) number = Integer.valueOf(numberStr); else number = 10;
Integer guess = Integer.valueOf(guessStr);
if (guess > number) {
System.out.println("Too high!");
return "no";
} else if (guess < number) {
System.out.println("Too low!");
return "no";
} else {
System.out.println("Great!");
return "yes";
}
}
}
Form definition
<?xml version="1.0" encoding="UTF-8"?>
<forms xmlns="http://www.openkm.com/xsd/forms-1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.openkm.com/xsd forms-1.0.xsd">
<form task="run_config">
<input label="Number to guess" name="number" />
<button label="Submit" />
</form>
<form task="guess_a_number">
<input label="Guess" name="guess" />
<button label="Submit" />
</form>
</forms>