KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corba > poa > WfProcessCORBA


1 package org.enhydra.shark.corba.poa;
2
3 import org.omg.TimeBase.UtcT;
4 import org.omg.WfBase.BaseException;
5 import org.omg.WfBase.NameValue;
6 import org.omg.WorkflowModel.*;
7 import org.omg.CORBA.ORB JavaDoc;
8 import org.omg.PortableServer.POA JavaDoc;
9 import org.omg.PortableServer.POAHelper JavaDoc;
10 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
11 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc;
12 import org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc;
13 import org.enhydra.shark.corba.poa.*;
14
15 /**
16  * WfProcessImpl - Workflow Process Object implementation
17  *
18  * @author David Forslund
19  * @version 1.0
20  */

21 public class WfProcessCORBA extends WfProcessPOA {
22
23     org.enhydra.shark.api.client.wfmodel.WfProcess sharkProc;
24
25     private Collective __collective;
26     private ORB JavaDoc orb;
27
28     /**
29      * Creates new WfProcessImpl
30      *
31      * @param sharkProc a WfProcess
32      */

33     protected WfProcessCORBA(ORB JavaDoc orb, Collective toJoin,
34                              org.enhydra.shark.api.client.wfmodel.WfProcess sharkProc) {
35
36         __collective = toJoin;
37         this.orb = orb;
38   // toJoin.__recruit(this);
39
this.sharkProc = sharkProc;
40     }
41
42     /**
43      * Retrieve the requestor of this process.
44      */

45     public WfRequester requester() throws BaseException {
46         try {
47             WfRequester req;
48             org.enhydra.shark.api.client.wfmodel.WfRequester requester = sharkProc.requester();
49             if (requester instanceof org.enhydra.shark.api.client.wfmodel.WfActivity) {
50                 req = SharkCORBAUtilities.makeWfActivity(new WfActivityCORBA(orb, __collective,
51                         (org.enhydra.shark.api.client.wfmodel.WfActivity) requester));
52             } else if (requester instanceof WfLinkingRequesterForCORBA) {
53                 req = WfLinkingRequesterForCORBA.getCORBARequester(sharkProc.key());
54             } else {
55                 req = SharkCORBAUtilities.makeWfRequester(new WfRequesterCORBA(orb , __collective, requester));
56             }
57             __collective.__recruit(req);
58             return req;
59         } catch (Exception JavaDoc ex) {
60             throw new BaseException();
61         }
62     }
63
64     /**
65      * Set the requester for this process.
66      */

67     public void set_requester(WfRequester new_value) throws BaseException,
68             CannotChangeRequester {
69         if (new_value == null) throw new CannotChangeRequester("Trying to set external requester which is null!");
70
71         if (new_value instanceof WfActivity) {
72             throw new CannotChangeRequester("Can't change requester to activity requester");
73         }
74
75         try {
76
77             WfLinkingRequesterForCORBA lr = new WfLinkingRequesterForCORBA();
78             lr.setOrb(orb);
79             WfLinkingRequesterForCORBA.setCORBARequester(sharkProc.key(), new_value);
80             sharkProc.set_requester(lr);
81
82         } catch (org.enhydra.shark.api.client.wfmodel.CannotChangeRequester ccr) {
83             throw new CannotChangeRequester();
84         } catch (Exception JavaDoc ex) {
85             throw new BaseException();
86         }
87     }
88
89     /**
90      * Retrieve the no of activities in this process.
91      */

92     public int how_many_step() throws BaseException {
93         try {
94             return sharkProc.how_many_step();
95         } catch (Exception JavaDoc ex) {
96             throw new BaseException();
97         }
98     }
99
100     /**
101      * Retrieve the Iterator of active activities of this process.
102      */

103     public WfActivityIterator get_iterator_step() throws BaseException {
104         try {
105             WfActivityIterator iter = SharkCORBAUtilities.makeWfActivityIterator(new WfActivityIteratorCORBA(orb, __collective,
106                     sharkProc.get_iterator_step()));
107             __collective.__recruit(iter);
108             return iter;
109
110         } catch (Exception JavaDoc ex) {
111             throw new BaseException();
112         }
113
114     }
115
116     /**
117      * Retrieve the List of activities of this process.
118      *
119      * @param max_number High limit of elements in the result set
120      * (0->all).
121      */

122     public WfActivity[] get_sequence_step(int max_number) throws BaseException {
123         try {
124             return SharkCORBAUtilities.makeCORBAActivities(__collective,
125                     sharkProc.get_sequence_step(max_number));
126         } catch (Exception JavaDoc ex) {
127             throw new BaseException();
128         }
129     }
130
131     /**
132      * Check if some activity is a member of this process.
133      *
134      * @return true if the specific activity is a member of this process,
135      * false otherwise.
136      */

137     public boolean is_member_of_step(WfActivity member) throws BaseException {
138         try {
139             WfActivity[] acts = get_sequence_step(0);
140             boolean ret = false;
141             if (acts != null) {
142                 for (int i = 0; i < acts.length; i++) {
143                     WfActivity act = acts[i];
144                     if (act.key().equals(member.key())) {
145                         ret = true;
146                         break;
147                     }
148                 }
149             }
150             return ret;
151         } catch (Exception JavaDoc ex) {
152             throw new BaseException();
153         }
154     }
155
156     /**
157      * Retrieve the WfProcessMgr of this process.
158      */

159     public WfProcessMgr manager() throws BaseException {
160         WfProcessMgr ret = null ;
161         try {
162             ret = SharkCORBAUtilities.makeWfProcessMgr(new WfProcessMgrCORBA(orb, __collective, sharkProc.manager()) );
163         } catch (org.enhydra.shark.api.client.wfbase.BaseException e) {
164             e.printStackTrace();
165             throw new BaseException();
166         }
167         __collective.__recruit(ret);
168         return ret;
169     }
170
171     /**
172      * Retrieve the result for this process.
173      */

174     public NameValue[] result() throws BaseException, ResultNotAvailable {
175         try {
176             return SharkCORBAUtilities.makeCORBANameValueArray(orb,
177                     sharkProc.result());
178         } catch (org.enhydra.shark.api.client.wfmodel.ResultNotAvailable rna) {
179             throw new ResultNotAvailable();
180         } catch (Exception JavaDoc ex) {
181             throw new BaseException();
182         }
183     }
184
185     /**
186      * Starts the process - creates a separate thread.
187      */

188     public void start() throws BaseException, CannotStart, AlreadyRunning {
189         try {
190             sharkProc.start();
191         } catch (org.enhydra.shark.api.client.wfmodel.CannotStart cns) {
192             throw new CannotStart();
193         } catch (org.enhydra.shark.api.client.wfmodel.AlreadyRunning ar) {
194             throw new AlreadyRunning();
195         } catch (Exception JavaDoc ex) {
196             throw new BaseException();
197         }
198     }
199
200     /**
201      * Retrieve the iterator of activities in some specific state.
202      */

203     public WfActivityIterator get_activities_in_state(String JavaDoc state) throws BaseException,
204             InvalidState {
205         try {
206             WfActivityIterator iter = SharkCORBAUtilities.makeWfActivityIterator(new WfActivityIteratorCORBA(orb, __collective,
207                     sharkProc.get_activities_in_state(state)));
208             __collective.__recruit(iter);
209             return iter;
210         } catch (org.enhydra.shark.api.client.wfmodel.InvalidState is) {
211             throw new InvalidState();
212         } catch (Exception JavaDoc ex) {
213             throw new BaseException();
214         }
215     }
216
217     public workflow_stateType workflow_state() throws BaseException {
218         try {
219             return workflow_stateType.from_int(sharkProc.workflow_state()
220                     .value());
221         } catch (Exception JavaDoc ex) {
222             throw new BaseException();
223         }
224     }
225
226     public while_openType while_open() throws BaseException {
227         try {
228             return while_openType.from_int(sharkProc.while_open().value());
229         } catch (Exception JavaDoc ex) {
230             throw new BaseException();
231         }
232     }
233
234     public why_not_runningType why_not_running() throws BaseException {
235         try {
236             return why_not_runningType.from_int(sharkProc.why_not_running()
237                     .value());
238         } catch (Exception JavaDoc ex) {
239             throw new BaseException();
240         }
241     }
242
243     public how_closedType how_closed() throws BaseException {
244         try {
245             return how_closedType.from_int(sharkProc.how_closed().value());
246         } catch (Exception JavaDoc ex) {
247             throw new BaseException();
248         }
249     }
250
251     public String JavaDoc[] valid_states() throws BaseException {
252         try {
253             return sharkProc.valid_states();
254         } catch (Exception JavaDoc ex) {
255             throw new BaseException();
256         }
257     }
258
259     public String JavaDoc state() throws BaseException {
260         try {
261             return sharkProc.state();
262         } catch (Exception JavaDoc ex) {
263             throw new BaseException();
264         }
265     }
266
267     public void change_state(String JavaDoc new_state) throws BaseException,
268             InvalidState,
269             TransitionNotAllowed {
270         try {
271             sharkProc.change_state(new_state);
272         } catch (org.enhydra.shark.api.client.wfmodel.InvalidState is) {
273             throw new InvalidState();
274         } catch (org.enhydra.shark.api.client.wfmodel.TransitionNotAllowed tna) {
275             throw new TransitionNotAllowed();
276         } catch (Exception JavaDoc ex) {
277             throw new BaseException();
278         }
279     }
280
281     public String JavaDoc name() throws BaseException {
282         try {
283             return sharkProc.name();
284         } catch (Exception JavaDoc ex) {
285             throw new BaseException();
286         }
287     }
288
289     public void set_name(String JavaDoc new_value) throws BaseException {
290         try {
291             sharkProc.set_name(new_value);
292         } catch (Exception JavaDoc ex) {
293             throw new BaseException();
294         }
295     }
296
297     public String JavaDoc key() throws BaseException {
298         try {
299             return sharkProc.key();
300         } catch (Exception JavaDoc ex) {
301             throw new BaseException();
302         }
303     }
304
305     public String JavaDoc description() throws BaseException {
306         try {
307             return sharkProc.description();
308         } catch (Exception JavaDoc ex) {
309             throw new BaseException();
310         }
311     }
312
313     public void set_description(String JavaDoc new_value) throws BaseException {
314         try {
315             sharkProc.set_description(new_value);
316         } catch (Exception JavaDoc ex) {
317             throw new BaseException();
318         }
319     }
320
321     public NameValue[] process_context() throws BaseException {
322         try {
323             return SharkCORBAUtilities.makeCORBANameValueArray(orb,
324                     sharkProc.process_context());
325         } catch (Exception JavaDoc ex) {
326             throw new BaseException();
327         }
328     }
329
330     public void set_process_context(NameValue[] new_value) throws BaseException,
331             InvalidData,
332             UpdateNotAllowed {
333         try {
334             sharkProc.set_process_context(SharkCORBAUtilities.makeMap(new_value));
335         } catch (org.enhydra.shark.api.client.wfmodel.InvalidData id) {
336             throw new InvalidData();
337         } catch (org.enhydra.shark.api.client.wfmodel.UpdateNotAllowed una) {
338             throw new UpdateNotAllowed();
339         } catch (Exception JavaDoc ex) {
340             throw new BaseException();
341         }
342     }
343
344     public short priority() throws BaseException {
345         try {
346             return sharkProc.priority();
347         } catch (Exception JavaDoc ex) {
348             throw new BaseException();
349         }
350     }
351
352     public void set_priority(short new_value) throws BaseException {
353         try {
354             sharkProc.set_priority(new_value);
355         } catch (Exception JavaDoc ex) {
356             throw new BaseException();
357         }
358     }
359
360     /**
361      * Resume this process.
362      */

363     public void resume() throws BaseException, CannotResume, NotSuspended {
364         try {
365             sharkProc.resume();
366         } catch (org.enhydra.shark.api.client.wfmodel.CannotResume cnr) {
367             throw new CannotResume();
368         } catch (org.enhydra.shark.api.client.wfmodel.NotSuspended ns) {
369             throw new NotSuspended();
370         } catch (Exception JavaDoc ex) {
371             throw new BaseException();
372         }
373     }
374
375     /**
376      * Suspend this process.
377      */

378     public void suspend() throws BaseException,
379             CannotSuspend,
380             NotRunning,
381             AlreadySuspended {
382         try {
383             sharkProc.suspend();
384         } catch (org.enhydra.shark.api.client.wfmodel.CannotSuspend cns) {
385             throw new CannotSuspend();
386         } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
387             throw new NotRunning();
388         } catch (org.enhydra.shark.api.client.wfmodel.AlreadySuspended as) {
389             throw new AlreadySuspended();
390         } catch (Exception JavaDoc ex) {
391             throw new BaseException();
392         }
393     }
394
395     /**
396      * Terminate this process.
397      */

