Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating BPEL files programmatically?

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?

like image 574
faridasabry Avatar asked Mar 12 '13 04:03

faridasabry


3 Answers

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.

like image 130
Sebi Avatar answered Oct 13 '22 23:10

Sebi


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

like image 25
Daniel Luebke Avatar answered Oct 13 '22 23:10

Daniel Luebke


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.

like image 32
faridasabry Avatar answered Oct 13 '22 23:10

faridasabry