1 6 7 package org.enhydra.shark.asap; 8 9 import java.rmi.RemoteException ; 10 import java.util.Map ; 11 12 import org.apache.axis.types.Duration; 13 import org.apache.axis.types.URI; 14 import org.enhydra.shark.api.client.wfmodel.WfProcess; 15 import org.enhydra.shark.api.client.wfmodel.WfProcessMgr; 16 import org.enhydra.shark.asap.types.*; 17 import org.enhydra.shark.asap.types.holders.*; 18 19 25 public class AsapFactoryBindingImpl implements FactoryPortType { 26 27 public void getProperties(Request rqHead, 28 String _rqBody, 29 ResponseHolder rsHead, 30 GetPropertiesRsHolder rsBody) throws RemoteException { 31 URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead, rsHead); 32 rsBody.value = new GetPropertiesRs(); 33 34 try { 35 String factoryName = AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey); 36 WfProcessMgr mgr = SharkServiceImpl.getExecAdmin() 37 .getProcessMgr(factoryName); 38 Map inputContext = SharkServiceImpl.getExecAdmin() 39 .getProcessMgrInputSignature(factoryName); 40 41 FactoryPropertiesGroup fpg = new FactoryPropertiesGroup(); 42 fpg.setKey(rqReceiverKey); 43 String name = SharkServiceImpl.getAdminMiscUtilities() 44 .getProcessMgrProcDefName(mgr.name()); 45 fpg.setName(name); 46 fpg.setSubject(""); 47 fpg.setDescription(mgr.description()); 48 fpg.setContextDataSchema(AsapBindingUtilitiesImpl.getContextDataSchema(inputContext)); 49 fpg.setResultDataSchema(AsapBindingUtilitiesImpl.getResultDataSchema(mgr.result_signature())); 50 fpg.setExpiration(new Duration("PT5M")); 51 rsBody.value.setFactoryPropertiesGroup(fpg); 52 } catch (Exception ex) { 53 ex.printStackTrace(); 54 throw new RemoteException ("Problems while retrieving context schema!!!"); 55 } 56 57 } 58 59 public void createInstance(Request rqHead, 60 CreateInstanceRq rqBody, 61 ResponseHolder rsHead, 62 CreateInstanceRsHolder rsBody) throws RemoteException { 63 URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead, rsHead); 64 65 69 CreateInstanceRqContextData rqContextData = rqBody.getContextData(); 70 String rqDescription = rqBody.getDescription(); 71 String rqName = rqBody.getName(); 72 if (null == rqName) rqName = "NONAME"; 73 URI rqObserverKey = rqBody.getObserverKey(); 74 String rqSubject = rqBody.getSubject(); 75 boolean rqStartImmediately = rqBody.isStartImmediately(); 76 77 try { 78 rsBody.value = new CreateInstanceRs(); 79 RequesterImpl r = new RequesterImpl(); 80 WfProcess p = SharkServiceImpl.getExecAdmin() 82 .getProcessMgr(AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey)) 83 .create_process(r); 84 Map m = p.manager().context_signature(); 85 System.err.println("MAP:" + m); 86 rsBody.value.setInstanceKey(AsapBindingUtilitiesImpl.instanceId2URI(p.key())); 87 r.addObserver(rsBody.value.getInstanceKey(), rqObserverKey); 88 p.set_requester(r); 89 p.set_name(rqName); 90 p.set_description(rqDescription); 91 Map context = AsapBindingUtilitiesImpl.parseContext(rqContextData, p); 92 if (null != context) { 93 p.set_process_context(context); 94 } 95 if (rqStartImmediately) { 96 startProcess(p); 97 } 98 } catch (Exception e) { 99 e.printStackTrace(); 100 throw new RemoteException (e.getMessage()); 101 } 102 } 103 104 public void listInstances(Request rqHead, 105 ListInstancesRq rqBody, 106 ResponseHolder rsHead, 107 ListInstancesRsHolder rsBody) throws RemoteException { 108 URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead, rsHead); 109 FilterType rqFilter = rqBody.getFilter(); 110 111 try { 112 rsBody.value = new ListInstancesRs(); 113 System.err.println("#key:" 114 + AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey)); 115 WfProcess[] processes = SharkServiceImpl.getExecAdmin() 116 .getProcessMgr(AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey)) 117 .get_sequence_process(0); 118 System.err.println("#processes.length:" + processes.length); 119 Instance[] array = new Instance[processes.length]; 120 for (int n = 0; n < processes.length; ++n) { 121 array[n] = new Instance(); 122 array[n].setInstanceKey(AsapBindingUtilitiesImpl.instanceId2URI(processes[n].key())); 123 array[n].setName(processes[n].name()); 124 array[n].setPriority(new Integer (processes[n].priority())); 125 array[n].setSubject(""); 126 } 127 rsBody.value.setInstance(array); 128 System.err.println("#array.length" + array.length); 129 } catch (Exception e) { 130 e.printStackTrace(); 131 throw new RemoteException (e.getMessage()); 132 } 133 } 134 135 private static void startProcess(final WfProcess process) { 136 new Thread () { 137 public void run() { 138 try { 139 process.start(); 140 } catch (Exception e) { 141 e.printStackTrace(); 142 } 143 } 144 }.start(); 145 } 146 } | Popular Tags |