KickJava   Java API By Example, From Geeks To Geeks.

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


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.enhydra.shark.corba.poa.Collective;
9 import org.enhydra.shark.corba.poa.SharkCORBAUtilities;
10
11 /**
12  * WfActivityImpl - Workflow Activity Object implementation
13  *
14  * @author David Forslund
15  * @version 1.0
16  */

17 public class WfActivityCORBA extends WfActivityPOA {
18
19    org.enhydra.shark.api.client.wfmodel.WfActivity sharkAct;
20
21    private Collective __collective;
22   private ORB JavaDoc orb;
23
24    /**
25     * Create a new WfActivityImpl
26     */

27    protected WfActivityCORBA(ORB JavaDoc orb, Collective toJoin,
28                              org.enhydra.shark.api.client.wfmodel.WfActivity sharkAct) {
29       __collective = toJoin;
30       this.orb = orb;
31       //toJoin.__recruit(this);
32
this.sharkAct = sharkAct;
33    }
34
35    /**
36     * Retrieve the no. of Assignment objects.
37     *
38     * @throws BaseException General workflow exception.
39     * @return No. of current assignments.
40     */

41    public int how_many_assignment() throws BaseException {
42       try {
43          return sharkAct.how_many_assignment();
44       } catch (Exception JavaDoc ex) {
45          throw new BaseException();
46       }
47    }
48
49    /**
50     * Retrieve the Iterator of Assignments objects.
51     */

52    public WfAssignmentIterator get_iterator_assignment() throws BaseException {
53       try {
54          WfAssignmentIterator iter = SharkCORBAUtilities.makeWfAssignmentIterator(new WfAssignmentIteratorCORBA(orb, __collective,
55                                               sharkAct.get_iterator_assignment()));
56           __collective.__recruit(iter);
57           return iter;
58       } catch (Exception JavaDoc ex) {
59          throw new BaseException();
60       }
61    }
62
63    /**
64     * Retrieve all assignments of this activity.
65     *
66     * @return array of WfAssignment objects.
67     */

68    public WfAssignment[] get_sequence_assignment(int max_number) throws BaseException {
69       try {
70          return SharkCORBAUtilities.makeCORBAAssignments( __collective,
71                                                          sharkAct.get_sequence_assignment(max_number));
72       } catch (Exception JavaDoc ex) {
73          throw new BaseException();
74       }
75    }
76
77    /**
78     * Check if a specific assignment is a member of this activity.
79     *
80     * @return true if the assignment is a member of this activity.
81     */

82    public boolean is_member_of_assignment(WfAssignment member) throws BaseException {
83       try {
84          String JavaDoc actId = member.activity().key();
85          return actId.equals(sharkAct.key());
86       } catch (Exception JavaDoc ex) {
87          throw new BaseException();
88       }
89    }
90
91    /**
92     * Getter for the process of this activity.
93     */

94    public WfProcess container() throws BaseException {
95       try {
96          WfProcess proc = SharkCORBAUtilities.makeWfProcess(new WfProcessCORBA(orb, __collective, sharkAct.container()));
97         __collective.__recruit(proc);
98           return proc;
99       } catch (Exception JavaDoc ex) {
100          throw new BaseException();
101       }
102    }
103
104    /**
105     * Retrieve the Result map of this activity.
106     *
107     * @return Map of results from this activity
108     */

109    public NameValue[] result() throws BaseException, ResultNotAvailable {
110       try {
111          return SharkCORBAUtilities.makeCORBANameValueArray(orb,
112                                                             sharkAct.result());
113       } catch (org.enhydra.shark.api.client.wfmodel.ResultNotAvailable rna) {
114          throw new ResultNotAvailable();
115       } catch (Exception JavaDoc ex) {
116          throw new BaseException();
117       }
118    }
119
120    /**
121     * Assign Result for this activity.
122     */

123    public void set_result(NameValue[] results) throws BaseException,
124                                               InvalidData {
125       try {
126          sharkAct.set_result(SharkCORBAUtilities.makeMap(results));
127       } catch (org.enhydra.shark.api.client.wfmodel.InvalidData id) {
128          throw new InvalidData();
129       } catch (Exception JavaDoc ex) {
130          throw new BaseException();
131       }
132    }
133
134    /**
135     * Complete this activity.
136     */

137    public void complete() throws BaseException, CannotComplete {
138       try {
139          sharkAct.complete();
140       } catch (org.enhydra.shark.api.client.wfmodel.CannotComplete cnc) {
141          throw new CannotComplete();
142       } catch (Exception JavaDoc ex) {
143          throw new BaseException();
144       }
145    }
146
147    public workflow_stateType workflow_state() throws BaseException {
148       try {
149          return workflow_stateType.from_int(sharkAct.workflow_state().value());
150       } catch (Exception JavaDoc ex) {
151          throw new BaseException();
152       }
153    }
154
155    public while_openType while_open() throws BaseException {
156       try {
157          return while_openType.from_int(sharkAct.while_open().value());
158       } catch (Exception JavaDoc ex) {
159          throw new BaseException();
160       }
161    }
162
163    public why_not_runningType why_not_running() throws BaseException {
164       try {
165          return why_not_runningType.from_int(sharkAct.why_not_running()
166             .value());
167       } catch (Exception JavaDoc ex) {
168          throw new BaseException();
169       }
170    }
171
172    public how_closedType how_closed() throws BaseException {
173       try {
174          return how_closedType.from_int(sharkAct.how_closed().value());
175       } catch (Exception JavaDoc ex) {
176          throw new BaseException();
177       }
178    }
179
180    public String JavaDoc[] valid_states() throws BaseException {
181       try {
182          return sharkAct.valid_states();
183       } catch (Exception JavaDoc ex) {
184          throw new BaseException();
185       }
186    }
187
188    public String JavaDoc state() throws BaseException {
189       try {
190          return sharkAct.state();
191       } catch (Exception JavaDoc ex) {
192          throw new BaseException();
193       }
194    }
195
196    public void change_state(String JavaDoc new_state) throws BaseException,
197                                              InvalidState,
198                                              TransitionNotAllowed {
199       try {
200          sharkAct.change_state(new_state);
201       } catch (org.enhydra.shark.api.client.wfmodel.InvalidState is) {
202          throw new InvalidState();
203       } catch (org.enhydra.shark.api.client.wfmodel.TransitionNotAllowed tna) {
204          throw new TransitionNotAllowed();
205       } catch (Exception JavaDoc ex) {
206          throw new BaseException();
207       }
208    }
209
210    public String JavaDoc name() throws BaseException {
211       try {
212          return sharkAct.name();
213       } catch (Exception JavaDoc ex) {
214          throw new BaseException();
215       }
216    }
217
218    public void set_name(String JavaDoc new_value) throws BaseException {
219       try {
220          sharkAct.set_name(new_value);
221       } catch (Exception JavaDoc ex) {
222          throw new BaseException();
223       }
224    }
225
226    public String JavaDoc key() throws BaseException {
227       try {
228          return sharkAct.key();
229       } catch (Exception JavaDoc ex) {
230          throw new BaseException();
231       }
232    }
233
234    public String JavaDoc description() throws BaseException {
235       try {
236          return sharkAct.description();
237       } catch (Exception JavaDoc ex) {
238          throw new BaseException();
239       }
240    }
241
242    public void set_description(String JavaDoc new_value) throws BaseException {
243       try {
244          sharkAct.set_description(new_value);
245       } catch (Exception JavaDoc ex) {
246          throw new BaseException();
247       }
248    }
249
250    public NameValue[] process_context() throws BaseException {
251       try {
252          return SharkCORBAUtilities.makeCORBANameValueArray(orb,
253                                                             sharkAct.process_context());
254       } catch (Exception JavaDoc ex) {
255          throw new BaseException();
256       }
257    }
258
259    public void set_process_context(NameValue[] new_value) throws BaseException,
260                                                          InvalidData,
261                                                          UpdateNotAllowed {
262       try {
263          sharkAct.set_process_context(SharkCORBAUtilities.makeMap(new_value));
264       } catch (org.enhydra.shark.api.client.wfmodel.InvalidData id) {
265          throw new InvalidData();
266       } catch (org.enhydra.shark.api.client.wfmodel.UpdateNotAllowed una) {
267          throw new UpdateNotAllowed();
268       } catch (Exception JavaDoc ex) {
269          throw new BaseException();
270       }
271    }
272
273    public short priority() throws BaseException {
274       try {
275          return sharkAct.priority();
276       } catch (Exception JavaDoc ex) {
277          throw new BaseException();
278       }
279    }
280
281    public void set_priority(short new_value) throws BaseException {
282       try {
283          sharkAct.set_priority(new_value);
284       } catch (Exception JavaDoc ex) {
285          throw new BaseException();
286       }
287    }
288
289    /**
290     * Resume this process or activity.
291     */

292    public void resume() throws BaseException, CannotResume, NotSuspended {
293       try {
294          sharkAct.resume();
295       } catch (org.enhydra.shark.api.client.wfmodel.CannotResume cnr) {
296          throw new CannotResume();
297       } catch (org.enhydra.shark.api.client.wfmodel.NotSuspended ns) {
298          throw new NotSuspended();
299       } catch (Exception JavaDoc ex) {
300          throw new BaseException();
301       }
302    }
303
304    /**
305     * Suspend this process or activity.
306     */

307    public void suspend() throws BaseException,
308                         CannotSuspend,
309                         NotRunning,
310                         AlreadySuspended {
311       try {
312          sharkAct.suspend();
313       } catch (org.enhydra.shark.api.client.wfmodel.CannotSuspend cns) {
314          throw new CannotSuspend();
315       } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
316          throw new NotRunning();
317       } catch (org.enhydra.shark.api.client.wfmodel.AlreadySuspended as) {
318          throw new AlreadySuspended();
319       } catch (Exception JavaDoc ex) {
320          throw new BaseException();
321       }
322    }
323
324    /**
325     * Terminate this process or activity.
326     */

