KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > asap > AsapFactoryBindingImpl


1 /*
2  * AsapFactoryBindingImpl.java
3  *
4  * This file was auto-generated from WSDL by the Apache Axis WSDL2Java emitter.
5  */

6
7 package org.enhydra.shark.asap;
8
9 import java.rmi.RemoteException JavaDoc;
10 import java.util.Map JavaDoc;
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 /**
20  * ASAP factory implementation
21  *
22  * @author V.Puskas, S.Bojanic
23  * @version 0.1
24  */

25 public class AsapFactoryBindingImpl implements FactoryPortType {
26
27    public void getProperties(Request rqHead,
28                              String JavaDoc _rqBody,
29                              ResponseHolder rsHead,
30                              GetPropertiesRsHolder rsBody) throws RemoteException JavaDoc {
31       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead, rsHead);
32       rsBody.value = new GetPropertiesRs();
33
34       try {
35          String JavaDoc factoryName = AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey);
36          WfProcessMgr mgr = SharkServiceImpl.getExecAdmin()
37             .getProcessMgr(factoryName);
38          Map JavaDoc inputContext = SharkServiceImpl.getExecAdmin()
39             .getProcessMgrInputSignature(factoryName);
40
41          FactoryPropertiesGroup fpg = new FactoryPropertiesGroup();
42          fpg.setKey(rqReceiverKey);
43          String JavaDoc 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 JavaDoc ex) {
53          ex.printStackTrace();
54          throw new RemoteException JavaDoc("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 JavaDoc {
63       URI rqReceiverKey = AsapBindingUtilitiesImpl.turnHeads(rqHead, rsHead);
64
65       // System.err.println("##" + rqHead + "\n[" + rqReceiverKey + "|"
66
// + rqRequestID + "|" + rqResponseRequired + "|" + rqSenderKey
67
// + "]");
68

69       CreateInstanceRqContextData rqContextData = rqBody.getContextData();
70       String JavaDoc rqDescription = rqBody.getDescription();
71       String JavaDoc rqName = rqBody.getName();
72       if (null == rqName) rqName = "NONAME";
73       URI rqObserverKey = rqBody.getObserverKey();
74       String JavaDoc rqSubject = rqBody.getSubject();
75       boolean rqStartImmediately = rqBody.isStartImmediately();
76
77       try {
78          rsBody.value = new CreateInstanceRs();
79          RequesterImpl r = new RequesterImpl();
80          //r.addDefaultObserver(rqObserverKey.toString());
81
WfProcess p = SharkServiceImpl.getExecAdmin()
82             .getProcessMgr(AsapBindingUtilitiesImpl.parseFactoryReceiverKey(rqReceiverKey))
83             .create_process(r);
84          Map JavaDoc 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 JavaDoc 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 JavaDoc e) {
99          e.printStackTrace();
100          throw new RemoteException JavaDoc(e.getMessage());
101       }
102    }
103
104    public void listInstances(Request rqHead,
105                              ListInstancesRq rqBody,
106                              ResponseHolder rsHead,
107                              ListInstancesRsHolder rsBody) throws RemoteException JavaDoc {
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 JavaDoc(processes[n].priority()));
125             array[n].setSubject("");
126          }
127          rsBody.value.setInstance(array);
128          System.err.println("#array.length" + array.length);
129       } catch (Exception JavaDoc e) {
130          e.printStackTrace();
131          throw new RemoteException JavaDoc(e.getMessage());
132       }
133    }
134
135    private static void startProcess(final WfProcess process) {
136       new Thread JavaDoc() {
137          public void run() {
138             try {
139                process.start();
140             } catch (Exception JavaDoc e) {
141                e.printStackTrace();
142             }
143          }
144       }.start();
145    }
146 }
Popular Tags