예제 #1
0
 public void testProcessFactory() {
   RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.process");
   factory
       // header
       .name("My process")
       .packageName("org.jbpm")
       // nodes
       .startNode(1)
       .name("Start")
       .done()
       .actionNode(2)
       .name("Action")
       .action("java", "System.out.println(\"Action\");")
       .done()
       .endNode(3)
       .name("End")
       .done()
       // connections
       .connection(1, 2)
       .connection(2, 3);
   RuleFlowProcess process = factory.validate().getProcess();
   KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
   kbuilder.add(
       ResourceFactory.newByteArrayResource(
           XmlBPMNProcessDumper.INSTANCE.dump(process).getBytes()),
       ResourceType.BPMN2);
   KnowledgeBase kbase = kbuilder.newKnowledgeBase();
   StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
   ksession.startProcess("org.jbpm.process");
 }
 public void convertToBpmn2(InputStream ruleFlowInputStream, OutputStream bpmn2OutputStream)
     throws SAXException, IOException {
   KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
   ((PackageBuilderConfiguration) conf).initSemanticModules();
   ((PackageBuilderConfiguration) conf).addSemanticModule(new ProcessSemanticModule());
   SemanticModules semanticModules = ((PackageBuilderConfiguration) conf).getSemanticModules();
   XmlProcessReader processReader =
       new XmlProcessReader(semanticModules, Thread.currentThread().getContextClassLoader());
   RuleFlowProcess p = (RuleFlowProcess) processReader.read(ruleFlowInputStream).get(0);
   bpmn2OutputStream.write(XmlBPMNProcessDumper.INSTANCE.dump(p).getBytes());
 }