398     public synchronized void terminate() throws BaseException,
399             CannotStop,
400             NotRunning {
401         try {
402             sharkProc.terminate();
403         } catch (org.enhydra.shark.api.client.wfmodel.CannotStop cns) {
404             throw new CannotStop();
405         } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
406             throw new NotRunning();
407         } catch (Exception JavaDoc ex) {
408             throw new BaseException();
409         }
410     }
411
412     /**
413      * Abort the execution of this process.
414      */

415     public synchronized void abort() throws BaseException,
416             CannotStop,
417             NotRunning {
418         try {
419             sharkProc.abort();
420         } catch (org.enhydra.shark.api.client.wfmodel.CannotStop cns) {
421             throw new CannotStop();
422         } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
423             throw new NotRunning();
424         } catch (Exception JavaDoc ex) {
425             throw new BaseException();
426         }
427     }
428
429     public int how_many_history() throws BaseException, HistoryNotAvailable {
430         try {
431             return sharkProc.how_many_history();
432         } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
433             throw new HistoryNotAvailable();
434         } catch (Exception JavaDoc ex) {
435             throw new BaseException();
436         }
437     }
438
439     /**
440      * Search in the history for specific elements.
441      *
442      * @return Found history elements that meet the search criteria.
443      */

444     public WfEventAuditIterator get_iterator_history(String JavaDoc query,
445                                                      NameValue[] names_in_query) throws BaseException,
446             HistoryNotAvailable {
447         WfEventAuditIterator ret = null;
448         try {
449             ret = SharkCORBAUtilities.makeWfEventAuditIterator(new WfEventAuditIteratorCORBA(orb, __collective, sharkProc.get_iterator_history(query,
450                     SharkCORBAUtilities.makeMap(names_in_query))));
451             __collective.__recruit(ret);
452         } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
453             throw new HistoryNotAvailable();
454         } catch (Exception JavaDoc ex) {
455             throw new BaseException();
456         }
457         return ret;
458     }
459
460     /**
461      * Getter for history sequence.
462      *
463      * @return List of History objects.
464      */