327    public void terminate() throws BaseException, CannotStop, NotRunning {
328       try {
329          sharkAct.terminate();
330       } catch (org.enhydra.shark.api.client.wfmodel.CannotStop cns) {
331          throw new CannotStop();
332       } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
333          throw new NotRunning();
334       } catch (Exception JavaDoc ex) {
335          throw new BaseException();
336       }
337    }
338
339    /**
340     * Abort the execution of this process or activity.
341     */

342    public void abort() throws BaseException, CannotStop, NotRunning {
343       try {
344          sharkAct.abort();
345       } catch (org.enhydra.shark.api.client.wfmodel.CannotStop cns) {
346          throw new CannotStop();
347       } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
348          throw new NotRunning();
349       } catch (Exception JavaDoc ex) {
350          throw new BaseException();
351       }
352    }
353
354    public int how_many_history() throws BaseException, HistoryNotAvailable {
355       try {
356          return sharkAct.how_many_history();
357       } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
358          throw new HistoryNotAvailable();
359       } catch (Exception JavaDoc ex) {
360          throw new BaseException();
361       }
362    }
363
364    /**
365     * Search in the history for specific elements.
366     *
367     * @param query Search criteria.
368     * @param names_in_query elements to search.
369     * @return Found history elements that meet the search criteria.
370     */

