Re: Process Definition Creation API

Sasa Bojanic <[email protected]> Wed, 13 Dec 2006 10:15:45 +0100
Newsgroups gmane.comp.java.enhydra.shark
Message-ID <[email protected]>
This is a multi-part message in MIME format...

------------=_1166001218-3131-29
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

there is no Shark API for creating XPDLs programmatically.
However, you can directly use JaWE's XPDL model implementation (which is 
also used in shark to parse XPDLs) to create XPDLs.
The following code creates XPDL Package, sets some properties, adds one 
participant, one process and one activity for the process.

       org.enhydra.shark.xpdl.elements.Package pkg=new 
org.enhydra.shark.xpdl.elements.Package();
       pkg.setId("test");
       pkg.setName("XPDL Test");
       pkg.getScript().setType("text/javascript");
       pkg.getPackageHeader().setXPDLVersion("1.0");
       pkg.getPackageHeader().setVendor("Together");
       pkg.getPackageHeader().setCreated("2006-12-13");
      
       Participant 
p=(Participant)pkg.getParticipants().generateNewElement();
       p.setId("secretary");
       p.getParticipantType().setTypeROLE();
       pkg.getParticipants().add(p);
      
       WorkflowProcess 
wp=(WorkflowProcess)pkg.getWorkflowProcesses().generateNewElement();
       pkg.getWorkflowProcesses().add(wp);
       wp.setAccessLevelPUBLIC();
       wp.setId("test");
       wp.setName("Test 1");
      
       ProcessHeader ph=wp.getProcessHeader();
       ph.setDescription("Description of process 1");
       ph.set("Priority","1");
      
       Activities acts=wp.getActivities();
       Activity act=(Activity)acts.generateNewElement();
       act.setId("actId");
       act.setName("Do something");
       act.getActivityTypes().setImplementation();
       
act.getActivityTypes().getImplementation().getImplementationTypes().setNo();
       act.setPerformer("secretary");
       act.setDescription("Test activity");
       acts.add(act);
      

To save such XPDL to a file you can do something like:

       Document document = null;
       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
       DocumentBuilder dbuilder = dbf.newDocumentBuilder();
       document = dbuilder.newDocument();
       FileOutputStream os=new FileOutputStream("c:/test.xpdl");

       XPDLRepositoryHandler xpdlRH=new XPDLRepositoryHandler();
       xpdlRH.toXML(document,*pkg*);

       // Use a Transformer for output
       TransformerFactory tFactory = TransformerFactory.newInstance();
       Transformer transformer = tFactory.newTransformer();
       transformer.setOutputProperty("indent","yes");
       
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4");
       transformer.setOutputProperty("encoding","UTF8");
       DOMSource source = new DOMSource(document);
       StreamResult result = new StreamResult(os);
       transformer.transform(source,result);
       os.close();


Greetings,
Sasa.

[email protected] wrote:
> Hello All,
>
> Is there an API that Shark exposes to programmatically create a process definition?  What I want to do is to create an API facade around Shark's API to create workflows and run them programmatically.
>
> Regards,
> Barry
>
>   
> ------------------------------------------------------------------------
>
>
> --
> You receive this message as a subscriber of the [email protected] mailing list.
> To unsubscribe: mailto:[email protected]
> For general help: mailto:[email protected]?subject=help
> ObjectWeb mailing lists service home page: http://www.objectweb.org/wws
>   



------------=_1166001218-3131-29
Content-Type: text/plain; name="message-footer.txt"
Content-Disposition: inline; filename="message-footer.txt"
Content-Transfer-Encoding: 8bit


--
You receive this message as a subscriber of the [email protected] mailing list.
To unsubscribe: mailto:[email protected]
For general help: mailto:[email protected]?subject=help
ObjectWeb mailing lists service home page: http://www.objectweb.org/wws

------------=_1166001218-3131-29--