Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » BPEL Designer » Create BPEL Process from java program
Create BPEL Process from java program [message #559779] Sat, 18 September 2010 10:43 Go to next message
lamine  is currently offline lamine Friend
Messages: 4
Registered: September 2010
Junior Member
I want to create a BPEL process from java program, using eclipse BPEL API,

I use this code :

BPELPackageImpl.init();
BPELPackage.eINSTANCE.eClass();
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
Map<String, Object> m = reg.getExtensionToFactoryMap();
m.put("bpel", new BPELResourceFactoryImpl());

URI uri = URI.createURI("examples/myFirstProcess.bpel");

ResourceSet resSet = new ResourceSetImpl();
Resource resource = resSet.createResource(uri) ;

BPELResourceImpl bpelResImp = (BPELResourceImpl) resource;

BPELFactory factory = BPELFactory.eINSTANCE;
process = factory.createProcess();
process.setName("xxxxx");
Sequence mySeq = BPELFactory.eINSTANCE.createSequence();
mySeq.setName("mainSequence");
Invoke myInv = BPELFactory.eINSTANCE.createInvoke();
process.setActivity(mySeq);
bpelResImp.getContents().add(process);
bpelResImp.save(null);





when I execute this program this exception is occured in this statement : " bpelResImp.save(null);":


java.lang.IllegalStateException: INamespaceMap cannot be attached to an eObject
at org.eclipse.bpel.model.util.BPELUtils.getNamespaceMap(BPELUt ils.java:260)
at org.eclipse.bpel.model.resource.BPELResourceImpl.doSave(BPEL ResourceImpl.java:88)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:1406)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993)
at ws.gen.BPELGenerator.createProc(BPELGreator.java:245)
at ws.gen.BPELGenerator.main
(BPELCreator.java:268)