371    public WfEventAuditIterator get_iterator_history(String JavaDoc query,
372                                                     NameValue[] names_in_query) throws BaseException,
373                                                                                HistoryNotAvailable {
374       try {
375          WfEventAuditIterator iter = SharkCORBAUtilities.makeWfEventAuditIterator(new WfEventAuditIteratorCORBA(orb, __collective,
376                                               sharkAct.get_iterator_history(query,
377                                                                             SharkCORBAUtilities.makeMap(names_in_query))));
378          __collective.__recruit(iter);
379           return iter;
380       } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
381          throw new HistoryNotAvailable();
382       } catch (Exception JavaDoc ex) {
383          throw new BaseException();
384       }
385    }
386
387    /**
388     * Getter for history sequence.
389     *
390     * @param max_number Maximum number of element in result list.
391     * @return List of History objects.
392     */

393    public WfEventAudit[] get_sequence_history(int max_number) throws BaseException,
394                                                              HistoryNotAvailable {
395       try {
396          return SharkCORBAUtilities.makeCORBAEventAudits(__collective,
397                                                          sharkAct.get_sequence_history(max_number));
398       } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
399          throw new HistoryNotAvailable();
400       } catch (Exception JavaDoc ex) {
401          throw new BaseException();
402       }
403    }
404
405    /**
406     * Predicate to check if a 'member' is an element of the history.
407     *
408     * @return true if the element of the history, false otherwise.
409     */

