KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark.corba;
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
8 /**
9  * WfActivityImpl - Workflow Activity Object implementation
10  *
11  * @author Sasa Bojanic
12  * @version 1.0
13  */

14 public class WfActivityCORBA extends _WfActivityImplBase {
15
16    org.enhydra.shark.api.client.wfmodel.WfActivity sharkAct;
17
18    private Collective __collective;
19
20    /**
21     * Create a new WfActivityImpl
22     */

23    protected WfActivityCORBA(Collective toJoin,
24                              org.enhydra.shark.api.client.wfmodel.WfActivity sharkAct) {
25       __collective = toJoin;
26       toJoin.__recruit(this);
27       this.sharkAct = sharkAct;
28    }
29
30    /**
31     * Retrieve the no. of Assignment objects.
32     *
33     * @throws org.omg.WfBase.BaseException General workflow exception.
34     * @return No. of current assignments.
35     */

36    public int how_many_assignment() throws BaseException {
37       try {
38          return sharkAct.how_many_assignment();
39       } catch (Exception JavaDoc ex) {
40          throw new BaseException();
41       }
42    }
43
44    /**
45     * Retrieve the Iterator of Assignments objects.
46     */

47    public WfAssignmentIterator get_iterator_assignment() throws BaseException {
48       try {
49          return new WfAssignmentIteratorCORBA(__collective,
50                                               sharkAct.get_iterator_assignment());
51       } catch (Exception JavaDoc ex) {
52          throw new BaseException();
53       }
54    }
55
56    /**
57     * Retrieve all assignments of this activity.
58     *
59     * @return array of WfAssignment objects.
60     */

61    public WfAssignment[] get_sequence_assignment(int max_number) throws BaseException {
62       try {
63          return SharkCORBAUtilities.makeCORBAAssignments(__collective,
64                                                          sharkAct.get_sequence_assignment(max_number));
65       } catch (Exception JavaDoc ex) {
66          throw new BaseException();
67       }
68    }
69
70    /**
71     * Check if a specific assignment is a member of this activity.
72     *
73     * @return true if the assignment is a member of this activity.
74     */

75    public boolean is_member_of_assignment(WfAssignment member) throws BaseException {
76       try {
77          String JavaDoc actId = member.activity().key();
78          return actId.equals(sharkAct.key());
79       } catch (Exception JavaDoc ex) {
80          throw new BaseException();
81       }
82    }
83
84    /**
85     * Getter for the process of this activity.
86     */

87    public WfProcess container() throws BaseException {
88       try {
89          return new WfProcessCORBA(__collective, sharkAct.container());
90       } catch (Exception JavaDoc ex) {
91          throw new BaseException();
92       }
93    }
94
95    /**
96     * Retrieve the Result map of this activity.
97     *
98     * @return Map of results from this activity
99     */

100    public NameValue[] result() throws BaseException, ResultNotAvailable {
101       try {
102          return SharkCORBAUtilities.makeCORBANameValueArray(this._orb(),
103                                                             sharkAct.result());
104       } catch (org.enhydra.shark.api.client.wfmodel.ResultNotAvailable rna) {
105          throw new ResultNotAvailable();
106       } catch (Exception JavaDoc ex) {
107          throw new BaseException();
108       }
109    }
110
111    /**
112     * Assign Result for this activity.
113     */

114    public void set_result(NameValue[] results) throws BaseException,
115                                               InvalidData {
116       try {
117          sharkAct.set_result(SharkCORBAUtilities.makeMap(results));
118       } catch (org.enhydra.shark.api.client.wfmodel.InvalidData id) {
119          throw new InvalidData();
120       } catch (Exception JavaDoc ex) {
121          throw new BaseException();
122       }
123    }
124
125    /**
126     * Complete this activity.
127     */

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

283    public void resume() throws BaseException, CannotResume, NotSuspended {
284       try {
285          sharkAct.resume();
286       } catch (org.enhydra.shark.api.client.wfmodel.CannotResume cnr) {
287          throw new CannotResume();
288       } catch (org.enhydra.shark.api.client.wfmodel.NotSuspended ns) {
289          throw new NotSuspended();
290       } catch (Exception JavaDoc ex) {
291          throw new BaseException();
292       }
293    }
294
295    /**
296     * Suspend this process or activity.
297     */

298    public void suspend() throws BaseException,
299                         CannotSuspend,
300                         NotRunning,
301                         AlreadySuspended {
302       try {
303          sharkAct.suspend();
304       } catch (org.enhydra.shark.api.client.wfmodel.CannotSuspend cns) {
305          throw new CannotSuspend();
306       } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
307          throw new NotRunning();
308       } catch (org.enhydra.shark.api.client.wfmodel.AlreadySuspended as) {
309          throw new AlreadySuspended();
310       } catch (Exception JavaDoc ex) {
311          throw new BaseException();
312       }
313    }
314
315    /**
316     * Terminate this process or activity.
317     */

