Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » BPMN 2.0 Modeler » Load BPMN2 model using the API
Load BPMN2 model using the API [message #1070295] Wed, 17 July 2013 16:53 Go to next message
Poissy B. is currently offline Poissy B.Friend
Messages: 31
Registered: June 2012
Member
Hello everyone,

Sorry this is a stupid question but I can't seem to be able to load a .bpmn2 model created with the modeler using the bpmn2 ecore api. Could someone share a code snippet on how to do this.

Sorry I am not giving more details about the errors because I am convinced it is stupidity on my end, but now I've spent too much time trying to load the damn model. Please help!

Thanks.

[Updated on: Mon, 29 July 2013 14:56]

Report message to a moderator

Re: Load BPMN2 model using the API [message #1070306 is a reply to message #1070295] Wed, 17 July 2013 17:40 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Hi Poissy,

Is it possible you're using the XMI loader instead of the XML loader? Try using the Bpmn2ResourceImpl class.

Bob
Re: Load BPMN2 model using the API [message #1070332 is a reply to message #1070306] Wed, 17 July 2013 18:58 Go to previous messageGo to next message
Poissy B. is currently offline Poissy B.Friend
Messages: 31
Registered: June 2012
Member
Hi Bob,

I've managed to load it. Could you confirm this is a correct way please:


Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("bpmn2", new Bpmn2ResourceFactoryImpl());

ResourceSet resSet = new ResourceSetImpl();

Resource resource = resSet.getResource(URI.createURI("My.bpmn2"), true);
		
DocumentRoot dr = (DocumentRoot)resource.getContents().get(0);
Process p = dr.getProcess();


Also the Process object is null even though I have a process element in the bpmn file. Am I doing something wrong?

Thanks!

[Updated on: Wed, 17 July 2013 19:03]

Report message to a moderator

Re: Load BPMN2 model using the API [message #1070399 is a reply to message #1070332] Wed, 17 July 2013 22:26 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Close, but not quite right Wink
Here's how you should load a bpmn process file from a workspace project:

			// Create a URI from a file string, workspace project string, URL, whatever...
			URI uri = URI.createFileURI("/MyEclipseProject/process_1.bpmn");
			Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
			// get the Resource Factory for this URI (it should be the Bpmn2ResourceFactory!)
			Factory f = reg.getFactory(uri);
			// create the resource object (note that this does not actually LOAD the file)
			Resource res = f.createResource(uri);
			try {
				// load it
				res.load(null);
			}
			catch (IOException e) {
				// handle "file not found" exceptions, HTTP timeouts, etc. here
				e.printStackTrace();
			}


To access the model elements, you need to start with the Definitions element obtained from the DocumentRoot. Then, to find the first Process object (or any other BPMN2 RootElement object) use this:

			DocumentRoot root = (DocumentRoot) res.getContents().get(0);
			Definitions definitions = root.getDefinitions();
			for (RootElement re : definitions.getRootElements()) {
				if (re instanceof Process) {
					Process p = (Process)re;
					break;
				}
			}


Yes, I know it's convoluted, but that's how it works Wink

HTH,
Bob
Re: Load BPMN2 model using the API [message #1070755 is a reply to message #1070399] Thu, 18 July 2013 15:42 Go to previous messageGo to next message
Poissy B. is currently offline Poissy B.Friend
Messages: 31
Registered: June 2012
Member
Thanks a lot Bob! In my case I still had to map the correct factory to the bpmn extension:

reg.getExtensionToFactoryMap().put("bpmn2", new Bpmn2ResourceFactoryImpl());


Actually I just got that you implemented the actual BPMN metamodel as described in the OMG standard. Everything makes much more sense now! At least I have nice UML diagrams to look into to find my answers now Smile

Thanks again!


Re: Load BPMN2 model using the API [message #1074710 is a reply to message #1070755] Sat, 27 July 2013 14:29 Go to previous messageGo to next message
Poissy B. is currently offline Poissy B.Friend
Messages: 31
Registered: June 2012
Member
Just figured out something else: we have to create the resource from the resource set otherwise some objects won't resolve proxies. Here is the full code to load a BPMN2 model properly using the BPMN20 API:

// Create a URI from a file string, workspace project string, URL, whatever...
URI uri = URI.createURI("FileName.bpmn2");
		
//Register the BPMN2ResourceFactory in Factory registry
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
reg.getExtensionToFactoryMap().put("bpmn2", new Bpmn2ResourceFactoryImpl());
		
// load the resource and resolve 
ResourceSet rs = new ResourceSetImpl();
Resource res = rs.createResource(uri);
		
try {
	// load it
	res.load(null);
} catch (IOException e) {
	// handle "file not found" exceptions, HTTP timeouts, etc. here
	e.printStackTrace();
}
Re: Load BPMN2 model using the API [message #1075021 is a reply to message #1074710] Sun, 28 July 2013 13:11 Go to previous messageGo to next message
Robert Brodt is currently offline Robert BrodtFriend
Messages: 811
Registered: August 2010
Location: Colorado Springs, CO
Senior Member

Thanks for sharing Poissy!
Re: Load BPMN2 model using the API [message #1075219 is a reply to message #1075021] Mon, 29 July 2013 03:37 Go to previous message
patricia ashaww is currently offline patricia ashawwFriend
Messages: 1
Registered: July 2013
Junior Member
Thanks for the information in here. Really a great help!
Previous Topic:how to add a new attribute to the bpmn2 model without any extension
Next Topic:Custom Service Tasks from .wid file
Goto Forum:
  


Current Time: Thu Apr 18 17:25:42 GMT 2024

Powered by FUDForum. Page generated in 0.03262 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top