any help please?
Re: Create BPEL Process from java program [message #658169 is a reply to message #559779] Mon, 07 March 2011 09:31 Go to previous messageGo to next message
Kamrad  is currently offline Kamrad Friend
Messages: 3
Registered: March 2011
Junior Member
Following code works fine for me (despite fact that it generates crap), but at least it could be considered as first step:
	protected Process createBPEL() {

		Process process = null;

		try {
			ResourceSet rSet = new ResourceSetImpl();
			rSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
					.put("xml", new GenericXMLResourceFactoryImpl());
			File file = new File("myfile.xml");
			file.createNewFile();
			String filePath = file.getAbsolutePath();
			System.out.println(filePath);
			Resource resource = rSet.createResource(URI.createFileURI(filePath));

			process = factory.createProcess();
			process.setName("FirstBPEL");
			Sequence seq = factory.createSequence();
			seq.setName("MainSequence");
			
			Receive recieve = factory.createReceive();
			PortType portType = new PortTypeProxy(URI.createURI("http://baseuri"), new QName("qname"));
			Operation operation = 
                               new OperationProxy(URI.createURI("http://localhost"), portType , "operation_name");
			recieve.setOperation(operation);
			
			Invoke invoke = factory.createInvoke();
			invoke.setOperation(operation);
			
			
			While whiles = factory.createWhile();
			If if_st = factory.createIf();
			
			List<Activity> activs = new ArrayList<Activity>();
			activs.add(recieve);
			activs.add(invoke);
			activs.add(if_st);
			activs.add(whiles);
			
			
			seq.getActivities().addAll(activs);
			
			process.setActivity(seq);

			resource.getContents().add(process);
			resource.save(null);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return process;
	}
Re: Create BPEL Process from java program [message #658243 is a reply to message #658169] Mon, 07 March 2011 14:57 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 Kamrad,

The BPEL EMF model that's used in the editor is not really meant to be used to serialized/deserialize XML. The way the editor does its serialization is through a DOM that is used as the model for the "Source" tab in the editor. Take a look at the BPELWriter class to see how the BPEL XML is created - there are methods for each of the BPEL activities and other stuff which create the DOM elements.

You might be able to adapt the writer for your own use. I think what you'd need to do is first construct the EMF model for the BPEL process that you want, then create a DOM and use the BPELWriter to serialize into that DOM (don't forget to add the appropriate namespaces!)

If you do get this to work, please let me know - I think it would be really useful to add this to the BPEL Designer as a public API.

Thanks in advance!

Bob
Re: Create BPEL Process from java program [message #659808 is a reply to message #658243] Tue, 15 March 2011 16:49 Go to previous messageGo to next message
Kamrad  is currently offline Kamrad Friend
Messages: 3
Registered: March 2011
Junior Member
Thanks a lot! But my another question is what exactly your output format are? Is it possible to deploy it to Apache ODE somehow?
Re: Create BPEL Process from java program [message #659887 is a reply to message #659808] Tue, 15 March 2011 21:59 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

Well, yes...as long as the output is valid BPEL and all of the imports are resolved you should be able to deploy the whole lot. You can either zip the entire bpel content folder and copy it to your Ode runtime directory, or you can recreate the folder and files structure there.

You will also need a deployment descriptor (deploy.xml) which defines the processes and their interfaces. All of this is in org.eclipse.bpel.apache.ode.deloy.model and .ui
Re: Create BPEL Process from java program [message #673188 is a reply to message #659887] Sun, 22 May 2011 19:01 Go to previous messageGo to next message
Ion  is currently offline Ion Friend
Messages: 1
Registered: May 2011
Junior Member
Hi!
I am using BPEL Designer with Eclipse Helios to create BPEL process files, but now I need to do this programmatically from a Java program and I can't resolve the imports for the code posted above. Could I create the BPEL file using the BPELWriter class from org.eclipse.bpel.common.extension.model?
Re: Create BPEL Process from java program [message #894721 is a reply to message #559779] Tue, 10 July 2012 09:27 Go to previous messageGo to next message
nitin agarwal is currently offline nitin agarwalFriend
Messages: 1
Registered: July 2012
Junior Member
if u got a error eObject not null getNamespaceMap()

them must check and reset request and response objects of invoking service to globle object. i have done it and solved my problem.
Re: Create BPEL Process from java program [message #1015906 is a reply to message #559779] Mon, 04 March 2013 08:56 Go to previous messageGo to next message
Farida Sabry is currently offline Farida SabryFriend
Messages: 2
Registered: February 2013
Junior Member
Have anyone managed to do this task .. I am trying to do the same to dynamically create a bpel process and deploy based on some inputs.. I tried the above code (after importing a lot of jar files from eclipse plugins folder) but
with :
rSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put("bpel", new BPELResourceFactoryImpl());
instead of "xml" .....
and I am receiving the following exception:
java.lang.IllegalStateException: INamespaceMap cannot be attached to an eObject
at org.eclipse.bpel.model.util.BPELUtils.getNamespaceMap(BPELUtils.java:271)
at org.eclipse.bpel.model.resource.BPELResourceImpl.doSave(BPELResourceImpl.java:101)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:1417)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(ResourceImpl.java:986)
at BPELCreator.createBPEL(BPELCreator.java:34)

Do you know how to solve this problem?? And if in the first sense, the org.eclipse.bpel.model API can be used programmatically to generate .bpel files??
icon3.gif  Re: Create BPEL Process from java program [message #1045039 is a reply to message #559779] Fri, 19 April 2013 17:27 Go to previous messageGo to next message
Luca Pino is currently offline Luca PinoFriend
Messages: 1
Registered: April 2013
Junior Member
Just add
AdapterRegistry.INSTANCE.registerAdapterFactory( BPELPackage.eINSTANCE, BasicBPELAdapterFactory.INSTANCE );

before the creation of the resource to get rid of the error
java.lang.IllegalStateException: INamespaceMap cannot be attached to an eObject


(took quite a while to solve this, hope it will be useful to others!)

edit: also it might be the case to mention this in the BPEL Model page - http://www.eclipse.org/bpel/developers/model.php
under the Reading and Writing BPEL Files, as I saw a lot of people struggling with this in the forum and mailing list.

[Updated on: Sat, 20 April 2013 12:47]

Report message to a moderator

Re: Create BPEL Process from java program [message #1057817 is a reply to message #1015906] Thu, 09 May 2013 03:12 Go to previous message
Areeg Samir is currently offline Areeg SamirFriend
Messages: 9
Registered: August 2012
Location: Egypt
Junior Member
https://groups.google.com/forum/?fromgroups=#!topic/bpelundereclipse/sFxojjpbDKo
Previous Topic:Complex type in BPEL Designer
Next Topic:Apache Server
Goto Forum:
  


Current Time: Thu Apr 25 15:55:28 GMT 2024

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

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

Back to the top