MessageFlow in BPMN 2.0 Modeler [message #1427665] |
Sat, 20 September 2014 11:37  |
Eclipse User |
|
|
|
Hi,
I was recently advised to try out org.eclipse.bpmn2.modeler.examples.modelreader in order to be able to access model elements through a simple Java programme. The example code accessed and displayed all the elements except MessageFlow elements between elements in two pools. The MessageFlow elements are not accessed although I have also added the following two lines in the code (the code is included for my adaptation of the modelreader.java file from Modeler example).
import org.eclipse.bpmn2.MessageFlow;
import org.eclipse.bpmn2.impl.MessageFlowImpl;
Having designed a test .bpmn file (a collaboration BPMN 2.0 diagram) with one message flow between two pools , my test java program is not able to show the MessageFlow instance which I except to see for the only message flow in .bpmn file. The bpmn file testMessageFlow.bpmn is also attached.
I need a direction here to understand what the problem is behind this.
Your advice, I'll appreciate.
Regards
MA
Package my.package.info
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import org.eclipse.bpmn2.Definitions;
import org.eclipse.bpmn2.FlowElement;
import org.eclipse.bpmn2.RootElement;
import org.eclipse.bpmn2.SequenceFlow;
import org.eclipse.bpmn2.MessageFlow;
import org.eclipse.bpmn2.impl.MessageFlowImpl;
import org.eclipse.bpmn2.impl.SequenceFlowImpl;
import org.eclipse.bpmn2.util.Bpmn2ResourceFactoryImpl;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.xmi.XMLResource;
public class MyBPMN2ModelReader {
public void ReadThisModel(String theBPMNFile) throws IOException {
URI uri = URI.createURI(theBPMNFile);
//URI uri = URI.createURI("SampleProcess.bpmn");
Bpmn2ResourceFactoryImpl resFactory = new Bpmn2ResourceFactoryImpl();
Resource resource = resFactory.createResource(uri);
// We need this option because all object references in the file are "by ID"
// instead of the document reference "URI#fragment" form.
HashMap<Object, Object> options = new HashMap<Object, Object>();
options.put(XMLResource.OPTION_DEFER_IDREF_RESOLUTION, true);
// Load the resource
resource.load(options);
// This is the root element of the XML document
Definitions d = getDefinitions(resource);
// Print all elements contained in all Processes found
List<RootElement> rootElements = d.getRootElements();
for (RootElement re : rootElements) {
if (re instanceof org.eclipse.bpmn2.Process) {
org.eclipse.bpmn2.Process process = (org.eclipse.bpmn2.Process) re;
System.out.println("Process: name="+process.getName()+" ID="+process.getId());
for (FlowElement fe : process.getFlowElements()) {
if (fe instanceof MessageFlowImpl) {
MessageFlow mf = ((MessageFlow) fe);
System.out.println("Message flow found.");
}
if (fe instanceof SequenceFlowImpl) {
SequenceFlow sf = ((SequenceFlow) fe);
if (sf != null) {
String source = "";
String target = "";
if (sf.getSourceRef() != null)
source = sf.getSourceRef().getId();
if (sf.getTargetRef() != null)
target = sf.getTargetRef().getId();
System.out.println("Sequence Flow: " + source + " -> " + target);
}
}
else {
System.out.println(fe.eClass().getName()+": name="+fe.getName()+" ID="+fe.getId());
}
}
}
}
}
private static Definitions getDefinitions(Resource resource) {
if (resource!=null && !resource.getContents().isEmpty() && !resource.getContents().get(0).eContents().isEmpty()) {
// Search for a Definitions object in this Resource
for (EObject e : resource.getContents()) {
for (Object o : e.eContents()) {
if (o instanceof Definitions)
return (Definitions) o;
}
}
}
return null;
}
}
And the test code is:
import java.io.IOException;
public class MyBPMN2ModelReaderTest {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
MyBPMN2ModelReader myReader = new MyBPMN2ModelReader();
myReader.ReadThisModel("testMessageFlow.bpmn");
}
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: MessageFlow in BPMN 2.0 Modeler [message #1695182 is a reply to message #1695169] |
Tue, 12 May 2015 10:00  |
Eclipse User |
|
|
|
OK, let's everyone take a step back here...
I think the confusion is in the basic EMF API, and this may be my fault for assuming everyone is familiar with EMF. There are lots of tutorials and examples on how to use EMF - I suggest starting there.
|
|
|
Powered by
FUDForum. Page generated in 0.54274 seconds