Generating BPEL files programmatically?

2019-02-17 00:24发布

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?

5条回答
放荡不羁爱自由
2楼-- · 2019-02-17 00:32

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.

查看更多
姐就是有狂的资本
3楼-- · 2019-02-17 00:35

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

查看更多
仙女界的扛把子
4楼-- · 2019-02-17 00:40

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.

查看更多
劫难
5楼-- · 2019-02-17 00:49

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.

查看更多
虎瘦雄心在
6楼-- · 2019-02-17 00:54

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.

查看更多
登录 后发表回答