3

I need to generate BPEL XML code in runtime. The only way I can do it now is to create XML document with "bare hands" using DOM API. But there must be a framework that could ease such work incorporating some kind of object model.

I guess it should look something like this:

BPELProcessFactory.CreateProcess().addSequence

Do you know any?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Wespiner
  • 81
  • 5

2 Answers2

2

The Eclipse BPEL designer project provides an EMF model for BPEL 2.0. The generated code can be used to programmatically create BPEL code with a convenient API.

vanto
  • 3,134
  • 18
  • 28
  • Do you have a working example ?? I am receiving an error as I stated [here](http://stackoverflow.com/questions/15353097/generating-bpel-files-programmatically) when using eclipse BPEL designer API to generate .bpel file – faridasabry Mar 13 '13 at 04:52
  • Please see my answer below. I have used this code, found from some forum, to create a basic bpel file, but I am unable to modify the code to create the bpel file according to my needs, because I have not found any **documentation** for this code. Can you guide me where to find any guideline on how I would go about modifying this code for advanced bpel functionalities? – Ahmed Akhtar Jun 24 '16 at 06:28
0

In case anyone stumbles upon this.

Yes this can be done using the BPEL Model.

Here is a sample piece of code which generates a quite trivial BPEL file:

public Process createBPEL()
{
    Process process = null;
    BPELFactory factory = BPELFactory.eINSTANCE;

    try
    {
        ResourceSet rSet = new ResourceSetImpl();
        rSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
                .put("bpel", new BPELResourceFactoryImpl());
        File file = new File("myfile.bpel");
        file.createNewFile();
        String filePath = file.getAbsolutePath();
        System.out.println(filePath);
        AdapterRegistry.INSTANCE.registerAdapterFactory( BPELPackage.eINSTANCE, BasicBPELAdapterFactory.INSTANCE );
        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);

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

        resource.save(map);
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    return process;
}

The dependencies require that you add the following jars to the project's build path from the plugins folder in eclipse installation directory:

  • org.eclipse.bpel.model_*.jar
  • org.eclipse.wst.wsdl_*.jar
  • org.eclipse.emf.common_*.jar
  • org.eclipse.emf.ecore_*.jar
  • org.eclipse.emf.ecore.xmi_*.jar
  • javax.wsdl_*.jar
  • org.apache.xerces_*.jar
  • org.eclipse.bpel.common.model_*.jar
  • org.eclipse.xsd_*.jar
  • org.eclipse.core.resources_*.jar
  • org.eclipse.osgi_*.jar
  • org.eclipse.core.runtime_*.jar
  • org.eclipse.equinox.common_*.jar
  • org.eclipse.core.jobs_*.jar
  • org.eclipse.core.runtime.compatibility_*.jar
Ahmed Akhtar
  • 1,444
  • 1
  • 16
  • 28