465     public WfEventAudit[] get_sequence_history(int max_number) throws BaseException,
466             HistoryNotAvailable {
467         try {
468             return SharkCORBAUtilities.makeCORBAEventAudits(__collective, sharkProc.get_sequence_history(max_number));
469         } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
470             throw new HistoryNotAvailable();
471         } catch (Exception JavaDoc ex) {
472             throw new BaseException();
473         }
474     }
475
476     /**
477      * Checks if a 'member' is an element of the history.
478      *
479      * @return true if the element of the history, false otherwise.
480      */

481     public boolean is_member_of_history(WfExecutionObject member) throws BaseException {
482         try {
483             boolean ret = false;
484             WfEventAudit[] evs = SharkCORBAUtilities.makeCORBAEventAudits(__collective, sharkProc.get_sequence_history(0));
485             if (evs != null) {
486                 for (int i = 0; i < evs.length; i++) {
487                     WfEventAudit ea = evs[i];
488                     if (member instanceof WfActivity) {
489                         WfActivity act = (WfActivity) member;
490                         if (act.container().key().equals(ea.process_key())
491                                 && act.key().equals(ea.activity_key())) {
492                             ret = true;
493                             break;
494                         }
495                     } else {
496                         if (member.key().equals(ea.process_key())) {
497                             ret = true;
498                             break;
499                         }
500                     }
501                 }
502             }
503             return ret;
504         } catch (Exception JavaDoc ex) {
505             throw new BaseException();
506         }
507     }
508
509     public UtcT last_state_time() throws BaseException {
510         try {
511             org.enhydra.shark.api.client.timebase.UtcT t = sharkProc.last_state_time();
512             return new UtcT(t.time, t.inacclo, t.inacchi, t.tdf);
513         } catch (Exception JavaDoc ex) {
514             throw new BaseException();
515         }
516     }
517
518     /**
519      * It is assumed that there can't be two or more processes having the
520      * same key.
521      */

522     public boolean equals(java.lang.Object JavaDoc obj) {
523         if (!(obj instanceof WfProcess)) return false;
524         WfProcess proc = (WfProcess) obj;
525         try {
526             return proc.key().equals(key());
527         } catch (Exception JavaDoc ex) {
528             return false;
529         }
530     }
531
532     public String JavaDoc toString() {
533         return sharkProc.toString();
534     }
535 }
Popular Tags