Generating BPEL files programmatically?
Asked Answered
S

5

7

Is there a way to generate BPEL programmatically in Java?

I tried using the BPEL Eclipse Designer API to write this code:

 Process process = null; 
 try {



        Resource.Factory.Registry reg =Resource.Factory.Registry.INSTANCE;

        Map<String, Object> m = reg.getExtensionToFactoryMap();

        m.put("bpel", new BPELResourceFactoryImpl());//it works with XMLResourceFactoryImpl()



         //create resource

         URI uri =URI.createFileURI("myBPEL2.bpel");



         ResourceSet rSet = new ResourceSetImpl();

          Resource bpelResource = rSet.createResource(uri);



          //create/populate process

          process = BPELFactory.eINSTANCE.createProcess();

          process.setName("myBPEL");

          Sequence mySeq = BPELFactory.eINSTANCE.createSequence();

          mySeq.setName("mainSequence");

          process.setActivity(mySeq);



          //save resource

          bpelResource.getContents().add(process);

          Map<String,String> map= new HashMap<String, String>();
          map.put("bpel", "http://docs.oasis-open.org/wsbpel/2.0/process/executable");
          map.put("tns", "http://matrix.bpelprocess");
          map.put("xsd", "http://www.w3.org/2001/XMLSchema");
          bpelResource.save(map);

    }



    catch (Exception e) {

          e.printStackTrace();

    }


}

but I received an error:

INamespaceMap cannot be attached to an eObject ...

I read this message by Simon:

I understand that using the BPEL model outside of eclipse might be desirable, but it was never intended by us. Thus, this isn't supported

Is there any other API that can help?

Scenery answered 12/3, 2013 at 4:4 Comment(1)
eclipse.org/forums/index.php/m/1015906 is about the same error you are seeing. Have you already come across that? Maybe you should stick to eclipse forums for problems like yours. The probability of someone else being able to help you is higher than here on stackoverflow.Jumpy
S
2

This has been solved using the unify framework API after adding the necessary classes to handle correlation. BPELUnit stated by @Daniel seems to be another alternative.

Scenery answered 15/9, 2013 at 7:47 Comment(3)
Could you please provide a step by step guide for how you solved the problem?Kazue
As far as I remember, the steps depends on the process you would like to generate, download the API and you have to use BpelProcess object and add to it your desired activities (Receive, Assign, Reply ....) and then use BpelSerializer to serialize the process and generate the .bpel file, hope this helps.Scenery
Thank you so much for replying. It would be great if you could please post some sample code?Kazue
G
3

You might want to give JAXB a try. It helps you to transform the official BPEL XSD into Java classes. You use those classes to construct your BPEL document and output it.

Granuloma answered 13/3, 2013 at 9:56 Comment(0)
D
3

I had exactly the same problem with the BPELUnit [1], so I started a module in BPELUnit that has the first things necessary for generating and reading BPEL Models [2] although it is far from complete. Supported is only BPEL 2.0 (1.1 will follow later) and handlers are also currently not supported (but will be added). It is under active development because BPELUnit's code coverage component will be based on it so it will get BPEL-feature complete over time. You are happily invited to contribute if you need to close gaps earlier.

You can check it out from GitHub or grap the Maven artifact.

As of now there is no documentation but you can have a look at the JUnit tests that read and write processes.

If this is not suitable for, I'd like to share some experiences with you:

  1. Do not use JAXB: You will need to read and write XML Namespaces which are not preserved with JAXB. That's why I have chosen XMLBeans. DOM would be the other alternative that I can think of.

  2. The inheritance in the XML Schema is not really developer friendly. That's why there are own interface structures and wrappers around the XMLBeans generated classes.

Daniel

[1] http://www.bpelunit.net
[2] https://github.com/bpelunit/bpelunit/tree/master/net.bpelunit.model.bpel

Danita answered 5/4, 2013 at 9:59 Comment(0)
S
2

This has been solved using the unify framework API after adding the necessary classes to handle correlation. BPELUnit stated by @Daniel seems to be another alternative.

Scenery answered 15/9, 2013 at 7:47 Comment(3)
Could you please provide a step by step guide for how you solved the problem?Kazue
As far as I remember, the steps depends on the process you would like to generate, download the API and you have to use BpelProcess object and add to it your desired activities (Receive, Assign, Reply ....) and then use BpelSerializer to serialize the process and generate the .bpel file, hope this helps.Scenery
Thank you so much for replying. It would be great if you could please post some sample code?Kazue
J
1

The Eclipse BPEL API is based on an EMF Model. So you could generate your own artifacts using JET or Xpand based on that. This way there is no requirement to run inside Eclipse.

Although you may can't use BPEL outside of Eclipse, have you considered moving parts of your application inside it?

The BPEL XML Schemas are listed in the appendig of the spec. So you could also base your work on that and integrate with existing BPEL applications where necessary.

Jumpy answered 12/3, 2013 at 7:43 Comment(3)
I was asking about creating .bpel files dynamically in Java code, I don't need to create a graphical model .. just a dynamic workflow based on the inputsScenery
@user1925930 I think that's what I was talking about. You can save EMF models as xml with a user defined file extension via the EMF Resources API.Jumpy
I edited my question to include the code I was trying with the org.eclipse.bpel.model and org.eclipse.emf.ecore.resource but I received the error mentioned above ..do you have an idea how to solve?Scenery
K
0

In case anyone is looking to solve the above problem while still running inside eclipse environment.

The problem can be resolved as stated by Luca Pino here by adding:

AdapterRegistry.INSTANCE.registerAdapterFactory( BPELPackage.eINSTANCE, BasicBPELAdapterFactory.INSTANCE );

before the resource creation line i.e.

Resource bpelResource = rSet.createResource(uri);

Note: Another solution, to the same problem, also stating how to resolve the dependencies to make this code work, can be found in my other answer here.

Kazue answered 21/6, 2016 at 21:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.