318    public void terminate() throws BaseException, CannotStop, NotRunning {
319       try {
320          sharkAct.terminate();
321       } catch (org.enhydra.shark.api.client.wfmodel.CannotStop cns) {
322          throw new CannotStop();
323       } catch (org.enhydra.shark.api.client.wfmodel.NotRunning nr) {
324          throw new NotRunning();
325       } catch (Exception JavaDoc ex) {
326          throw new BaseException();
327       }
328    }
329
330    /**
331     * Abort the execution of this process or activity.
332     */

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

362    public WfEventAuditIterator get_iterator_history(String JavaDoc query,
363                                                     NameValue[] names_in_query) throws BaseException,
364                                                                                HistoryNotAvailable {
365       try {
366          return new WfEventAuditIteratorCORBA(__collective,
367                                               sharkAct.get_iterator_history(query,
368                                                                             SharkCORBAUtilities.makeMap(names_in_query)));
369       } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
370          throw new HistoryNotAvailable();
371       } catch (Exception JavaDoc ex) {
372          throw new BaseException();
373       }
374    }
375
376    /**
377     * Getter for history sequence.
378     *
379     * @param max_number Maximum number of element in result list.
380     * @return List of History objects.
381     */

382    public WfEventAudit[] get_sequence_history(int max_number) throws BaseException,
383                                                              HistoryNotAvailable {
384       try {
385          return SharkCORBAUtilities.makeCORBAEventAudits(__collective,
386                                                          sharkAct.get_sequence_history(max_number));
387       } catch (org.enhydra.shark.api.client.wfmodel.HistoryNotAvailable hna) {
388          throw new HistoryNotAvailable();
389       } catch (Exception JavaDoc ex) {
390          throw new BaseException();
391       }
392    }
393
394    /**
395     * Predicate to check if a 'member' is an element of the history.
396     *
397     * @return true if the element of the history, false otherwise.
398     */

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

440    public int how_many_performer() throws BaseException {
441       try {
442          return sharkAct.how_many_performer();
443       } catch (Exception JavaDoc ex) {
444          throw new BaseException();
445       }
446    }
447
448    /**
449     * Gets an iterator of processes.
450     */

451    public WfProcessIterator get_iterator_performer() throws BaseException {
452       try {
453          return new WfProcessIteratorCORBA(__collective,
454                                            sharkAct.get_iterator_performer());
455       } catch (Exception JavaDoc ex) {
456          throw new BaseException();
457       }
458    }
459
460    /**
461     * A list of processes
462     *
463     * @return List of WfProcess objects.
464     */

465    public WfProcess[] get_sequence_performer(int max_number) throws BaseException {
466       try {
467          return SharkCORBAUtilities.makeCORBAProcesses(__collective,
468                                                        sharkAct.get_sequence_performer(max_number));
469       } catch (Exception JavaDoc ex) {
470          throw new BaseException();
471       }
472    }
473
474    /**
475     * Checks if a WfProcess is associated with this requester object
476     *
477     * @return true if the process is found.
478     */

479    public boolean is_member_of_performer(WfProcess member) throws BaseException {
480       try {
481          boolean ret = false;
482          WfProcess[] perfs = SharkCORBAUtilities.makeCORBAProcesses(__collective,
483                                                                     sharkAct.get_sequence_performer(0));
484          if (perfs != null) {
485             for (int i = 0; i < perfs.length; i++) {
486                WfProcess perf = perfs[i];
487                if (perf.key().equals(member.key())) {
488                   ret = true;
489                   break;
490                }
491             }
492          }
493          return ret;
494       } catch (Exception JavaDoc ex) {
495          throw new BaseException();
496       }
497    }
498
499    public void receive_event(WfEventAudit event) throws BaseException,
500                                                 InvalidPerformer {}
501
502    /**
503     * It is assumed that there can't be two or more activities having
504     * the same key.
505     */

506    public boolean equals(java.lang.Object JavaDoc obj) {
507       if (!(obj instanceof WfActivity)) return false;
508       WfActivity act = (WfActivity) obj;
509       try {
510          return act.key().equals(key());
511       } catch (Exception JavaDoc ex) {
512          return false;
513       }
514    }
515
516    public String JavaDoc toString() {
517       return sharkAct.toString();
518    }
519
520 }
Popular Tags