Hi Thorben and all,
This is what I'm trying to do.
I have a language that I compile to BPMN and it is very hard to have the xml generator up to date so I came across Camunda Model API and believed it would be nice to use.
After reading this link(
http://docs.camunda.org/latest/guides/user-guide/#bpmn-model-api), I tried to copy and paste the code that is there and I have some errors. BTW, I'm using version 7.1.0.
The code I am trying is bellow. Lines with the //ERROR comment are those not working.
package org.prisma.test.camunda;
import java.io.File;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.BpmnModelElementInstance;
import org.camunda.bpm.model.bpmn.instance.Definitions;
import org.camunda.bpm.model.bpmn.instance.EndEvent;
import org.camunda.bpm.model.bpmn.instance.FlowNode;
import org.camunda.bpm.model.bpmn.instance.SequenceFlow;
import org.camunda.bpm.model.bpmn.instance.StartEvent;
import org.camunda.bpm.model.bpmn.instance.UserTask;
import org.camunda.bpm.model.xml.instance.ModelElementInstance;
public class ProcessGen {
void genSimpleProcess(){
// create an empty model
BpmnModelInstance modelInstance = Bpmn.createEmptyModel();
Definitions definitions = modelInstance.newInstance(Definitions.class);
definitions.setTargetNamespace("
http://camunda.org/examples");
modelInstance.setDefinitions(definitions);
// create the process
Process process = createElement(definitions, "process-with-one-task", Process.class); // ERROR
// create start event, user task and end event
StartEvent startEvent = createElement(process, "start", StartEvent.class); //ERROR
UserTask task1 = createElement(process, "task1", UserTask.class); //ERROR
task1.setName("User Task");
EndEvent endEvent = createElement(process, "end", EndEvent.class); // ERROR
// create the connections between the elements
createSequenceFlow(process, startEvent, task1);
createSequenceFlow(process, task1, endEvent);
// validate and write model to file
Bpmn.validateModel(modelInstance);
File file = File.createTempFile("bpmn-model-api-", ".bpmn");
Bpmn.writeModelToFile(file, modelInstance);
}
protected <T extends BpmnModelElementInstance> T createElement(BpmnModelElementInstance parentElement, String id, Class<T> elementClass) {
T element = modelInstance.newInstance(elementClass); // ERROR
element.setAttributeValue("id", id, true);
parentElement.addChildElement(element);
return element;
}
public SequenceFlow createSequenceFlow(Process process, FlowNode from, FlowNode to) {
String identifier = from.getId() + "-" + to.getId();
SequenceFlow sequenceFlow = createElement(process, identifier, SequenceFlow.class); // ERROR
process.addChildElement(sequenceFlow); // ERROR
sequenceFlow.setSource(from);
from.getOutgoing().add(sequenceFlow);
sequenceFlow.setTarget(to);
to.getIncoming().add(sequenceFlow);
return sequenceFlow;