410    public boolean is_member_of_history(WfExecutionObject member) throws BaseException {
411       try {
412          boolean ret = false;
413          WfEventAudit[] evs = SharkCORBAUtilities.makeCORBAEventAudits(__collective,
414                                                                        sharkAct.get_sequence_history(0));
415          if (evs != null) {
416             for (int i = 0; i < evs.length; i++) {
417                WfEventAudit ea = evs[i];
418                if (member instanceof WfActivity) {
419                   WfActivity act = (WfActivity) member;
420                   if (act.container().key().equals(ea.process_key())
421                       && act.key().equals(ea.activity_key())) {
422                      ret = true;
423                      break;
424                   }
425                } else {
426                   if (member.key().equals(ea.process_key())) {
427                      ret = true;
428                      break;
429                   }
430                }
431             }
432          }
433          return ret;
434       } catch (Exception JavaDoc ex) {
435          throw new BaseException();
436       }
437    }
438
439    public UtcT last_state_time() throws BaseException {
440       try {
441          org.enhydra.shark.api.client.timebase.UtcT t = sharkAct.last_state_time();
442          return new UtcT(t.time, t.inacclo, t.inacchi, t.tdf);
443       } catch (Exception JavaDoc ex) {
444          throw new BaseException();
445       }
446    }
447
448    /**
449     * Gets the number of processes.
450     */

451    public int how_many_performer() throws BaseException {
452       try {
453          return sharkAct.how_many_performer();
454       } catch (Exception JavaDoc ex) {
455          throw new BaseException();
456       }
457    }
458
459    /**
460     * Gets an iterator of processes.
461     */

462    public WfProcessIterator get_iterator_performer() throws BaseException {
463       try {
464          WfProcessIterator iter = SharkCORBAUtilities.makeWfProcessIterator(new WfProcessIteratorCORBA(orb, __collective,
465                                            sharkAct.get_iterator_performer()));
466           __collective.__recruit(iter);
467           return iter;
468
469       } catch (Exception JavaDoc ex) {
470          throw new BaseException();
471       }
472    }
473
474    /**
475     * A list of processes
476     *
477     * @return List of WfProcess objects.
478     */

479    public WfProcess[] get_sequence_performer(int max_number) throws BaseException {
480       try {
481          return SharkCORBAUtilities.makeCORBAProcesses(__collective,
482                                                        sharkAct.get_sequence_performer(max_number));
483       } catch (Exception JavaDoc ex) {
484          throw new BaseException();
485       }
486    }
487
488    /**
489     * Checks if a WfProcess is associated with this requester object
490     *
491     * @return true if the process is found.
492     */

493    public boolean is_member_of_performer(WfProcess member) throws BaseException {
494       try {
495          boolean ret = false;
496          WfProcess[] perfs = SharkCORBAUtilities.makeCORBAProcesses(__collective,
497                                                                     sharkAct.get_sequence_performer(0));
498          if (perfs != null) {
499             for (int i = 0; i < perfs.length; i++) {
500                WfProcess perf = perfs[i];
501                if (perf.key().equals(member.key())) {
502                   ret = true;
503                   break;
504                }
505             }
506          }
507          return ret;
508       } catch (Exception JavaDoc ex) {
509          throw new BaseException();
510       }
511    }
512
513    public void receive_event(WfEventAudit event) throws BaseException,
514                                                 InvalidPerformer {}
515
516    /**
517     * It is assumed that there can't be two or more activities having
518     * the same key.
519     */

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