KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > WfActivityWrapper


1 package org.enhydra.shark;
2
3 import org.enhydra.shark.api.client.wfmodel.*;
4
5 import java.util.Iterator JavaDoc;
6 import java.util.List JavaDoc;
7 import java.util.Map JavaDoc;
8 import org.enhydra.shark.api.RootException;
9 import org.enhydra.shark.api.SharkTransaction;
10 import org.enhydra.shark.api.client.timebase.UtcT;
11 import org.enhydra.shark.api.client.wfbase.BaseException;
12 import org.enhydra.shark.api.common.SharkConstants;
13 import org.enhydra.shark.api.internal.eventaudit.EventAuditManagerInterface;
14 import org.enhydra.shark.api.internal.security.SecurityManager;
15 import org.enhydra.shark.api.internal.working.WfActivityInternal;
16
17 /**
18  * WfActivityWrapper - Workflow Activity Object implementation
19  * @author Sasa Bojanic
20  * @author Vladimir Puskas
21  */

22 public class WfActivityWrapper implements WfActivity {
23
24    private String JavaDoc userAuth;
25    private String JavaDoc mgrName;
26    private String JavaDoc processId;
27    private String JavaDoc id;
28
29    /**
30     * Create a new WfActivityWrapper
31     */

32    protected WfActivityWrapper(String JavaDoc userAuth,String JavaDoc mgrName,String JavaDoc processId,String JavaDoc id) {
33       this.userAuth=userAuth;
34       this.mgrName=mgrName;
35       this.processId=processId;
36       this.id = id;
37    }
38
39    /**
40     * Retrieve the no. of Assignment objects.
41     * @throws BaseException General workflow exception.
42     * @return No. of current assignments.
43     */

44    public int how_many_assignment () throws BaseException {
45       int ret = -1;
46       SharkTransaction t = null;
47       try {
48          t = SharkUtilities.createTransaction();
49          ret = how_many_assignment(t);
50          //SharkUtilities.commitTransaction(t);
51
} catch (RootException e) {
52          //SharkUtilities.rollbackTransaction(t);
53
SharkUtilities.emptyCaches(t);
54          if (e instanceof BaseException)
55             throw (BaseException)e;
56          else
57             throw new BaseException(e);
58       } finally {
59          SharkUtilities.releaseTransaction(t);
60       }
61       return ret;
62    }
63
64    public int how_many_assignment (SharkTransaction t) throws BaseException {
65       try {
66          SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
67          if (sm!=null) {
68             WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
69             sm.check_activity_how_many_assignment(t,
70                                                   processId,
71                                                   id,
72                                                   userAuth,
73                                                   actInternal.container(t).requester(t).getResourceRequesterUsername(t),
74                                                   actInternal.getResourceUsername(t),
75                                                   actInternal.getAssignmentResourceIds(t));
76          }
77
78          return SharkEngineManager
79             .getInstance()
80             .getInstancePersistenceManager()
81             .getAllValidAssignmentsForActivity(id,t).size();
82       } catch (Exception JavaDoc e) {
83          throw new BaseException(e);
84       }
85
86    }
87
88    /**
89     * Retrieve the Iterator of Assignments objects.
90     */

91    public WfAssignmentIterator get_iterator_assignment () throws BaseException {
92       WfAssignmentIterator ret = null;
93       SharkTransaction t = null;
94       try {
95          t = SharkUtilities.createTransaction();
96          ret = get_iterator_assignment(t);
97          //SharkUtilities.commitTransaction(t);
98
} catch (RootException e) {
99          //SharkUtilities.rollbackTransaction(t);
100
SharkUtilities.emptyCaches(t);
101          if (e instanceof BaseException)
102             throw (BaseException)e;
103          else
104             throw new BaseException(e);
105       } finally {
106          SharkUtilities.releaseTransaction(t);
107       }
108       return ret;
109    }
110
111    public WfAssignmentIterator get_iterator_assignment (SharkTransaction t) throws BaseException {
112       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
113       if (sm!=null) {
114          WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
115          try {
116             sm.check_activity_get_iterator_assignment(t,
117                                                       processId,
118                                                       id,
119                                                       userAuth,
120                                                       actInternal.container(t).requester(t).getResourceRequesterUsername(t),
121                                                       actInternal.getResourceUsername(t),
122                                                       actInternal.getAssignmentResourceIds(t));
123          } catch (Exception JavaDoc ex) {
124             throw new BaseException(ex);
125          }
126       }
127       return SharkEngineManager.getInstance().getObjectFactory().createAssignmentIteratorWrapper(t,userAuth,processId,id);
128    }
129
130    /**
131     * Retrieve all assignments of this activity.
132     * @return array of WfAssignment objects.
133     */

134    public WfAssignment[] get_sequence_assignment (int max_number) throws BaseException {
135       WfAssignment[] ret = null;
136       SharkTransaction t = null;
137       try {
138          t = SharkUtilities.createTransaction();
139          ret = get_sequence_assignment(t,max_number);
140          //SharkUtilities.commitTransaction(t);
141
} catch (RootException e) {
142          //SharkUtilities.rollbackTransaction(t);
143
SharkUtilities.emptyCaches(t);
144          if (e instanceof BaseException)
145             throw (BaseException)e;
146          else
147             throw new BaseException(e);
148       } finally {
149          SharkUtilities.releaseTransaction(t);
150       }
151       return ret;
152    }
153
154    public WfAssignment[] get_sequence_assignment (SharkTransaction t,int max_number) throws BaseException {
155       try {
156          SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
157          if (sm!=null) {
158             WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
159             sm.check_activity_get_sequence_assignment(t,
160                                                       processId,
161                                                       id,
162                                                       userAuth,
163                                                       actInternal.container(t).requester(t).getResourceRequesterUsername(t),
164                                                       actInternal.getResourceUsername(t),
165                                                       actInternal.getAssignmentResourceIds(t));
166          }
167          List JavaDoc l=SharkUtilities.createAssignmentWrappers(t,userAuth,processId,id);
168          if (max_number > l.size() || max_number<=0) {
169             max_number = l.size();
170          }
171          WfAssignment[] ret = new WfAssignment[l.size()];
172          l.subList(0, max_number).toArray(ret);
173          return ret;
174       } catch (Exception JavaDoc ex) {
175          throw new BaseException(ex);
176       }
177    }
178
179    /**
180     * Check if a specific assignment is a member of this activity.
181     * @return true if the assignment is a member of this activity.
182     */

183    public boolean is_member_of_assignment (WfAssignment member) throws BaseException {
184       boolean ret = false;
185       SharkTransaction t = null;
186       try {
187          t = SharkUtilities.createTransaction();
188          ret = is_member_of_assignment(t,member);
189          //SharkUtilities.commitTransaction(t);
190
} catch (RootException e) {
191          //SharkUtilities.rollbackTransaction(t);
192
SharkUtilities.emptyCaches(t);
193          if (e instanceof BaseException)
194             throw (BaseException)e;
195          else
196             throw new BaseException(e);
197       } finally {
198          SharkUtilities.releaseTransaction(t);
199       }
200       return ret;
201    }
202
203    public boolean is_member_of_assignment (SharkTransaction t,WfAssignment member) throws BaseException {
204       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
205       if (sm!=null) {
206          WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
207          try {
208             sm.check_activity_is_member_of_assignment(t,
209                                                       processId,
210                                                       id,
211                                                       userAuth,
212                                                       actInternal.container(t).requester(t).getResourceRequesterUsername(t),
213                                                       actInternal.getResourceUsername(t),
214                                                       actInternal.getAssignmentResourceIds(t));
215          } catch (Exception JavaDoc ex) {
216             throw new BaseException(ex);
217          }
218       }
219       String JavaDoc actId=member.activity(t).key(t);
220       return actId.equals(id);
221    }
222
223    /**
224     * Getter for the process of this activity.
225     */

226    public WfProcess container () throws BaseException {
227       WfProcess ret = null;
228       SharkTransaction t = null;
229       try {
230          t = SharkUtilities.createTransaction();
231          ret = container(t);
232          //SharkUtilities.commitTransaction(t);
233
} catch (RootException e) {
234          //SharkUtilities.rollbackTransaction(t);
235
SharkUtilities.emptyCaches(t);
236          if (e instanceof BaseException)
237             throw (BaseException)e;
238          else
239             throw new BaseException(e);
240       } finally {
241          SharkUtilities.releaseTransaction(t);
242       }
243       return ret;
244    }
245
246    public WfProcess container (SharkTransaction t) throws BaseException {
247       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
248       if (sm!=null) {
249          WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
250          try {
251             sm.check_activity_container(t,
252                                         processId,
253                                         id,
254                                         userAuth,
255                                         actInternal.container(t).requester(t).getResourceRequesterUsername(t),
256                                         actInternal.getResourceUsername(t),
257                                         actInternal.getAssignmentResourceIds(t));
258          } catch (Exception JavaDoc ex) {
259             throw new BaseException(ex);
260          }
261       }
262       return SharkEngineManager.getInstance().getObjectFactory().createProcessWrapper(userAuth,mgrName,processId);
263    }
264
265    /**
266     * Retrieve the Result map of this activity.
267     * @return Map of results from this activity
268     */

269    public Map JavaDoc result () throws BaseException, ResultNotAvailable {
270       Map JavaDoc ret = null;
271       SharkTransaction t = null;
272       try {
273          t = SharkUtilities.createTransaction();
274          ret = result(t);
275          //SharkUtilities.commitTransaction(t);
276
} catch (RootException e) {
277          //SharkUtilities.rollbackTransaction(t);
278
SharkUtilities.emptyCaches(t);
279          if (e instanceof ResultNotAvailable)
280             throw (ResultNotAvailable)e;
281          else if (e instanceof BaseException)
282             throw (BaseException)e;
283          else
284             throw new BaseException(e);
285       } finally {
286          SharkUtilities.releaseTransaction(t);
287       }
288       return ret;
289    }
290
291    public Map JavaDoc result (SharkTransaction t) throws BaseException, ResultNotAvailable {
292       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
293       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
294       if (sm!=null) {
295          try {
296             sm.check_activity_result(t,
297                                      processId,
298                                      id,
299                                      userAuth,
300                                      actInternal.container(t).requester(t).getResourceRequesterUsername(t),
301                                      actInternal.getResourceUsername(t),
302                                      actInternal.getAssignmentResourceIds(t));
303          } catch (Exception JavaDoc ex) {
304             throw new BaseException(ex);
305          }
306       }
307
308       return actInternal.result(t);
309    }
310
311    /**
312     * Assign Result for this activity.
313     */

314    public void set_result (Map JavaDoc results) throws BaseException, InvalidData {
315       SharkTransaction t = null;
316       try {
317          t = SharkUtilities.createTransaction();
318          set_result(t,results);
319          SharkUtilities.commitTransaction(t);
320       } catch (RootException e) {
321          SharkUtilities.rollbackTransaction(t,e);
322          if (e instanceof InvalidData)
323             throw (InvalidData)e;
324          else if (e instanceof BaseException)
325             throw (BaseException)e;
326          else
327             throw new BaseException(e);
328       } finally {
329          SharkUtilities.releaseTransaction(t);
330       }
331    }
332
333    public void set_result (SharkTransaction t,Map JavaDoc results) throws BaseException, InvalidData {
334       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
335       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
336       if (sm!=null) {
337          try {
338             sm.check_activity_set_result(t,
339                                          processId,
340                                          id,
341                                          userAuth,
342                                          actInternal.container(t).requester(t).getResourceRequesterUsername(t),
343                                          actInternal.getResourceUsername(t),
344                                          actInternal.getAssignmentResourceIds(t));
345          } catch (Exception JavaDoc ex) {
346             throw new BaseException(ex);
347          }
348       }
349       actInternal.set_result(t,results);
350    }
351
352    /**
353     * Complete this activity.
354     */

355    public void complete () throws BaseException, CannotComplete {
356       SharkTransaction t = null;
357       try {
358          t = SharkUtilities.createTransaction();
359          complete(t);
360          SharkUtilities.commitTransaction(t);
361       } catch (RootException e) {
362          //e.printStackTrace();
363
SharkUtilities.rollbackTransaction(t,e);
364          if (e instanceof CannotComplete)
365             throw (CannotComplete)e;
366          else if (e instanceof BaseException)
367             throw (BaseException)e;
368          else
369             throw new BaseException(e);
370       } finally {
371          SharkUtilities.releaseTransaction(t);
372       }
373    }
374
375    public void complete (SharkTransaction t) throws BaseException, CannotComplete {
376       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
377       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
378       if (sm!=null) {
379          try {
380             sm.check_activity_complete(t,
381                                        processId,
382                                        id,
383                                        userAuth,
384                                        actInternal.container(t).requester(t).getResourceRequesterUsername(t),
385                                        actInternal.getResourceUsername(t),
386                                        actInternal.getAssignmentResourceIds(t));
387          } catch (Exception JavaDoc ex) {
388             throw new BaseException(ex);
389          }
390       }
391       actInternal.complete(t);
392    }
393
394    /**
395     * Method workflow_state
396     *
397     * @return a workflow_stateType
398     *
399     * @exception BaseException
400     */

401    public workflow_stateType workflow_state () throws BaseException {
402       workflow_stateType ret = null;
403       SharkTransaction t = null;
404       try {
405          t = SharkUtilities.createTransaction();
406          ret = workflow_state(t);
407          //SharkUtilities.commitTransaction(t);
408
} catch (RootException e) {
409          //SharkUtilities.rollbackTransaction(t);
410
SharkUtilities.emptyCaches(t);
411          if (e instanceof BaseException)
412             throw (BaseException)e;
413          else
414             throw new BaseException(e);
415       } finally {
416          SharkUtilities.releaseTransaction(t);
417       }
418       return ret;
419    }
420
421    /**
422     * Method workflow_state
423     *
424     * @param t a SharkTransaction
425     *
426     * @return a workflow_stateType
427     *
428     * @exception BaseException
429     */

430    public workflow_stateType workflow_state (SharkTransaction t) throws BaseException {
431       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
432       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
433       if (sm!=null) {
434          try {
435             sm.check_activity_workflow_state(t,
436                                              processId,
437                                              id,
438                                              userAuth,
439                                              actInternal.container(t).requester(t).getResourceRequesterUsername(t),
440                                              actInternal.getResourceUsername(t),
441                                              actInternal.getAssignmentResourceIds(t));
442          } catch (Exception JavaDoc ex) {
443             throw new BaseException(ex);
444          }
445       }
446
447       String JavaDoc state=actInternal.state(t);
448
449       if (state.startsWith(SharkConstants.STATEPREFIX_CLOSED)) {
450          return workflow_stateType.closed;
451       } else {
452          return workflow_stateType.open;
453       }
454    }
455
456    public while_openType while_open () throws BaseException {
457       while_openType ret = null;
458       SharkTransaction t = null;
459       try {
460          t = SharkUtilities.createTransaction();
461          ret = while_open(t);
462          //SharkUtilities.commitTransaction(t);
463
} catch (RootException e) {
464          //SharkUtilities.rollbackTransaction(t);
465
SharkUtilities.emptyCaches(t);
466          if (e instanceof BaseException)
467             throw (BaseException)e;
468          else
469             throw new BaseException(e);
470       } finally {
471          SharkUtilities.releaseTransaction(t);
472       }
473       return ret;
474    }
475
476    /**
477     * Method while_open
478     *
479     * @param t a SharkTransaction
480     *
481     * @return a while_openType
482     *
483     * @exception BaseException
484     */

485    public while_openType while_open (SharkTransaction t) throws BaseException {
486       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
487       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
488       if (sm!=null) {
489          try {
490             sm.check_activity_while_open(t,
491                                          processId,
492                                          id,
493                                          userAuth,
494                                          actInternal.container(t).requester(t).getResourceRequesterUsername(t),
495                                          actInternal.getResourceUsername(t),
496                                          actInternal.getAssignmentResourceIds(t));
497          } catch (Exception JavaDoc ex) {
498             throw new BaseException(ex);
499          }
500       }
501
502       String JavaDoc state=actInternal.state(t);
503
504       if (state.equals(SharkConstants.STATE_OPEN_RUNNING)) {
505          return while_openType.running;
506       } else {
507          return while_openType.not_running;
508       }
509    }
510
511    /**
512     * Method why_not_running
513     *
514     * @return a why_not_runningType
515     *
516     * @exception BaseException
517     */

518    public why_not_runningType why_not_running () throws BaseException {
519       why_not_runningType ret = null;
520       SharkTransaction t = null;
521       try {
522          t = SharkUtilities.createTransaction();
523          ret = why_not_running(t);
524          //SharkUtilities.commitTransaction(t);
525
} catch (RootException e) {
526          //SharkUtilities.rollbackTransaction(t);
527
SharkUtilities.emptyCaches(t);
528          if (e instanceof BaseException)
529             throw (BaseException)e;
530          else
531             throw new BaseException(e);
532       } finally {
533          SharkUtilities.releaseTransaction(t);
534       }
535       return ret;
536    }
537
538    /**
539     * Method why_not_running
540     *
541     * @param t a SharkTransaction
542     *
543     * @return a why_not_runningType
544     *
545     * @exception BaseException
546     */

547    public why_not_runningType why_not_running (SharkTransaction t) throws BaseException {
548       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
549       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
550       if (sm!=null) {
551          try {
552             sm.check_activity_why_not_running(t,
553                                               processId,
554                                               id,
555                                               userAuth,
556                                               actInternal.container(t).requester(t).getResourceRequesterUsername(t),
557                                               actInternal.getResourceUsername(t),
558                                               actInternal.getAssignmentResourceIds(t));
559          } catch (Exception JavaDoc ex) {
560             throw new BaseException(ex);
561          }
562       }
563
564       String JavaDoc state=actInternal.state(t);
565
566       if (state.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED)) {
567          return why_not_runningType.suspended;
568       } else {
569          return why_not_runningType.not_started;
570       }
571    }
572
573    /**
574     * Method how_closed
575     *
576     * @return a how_closedType
577     *
578     * @exception BaseException
579     */

580    public how_closedType how_closed () throws BaseException {
581       how_closedType ret = null;
582       SharkTransaction t = null;
583       try {
584          t = SharkUtilities.createTransaction();
585          ret = how_closed(t);
586          //SharkUtilities.commitTransaction(t);
587
} catch (RootException e) {
588          //SharkUtilities.rollbackTransaction(t);
589
SharkUtilities.emptyCaches(t);
590          if (e instanceof BaseException)
591             throw (BaseException)e;
592          else
593             throw new BaseException(e);
594       } finally {
595          SharkUtilities.releaseTransaction(t);
596       }
597       return ret;
598    }
599
600    /**
601     * Method how_closed
602     *
603     * @param t a SharkTransaction
604     *
605     * @return a how_closedType
606     *
607     * @exception BaseException
608     */

609    public how_closedType how_closed (SharkTransaction t) throws BaseException {
610       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
611       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
612       if (sm!=null) {
613          try {
614             sm.check_activity_how_closed(t,
615                                          processId,
616                                          id,
617                                          userAuth,
618                                          actInternal.container(t).requester(t).getResourceRequesterUsername(t),
619                                          actInternal.getResourceUsername(t),
620                                          actInternal.getAssignmentResourceIds(t));
621          } catch (Exception JavaDoc ex) {
622             throw new BaseException(ex);
623          }
624       }
625
626       String JavaDoc state=actInternal.state(t);
627
628       if (state.equals(SharkConstants.STATE_CLOSED_COMPLETED)) {
629          return how_closedType.completed;
630       } else if (state.equals(SharkConstants.STATE_CLOSED_TERMINATED)) {
631          return how_closedType.terminated;
632       } else {
633          return how_closedType.aborted;
634       }
635    }
636
637
638    public String JavaDoc[] valid_states () throws BaseException {
639       String JavaDoc[] ret = null;
640       SharkTransaction t = null;
641       try {
642          t = SharkUtilities.createTransaction();
643          ret = valid_states(t);
644          //SharkUtilities.commitTransaction(t);
645
} catch (RootException e) {
646          //SharkUtilities.rollbackTransaction(t);
647
SharkUtilities.emptyCaches(t);
648          if (e instanceof BaseException)
649             throw (BaseException)e;
650          else
651             throw new BaseException(e);
652       } finally {
653          SharkUtilities.releaseTransaction(t);
654       }
655       return ret;
656    }
657
658    public String JavaDoc[] valid_states (SharkTransaction t) throws BaseException {
659       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
660       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
661       if (sm!=null) {
662          try {
663             sm.check_activity_valid_states(t,
664                                            processId,
665                                            id,
666                                            userAuth,
667                                            actInternal.container(t).requester(t).getResourceRequesterUsername(t),
668                                            actInternal.getResourceUsername(t),
669                                            actInternal.getAssignmentResourceIds(t));
670          } catch (Exception JavaDoc ex) {
671             throw new BaseException(ex);
672          }
673       }
674
675       String JavaDoc state=actInternal.state(t);
676
677       List JavaDoc vs=SharkUtilities.valid_activity_states(actInternal.state(t));
678       String JavaDoc[] vss=new String JavaDoc[vs.size()];
679       vs.toArray(vss);
680       return vss;
681    }
682
683    public String JavaDoc state () throws BaseException {
684       String JavaDoc ret = null;
685       SharkTransaction t = null;
686       try {
687          t = SharkUtilities.createTransaction();
688          ret = state(t);
689          //SharkUtilities.commitTransaction(t);
690
} catch (RootException e) {
691          //SharkUtilities.rollbackTransaction(t);
692
SharkUtilities.emptyCaches(t);
693          if (e instanceof BaseException)
694             throw (BaseException)e;
695          else
696             throw new BaseException(e);
697       } finally {
698          SharkUtilities.releaseTransaction(t);
699       }
700       return ret;
701    }
702
703    public String JavaDoc state (SharkTransaction t) throws BaseException {
704       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
705       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
706       if (sm!=null) {
707          try {
708             sm.check_activity_state(t,
709                                     processId,
710                                     id,
711                                     userAuth,
712                                     actInternal.container(t).requester(t).getResourceRequesterUsername(t),
713                                     actInternal.getResourceUsername(t),
714                                     actInternal.getAssignmentResourceIds(t));
715          } catch (Exception JavaDoc ex) {
716             throw new BaseException(ex);
717          }
718       }
719
720       String JavaDoc state=actInternal.state(t);
721
722       return actInternal.state(t);
723    }
724
725    public void change_state (String JavaDoc new_state) throws BaseException, InvalidState, TransitionNotAllowed {
726       SharkTransaction t = null;
727       try {
728          t = SharkUtilities.createTransaction();
729          change_state(t, new_state);
730          SharkUtilities.commitTransaction(t);
731       } catch (RootException e) {
732          SharkUtilities.rollbackTransaction(t,e);
733          if (e instanceof InvalidState)
734             throw (InvalidState)e;
735          else if (e instanceof TransitionNotAllowed)
736             throw (TransitionNotAllowed)e;
737          else if (e instanceof BaseException)
738             throw (BaseException)e;
739          else
740             throw new BaseException(e);
741       } finally {
742          SharkUtilities.releaseTransaction(t);
743       }
744    }
745
746    public void change_state (SharkTransaction t,String JavaDoc new_state) throws BaseException, InvalidState, TransitionNotAllowed {
747       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
748       String JavaDoc curResUname=actInternal.getResourceUsername(t);
749       String JavaDoc curState=actInternal.state(t);
750       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
751       if (sm!=null) {
752          try {
753             sm.check_activity_change_state(t,
754                                            processId,
755                                            id,
756                                            userAuth,
757                                            actInternal.container(t).requester(t).getResourceRequesterUsername(t),
758                                            curResUname,
759                                            actInternal.getAssignmentResourceIds(t),
760                                            curState,
761                                            new_state);
762          } catch (Exception JavaDoc ex) {
763             throw new BaseException(ex);
764          }
765       }
766
767       if (!SharkConstants.possibleActivityStates.contains(new_state)) {
768          throw new InvalidState("Can't change activity state to "+new_state+" - no such state!");
769       }
770
771       if (!SharkUtilities.valid_activity_states(actInternal.state(t)).contains(new_state)) {
772          throw new TransitionNotAllowed("Current activity state is "+curState+" - can't change to state "+new_state+"!");
773       }
774       if (new_state.equals(SharkConstants.STATE_CLOSED_ABORTED)) {
775          try {
776             actInternal.abort(t);
777          } catch (CannotStop cns) {
778             throw new TransitionNotAllowed(cns);
779          } catch (NotRunning nr) {
780             throw new TransitionNotAllowed(nr);
781          }
782       } else if (new_state.equals(SharkConstants.STATE_CLOSED_COMPLETED)) {
783          try {
784             actInternal.complete(t);
785          } catch (CannotComplete cnc) {
786             throw new TransitionNotAllowed(cnc);
787          }
788       } else if (new_state.equals(SharkConstants.STATE_CLOSED_TERMINATED)) {
789          try {
790             actInternal.terminate(t);
791          } catch (CannotStop cns) {
792             throw new TransitionNotAllowed(cns);
793          } catch (NotRunning nr) {
794             throw new TransitionNotAllowed(nr);
795          }
796       } else if (new_state.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED)) {
797          try {
798             actInternal.set_accepted_status(t,false,userAuth);
799          } catch (Exception JavaDoc ex) {
800             throw new BaseException(ex);
801          }
802       } else if (new_state.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED)) {
803          try {
804             actInternal.suspend(t);
805          } catch (AlreadySuspended as) {
806             throw new TransitionNotAllowed(as);
807          } catch (CannotSuspend cns) {
808             throw new TransitionNotAllowed(cns);
809          } catch (NotRunning nr) {
810             throw new TransitionNotAllowed(nr);
811          }
812       } else { //new state is open.running
813
if (curState.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED)) {
814             try {
815                actInternal.resume(t);
816             } catch (CannotResume cnr) {
817                throw new TransitionNotAllowed(cnr);
818             } catch (NotSuspended ns) {
819                throw new TransitionNotAllowed(ns);
820             }
821          } else { // curState is NOT_RUNNING_NOT_STARTED
822
try {
823                actInternal.set_accepted_status(t,true,userAuth);
824             } catch (Exception JavaDoc ex) {
825                throw new BaseException(ex);
826             }
827          }
828       }
829    }
830
831    public String JavaDoc name () throws BaseException {
832       String JavaDoc ret = null;
833       SharkTransaction t = null;
834       try {
835          t = SharkUtilities.createTransaction();
836          ret = name(t);
837          //SharkUtilities.commitTransaction(t);
838
} catch (RootException e) {
839          //SharkUtilities.rollbackTransaction(t);
840
SharkUtilities.emptyCaches(t);
841          if (e instanceof BaseException)
842             throw (BaseException)e;
843          else
844             throw new BaseException(e);
845       } finally {
846          SharkUtilities.releaseTransaction(t);
847       }
848       return ret;
849    }
850
851    public String JavaDoc name (SharkTransaction t) throws BaseException {
852       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
853       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
854       if (sm!=null) {
855          try {
856             sm.check_activity_name(t,
857                                    processId,
858                                    id,
859                                    userAuth,
860                                    actInternal.container(t).requester(t).getResourceRequesterUsername(t),
861                                    actInternal.getResourceUsername(t),
862                                    actInternal.getAssignmentResourceIds(t));
863          } catch (Exception JavaDoc ex) {
864             throw new BaseException(ex);
865          }
866       }
867       return actInternal.name(t);
868    }
869
870    public void set_name (String JavaDoc new_value) throws BaseException {
871       SharkTransaction t = null;
872       try {
873          t = SharkUtilities.createTransaction();
874          set_name(t, new_value);
875          SharkUtilities.commitTransaction(t);
876       } catch (RootException e) {
877          SharkUtilities.rollbackTransaction(t,e);
878          if (e instanceof BaseException)
879             throw (BaseException)e;
880          else
881             throw new BaseException(e);
882       } finally {
883          SharkUtilities.releaseTransaction(t);
884       }
885    }
886
887    public void set_name (SharkTransaction t,String JavaDoc new_value) throws BaseException {
888       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
889       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
890       if (sm!=null) {
891          try {
892             sm.check_activity_set_name(t,
893                                        processId,
894                                        id,
895                                        userAuth,
896                                        actInternal.container(t).requester(t).getResourceRequesterUsername(t),
897                                        actInternal.getResourceUsername(t),
898                                        actInternal.getAssignmentResourceIds(t));
899          } catch (Exception JavaDoc ex) {
900             throw new BaseException(ex);
901          }
902       }
903       actInternal.set_name(t,new_value);
904    }
905
906    public String JavaDoc key () throws BaseException {
907       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
908       if (sm==null) {
909          return id;
910       }
911       String JavaDoc ret = null;
912       SharkTransaction t = null;
913       try {
914          t = SharkUtilities.createTransaction();
915          ret = key(t);
916          //SharkUtilities.commitTransaction(t);
917
} catch (RootException e) {
918          //SharkUtilities.rollbackTransaction(t);
919
SharkUtilities.emptyCaches(t);
920          if (e instanceof BaseException)
921             throw (BaseException)e;
922          else
923             throw new BaseException(e);
924       } finally {
925          SharkUtilities.releaseTransaction(t);
926       }
927       return ret;
928    }
929
930    public String JavaDoc key (SharkTransaction t) throws BaseException {
931       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
932       if (sm!=null) {
933          WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
934          try {
935             sm.check_activity_key(t,
936                                   processId,
937                                   id,
938                                   userAuth,
939                                   actInternal.container(t).requester(t).getResourceRequesterUsername(t),
940                                   actInternal.getResourceUsername(t),
941                                   actInternal.getAssignmentResourceIds(t));
942          } catch (Exception JavaDoc ex) {
943             throw new BaseException(ex);
944          }
945       }
946       return id;
947    }
948
949    public String JavaDoc description () throws BaseException {
950       String JavaDoc ret = null;
951       SharkTransaction t = null;
952       try {
953          t = SharkUtilities.createTransaction();
954          ret = description(t);
955          //SharkUtilities.commitTransaction(t);
956
} catch (RootException e) {
957          //SharkUtilities.rollbackTransaction(t);
958
SharkUtilities.emptyCaches(t);
959          if (e instanceof BaseException)
960             throw (BaseException)e;
961          else
962             throw new BaseException(e);
963       } finally {
964          SharkUtilities.releaseTransaction(t);
965       }
966       return ret;
967    }
968
969    public String JavaDoc description (SharkTransaction t) throws BaseException {
970       WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
971       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
972       if (sm!=null) {
973          try {
974             sm.check_activity_description(t,
975                                           processId,
976                                           id,
977                                           userAuth,
978                                           actInternal.container(t).requester(t).getResourceRequesterUsername(t),
979                                           actInternal.getResourceUsername(t),
980                                           actInternal.getAssignmentResourceIds(t));
981          } catch (Exception JavaDoc ex) {
982             throw new BaseException(ex);
983          }
984       }
985       return actInternal.description(t);
986    }
987
988    public void set_description (String JavaDoc new_value) throws BaseException {
989       SharkTransaction t = null;
990       try {
991          t = SharkUtilities.createTransaction();
992          set_description(t, new_value);
993          SharkUtilities.commitTransaction(t);
994       } catch (RootException e) {
995          SharkUtilities.rollbackTransaction(t,e);
996          if (e instanceof BaseException)
997             throw (BaseException)e;
998          else
999             throw new BaseException(e);
1000      } finally {
1001         SharkUtilities.releaseTransaction(t);
1002      }
1003   }
1004
1005   public void set_description (SharkTransaction t,String JavaDoc new_value) throws BaseException {
1006      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1007      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1008      if (sm!=null) {
1009         try {
1010            sm.check_activity_set_description(t,
1011                                              processId,
1012                                              id,
1013                                              userAuth,
1014                                              actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1015                                              actInternal.getResourceUsername(t),
1016                                              actInternal.getAssignmentResourceIds(t));
1017         } catch (Exception JavaDoc ex) {
1018            throw new BaseException(ex);
1019         }
1020      }
1021
1022      actInternal.set_description(t,new_value);
1023   }
1024
1025   public Map JavaDoc process_context () throws BaseException {
1026      Map JavaDoc ret = null;
1027      SharkTransaction t = null;
1028      try {
1029         t = SharkUtilities.createTransaction();
1030         ret = process_context(t);
1031         //SharkUtilities.commitTransaction(t);
1032
} catch (RootException e) {
1033         //SharkUtilities.rollbackTransaction(t);
1034
SharkUtilities.emptyCaches(t);
1035         if (e instanceof BaseException)
1036            throw (BaseException)e;
1037         else
1038            throw new BaseException(e);
1039      } finally {
1040         SharkUtilities.releaseTransaction(t);
1041      }
1042      return ret;
1043   }
1044
1045   public Map JavaDoc process_context (SharkTransaction t) throws BaseException {
1046      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1047      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1048      if (sm!=null) {
1049         try {
1050            sm.check_activity_process_context(t,
1051                                              processId,
1052                                              id,
1053                                              userAuth,
1054                                              actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1055                                              actInternal.getResourceUsername(t),
1056                                              actInternal.getAssignmentResourceIds(t));
1057         } catch (Exception JavaDoc ex) {
1058            throw new BaseException(ex);
1059         }
1060      }
1061
1062      return actInternal.process_context(t);
1063   }
1064
1065   public void set_process_context (Map JavaDoc new_value) throws BaseException, InvalidData, UpdateNotAllowed {
1066      SharkTransaction t = null;
1067      try {
1068         t = SharkUtilities.createTransaction();
1069         set_process_context(t, new_value);
1070         SharkUtilities.commitTransaction(t);
1071      } catch (RootException e) {
1072         SharkUtilities.rollbackTransaction(t,e);
1073         if (e instanceof InvalidData)
1074            throw (InvalidData)e;
1075         else if (e instanceof UpdateNotAllowed)
1076            throw (UpdateNotAllowed)e;
1077         else if (e instanceof BaseException)
1078            throw (BaseException)e;
1079         else
1080            throw new BaseException(e);
1081      } finally {
1082         SharkUtilities.releaseTransaction(t);
1083      }
1084   }
1085
1086   public void set_process_context (SharkTransaction t,Map JavaDoc new_value) throws BaseException, InvalidData, UpdateNotAllowed {
1087      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1088      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1089      if (sm!=null) {
1090         try {
1091            sm.check_activity_set_process_context(t,
1092                                                  processId,
1093                                                  id,
1094                                                  userAuth,
1095                                                  actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1096                                                  actInternal.getResourceUsername(t),
1097                                                  actInternal.getAssignmentResourceIds(t));
1098         } catch (Exception JavaDoc ex) {
1099            throw new BaseException(ex);
1100         }
1101      }
1102      actInternal.set_process_context(t,new_value);
1103   }
1104
1105   public short priority () throws BaseException {
1106      short ret = -1;
1107      SharkTransaction t = null;
1108      try {
1109         t = SharkUtilities.createTransaction();
1110         ret = priority(t);
1111         //SharkUtilities.commitTransaction(t);
1112
} catch (RootException e) {
1113         //SharkUtilities.rollbackTransaction(t);
1114
SharkUtilities.emptyCaches(t);
1115         if (e instanceof BaseException)
1116            throw (BaseException)e;
1117         else
1118            throw new BaseException(e);
1119      } finally {
1120         SharkUtilities.releaseTransaction(t);
1121      }
1122      return ret;
1123   }
1124
1125   public short priority (SharkTransaction t) throws BaseException {
1126      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1127      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1128      if (sm!=null) {
1129         try {
1130            sm.check_activity_priority(t,
1131                                       processId,
1132                                       id,
1133                                       userAuth,
1134                                       actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1135                                       actInternal.getResourceUsername(t),
1136                                       actInternal.getAssignmentResourceIds(t));
1137         } catch (Exception JavaDoc ex) {
1138            throw new BaseException(ex);
1139         }
1140      }
1141      return actInternal.priority(t);
1142   }
1143
1144   public void set_priority (short new_value) throws BaseException {
1145      SharkTransaction t = null;
1146      try {
1147         t = SharkUtilities.createTransaction();
1148         set_priority(t, new_value);
1149         SharkUtilities.commitTransaction(t);
1150      } catch (RootException e) {
1151         SharkUtilities.rollbackTransaction(t,e);
1152         if (e instanceof BaseException)
1153            throw (BaseException)e;
1154         else
1155            throw new BaseException(e);
1156      } finally {
1157         SharkUtilities.releaseTransaction(t);
1158      }
1159   }
1160
1161   public void set_priority (SharkTransaction t,short new_value) throws BaseException {
1162      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1163      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1164      if (sm!=null) {
1165         try {
1166            sm.check_activity_set_priority(t,
1167                                           processId,
1168                                           id,
1169                                           userAuth,
1170                                           actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1171                                           actInternal.getResourceUsername(t),
1172                                           actInternal.getAssignmentResourceIds(t));
1173         } catch (Exception JavaDoc ex) {
1174            throw new BaseException(ex);
1175         }
1176      }
1177
1178      actInternal.set_priority(t,new_value);
1179   }
1180
1181   /**
1182    * Resume this process or activity.
1183    */

1184   public void resume() throws BaseException, CannotResume, NotSuspended {
1185      SharkTransaction t = null;
1186      try {
1187         t = SharkUtilities.createTransaction();
1188         resume(t);
1189         SharkUtilities.commitTransaction(t);
1190      } catch (RootException e) {
1191         SharkUtilities.rollbackTransaction(t,e);
1192         if (e instanceof CannotResume)
1193            throw (CannotResume)e;
1194         else if (e instanceof NotSuspended)
1195            throw (NotSuspended)e;
1196         else if (e instanceof BaseException)
1197            throw (BaseException)e;
1198         else
1199            throw new BaseException(e);
1200      } finally {
1201         SharkUtilities.releaseTransaction(t);
1202      }
1203   }
1204
1205   public void resume(SharkTransaction t) throws BaseException, CannotResume, NotSuspended {
1206      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1207      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1208      if (sm!=null) {
1209         try {
1210            sm.check_activity_result(t,
1211                                     processId,
1212                                     id,
1213                                     userAuth,
1214                                     actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1215                                     actInternal.getResourceUsername(t),
1216                                     actInternal.getAssignmentResourceIds(t));
1217         } catch (Exception JavaDoc ex) {
1218            throw new BaseException(ex);
1219         }
1220      }
1221      actInternal.resume(t);
1222   }
1223
1224   /**
1225    * Suspend this process or activity.
1226    */

1227   public void suspend() throws BaseException, CannotSuspend, NotRunning, AlreadySuspended {
1228      SharkTransaction t = null;
1229      try {
1230         t = SharkUtilities.createTransaction();
1231         suspend(t);
1232         SharkUtilities.commitTransaction(t);
1233      } catch (RootException e) {
1234         SharkUtilities.rollbackTransaction(t,e);
1235         if (e instanceof CannotSuspend)
1236            throw (CannotSuspend)e;
1237         else if (e instanceof NotRunning)
1238            throw (NotRunning)e;
1239         else if (e instanceof AlreadySuspended)
1240            throw (AlreadySuspended)e;
1241         else if (e instanceof BaseException)
1242            throw (BaseException)e;
1243         else
1244            throw new BaseException(e);
1245      } finally {
1246         SharkUtilities.releaseTransaction(t);
1247      }
1248   }
1249
1250   public void suspend(SharkTransaction t) throws BaseException, CannotSuspend, NotRunning, AlreadySuspended {
1251      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1252      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1253      if (sm!=null) {
1254         try {
1255            sm.check_activity_suspend(t,
1256                                      processId,
1257                                      id,
1258                                      userAuth,
1259                                      actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1260                                      actInternal.getResourceUsername(t),
1261                                      actInternal.getAssignmentResourceIds(t));
1262         } catch (Exception JavaDoc ex) {
1263            throw new BaseException(ex);
1264         }
1265      }
1266      actInternal.suspend(t);
1267   }
1268
1269   /**
1270    * Terminate this process or activity.
1271    */

1272   public void terminate() throws BaseException, CannotStop, NotRunning {
1273      SharkTransaction t = null;
1274      try {
1275         t = SharkUtilities.createTransaction();
1276         terminate(t);
1277         SharkUtilities.commitTransaction(t);
1278      } catch (RootException e) {
1279         SharkUtilities.rollbackTransaction(t,e);
1280         if (e instanceof CannotStop)
1281            throw (CannotStop)e;
1282         else if (e instanceof NotRunning)
1283            throw (NotRunning)e;
1284         else if (e instanceof BaseException)
1285            throw (BaseException)e;
1286         else
1287            throw new BaseException(e);
1288      } finally {
1289         SharkUtilities.releaseTransaction(t);
1290      }
1291   }
1292
1293   public void terminate(SharkTransaction t) throws BaseException, CannotStop, NotRunning {
1294      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1295      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1296      if (sm!=null) {
1297         try {
1298            sm.check_activity_terminate(t,
1299                                        processId,
1300                                        id,
1301                                        userAuth,
1302                                        actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1303                                        actInternal.getResourceUsername(t),
1304                                        actInternal.getAssignmentResourceIds(t));
1305         } catch (Exception JavaDoc ex) {
1306            throw new BaseException(ex);
1307         }
1308      }
1309      actInternal.terminate(t);
1310   }
1311
1312   /**
1313    * Abort the execution of this process or activity.
1314    */

1315   public void abort() throws BaseException, CannotStop, NotRunning {
1316      SharkTransaction t = null;
1317      try {
1318         t = SharkUtilities.createTransaction();
1319         abort(t);
1320         SharkUtilities.commitTransaction(t);
1321      } catch (RootException e) {
1322         SharkUtilities.rollbackTransaction(t,e);
1323         if (e instanceof CannotStop)
1324            throw (CannotStop)e;
1325         else if (e instanceof NotRunning)
1326            throw (NotRunning)e;
1327         else if (e instanceof BaseException)
1328            throw (BaseException)e;
1329         else
1330            throw new BaseException(e);
1331      } finally {
1332         SharkUtilities.releaseTransaction(t);
1333      }
1334   }
1335
1336   public void abort(SharkTransaction t) throws BaseException, CannotStop, NotRunning {
1337      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1338      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1339      if (sm!=null) {
1340         try {
1341            sm.check_activity_abort(t,
1342                                    processId,
1343                                    id,
1344                                    userAuth,
1345                                    actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1346                                    actInternal.getResourceUsername(t),
1347                                    actInternal.getAssignmentResourceIds(t));
1348         } catch (Exception JavaDoc ex) {
1349            throw new BaseException(ex);
1350         }
1351      }
1352      actInternal.abort(t);
1353   }
1354
1355   public int how_many_history() throws BaseException, HistoryNotAvailable {
1356      int ret = -1;
1357      SharkTransaction t = null;
1358      try {
1359         t = SharkUtilities.createTransaction();
1360         ret = how_many_history(t);
1361         //SharkUtilities.commitTransaction(t);
1362
} catch (RootException e) {
1363         //SharkUtilities.rollbackTransaction(t);
1364
SharkUtilities.emptyCaches(t);
1365         if (e instanceof HistoryNotAvailable)
1366            throw (HistoryNotAvailable)e;
1367         else if (e instanceof BaseException)
1368            throw (BaseException)e;
1369         else
1370            throw new BaseException(e);
1371      } finally {
1372         SharkUtilities.releaseTransaction(t);
1373      }
1374      return ret;
1375   }
1376
1377   public int how_many_history(SharkTransaction t) throws BaseException, HistoryNotAvailable {
1378      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1379      if (sm!=null) {
1380         WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1381         try {
1382            sm.check_activity_how_many_history(t,
1383                                               processId,
1384                                               id,
1385                                               userAuth,
1386                                               actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1387                                               actInternal.getResourceUsername(t),
1388                                               actInternal.getAssignmentResourceIds(t));
1389         } catch (Exception JavaDoc ex) {
1390            throw new BaseException(ex);
1391         }
1392      }
1393      try {
1394         EventAuditManagerInterface eam = SharkEngineManager
1395            .getInstance()
1396            .getEventAuditManager();
1397         if (null == eam)
1398            return 0;
1399         return eam.restoreActivityHistory(processId,id,t).size();
1400      } catch (Exception JavaDoc ex) {
1401         throw new BaseException("Problems while retrieving activity's history!",ex);
1402      }
1403   }
1404
1405   /**
1406    * Search in the history for specific elements.
1407    * @param query Search criteria.
1408    * @param names_in_query elements to search.
1409    * @return Found history elements that meet the search criteria.
1410    */

1411   public WfEventAuditIterator get_iterator_history (String JavaDoc query, Map JavaDoc names_in_query) throws BaseException, HistoryNotAvailable {
1412      WfEventAuditIterator ret = null;
1413      SharkTransaction t = null;
1414      try {
1415         t = SharkUtilities.createTransaction();
1416         ret = get_iterator_history(t,query,names_in_query);
1417         //SharkUtilities.commitTransaction(t);
1418
} catch (RootException e) {
1419         //SharkUtilities.rollbackTransaction(t);
1420
SharkUtilities.emptyCaches(t);
1421         if (e instanceof HistoryNotAvailable)
1422            throw (HistoryNotAvailable)e;
1423         else if (e instanceof BaseException)
1424            throw (BaseException)e;
1425         else
1426            throw new BaseException(e);
1427      } finally {
1428         SharkUtilities.releaseTransaction(t);
1429      }
1430      return ret;
1431   }
1432
1433   public WfEventAuditIterator get_iterator_history (SharkTransaction t,String JavaDoc query, Map JavaDoc names_in_query) throws BaseException, HistoryNotAvailable {
1434      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1435      if (sm!=null) {
1436         WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1437         try {
1438            sm.check_activity_get_iterator_history(t,
1439                                                   processId,
1440                                                   id,
1441                                                   userAuth,
1442                                                   actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1443                                                   actInternal.getResourceUsername(t),
1444                                                   actInternal.getAssignmentResourceIds(t));
1445         } catch (Exception JavaDoc ex) {
1446            throw new BaseException(ex);
1447         }
1448      }
1449      WfEventAuditIterator it=SharkEngineManager.
1450         getInstance().
1451         getObjectFactory().
1452         createEventAuditIteratorWrapper(t,userAuth,processId,id);
1453      try {
1454         it.set_query_expression(t,query);
1455         it.set_names_in_expression(t,names_in_query);
1456      } catch (Exception JavaDoc ex) {
1457         throw new BaseException(ex);
1458      }
1459      return it;
1460   }
1461
1462   /**
1463    * Getter for history sequence.
1464    * @param max_number Maximum number of element in result list.
1465    * @return List of History objects.
1466    */

1467   public WfEventAudit[] get_sequence_history (int max_number) throws BaseException, HistoryNotAvailable {
1468      WfEventAudit[] ret = null;
1469      SharkTransaction t = null;
1470      try {
1471         t = SharkUtilities.createTransaction();
1472         ret = get_sequence_history(t,max_number);
1473         //SharkUtilities.commitTransaction(t);
1474
} catch (RootException e) {
1475         //SharkUtilities.rollbackTransaction(t);
1476
SharkUtilities.emptyCaches(t);
1477         if (e instanceof HistoryNotAvailable)
1478            throw (HistoryNotAvailable)e;
1479         else if (e instanceof BaseException)
1480            throw (BaseException)e;
1481         else
1482            throw new BaseException(e);
1483      } finally {
1484         SharkUtilities.releaseTransaction(t);
1485      }
1486      return ret;
1487   }
1488
1489   public WfEventAudit[] get_sequence_history (SharkTransaction t,int max_number) throws BaseException, HistoryNotAvailable {
1490      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1491      if (sm!=null) {
1492         WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1493         try {
1494            sm.check_activity_get_sequence_history(t,
1495                                                   processId,
1496                                                   id,
1497                                                   userAuth,
1498                                                   actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1499                                                   actInternal.getResourceUsername(t),
1500                                                   actInternal.getAssignmentResourceIds(t));
1501         } catch (Exception JavaDoc ex) {
1502            throw new BaseException(ex);
1503         }
1504      }
1505
1506      List JavaDoc history=SharkUtilities.createActivityHistoryEvents(t,userAuth,processId,id);
1507      if (max_number>history.size() || max_number<=0) {
1508         max_number=history.size();
1509      }
1510      WfEventAudit[] eas=new WfEventAudit[max_number];
1511      history.subList(0,max_number).toArray(eas);
1512      return eas;
1513   }
1514
1515   /**
1516    * Predicate to check if a 'member' is an element of the history.
1517    * @return true if the element of the history, false otherwise.
1518    */

1519   public boolean is_member_of_history (WfExecutionObject member) throws BaseException {
1520      boolean ret = false;
1521      SharkTransaction t = null;
1522      try {
1523         t = SharkUtilities.createTransaction();
1524         ret = is_member_of_history(t,member);
1525         //SharkUtilities.commitTransaction(t);
1526
} catch (RootException e) {
1527         //SharkUtilities.rollbackTransaction(t);
1528
SharkUtilities.emptyCaches(t);
1529         if (e instanceof BaseException)
1530            throw (BaseException)e;
1531         else
1532            throw new BaseException(e);
1533      } finally {
1534         SharkUtilities.releaseTransaction(t);
1535      }
1536      return ret;
1537   }
1538
1539   public boolean is_member_of_history (SharkTransaction t,WfExecutionObject member) throws BaseException {
1540      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1541      if (sm!=null) {
1542         WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1543         try {
1544            sm.check_activity_is_member_of_history(t,
1545                                                   processId,
1546                                                   id,
1547                                                   userAuth,
1548                                                   actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1549                                                   actInternal.getResourceUsername(t),
1550                                                   actInternal.getAssignmentResourceIds(t));
1551         } catch (Exception JavaDoc ex) {
1552            throw new BaseException(ex);
1553         }
1554      }
1555
1556      boolean ret=false;
1557      List JavaDoc history=SharkUtilities.createActivityHistoryEvents(t,userAuth,processId,id);
1558      Iterator JavaDoc it=history.iterator();
1559      while (it.hasNext()) {
1560         WfEventAudit ea=(WfEventAudit)it.next();
1561         if (member instanceof WfActivity) {
1562            WfActivity act=(WfActivity)member;
1563            if (act.container(t).key(t).equals(ea.process_key()) &&
1564                act.key(t).equals(ea.activity_key())) {
1565               ret=true;
1566               break;
1567            }
1568         } else {
1569            if (member.key(t).equals(ea.process_key())) {
1570               ret=true;
1571               break;
1572            }
1573         }
1574      }
1575      return ret;
1576   }
1577
1578   public UtcT last_state_time () throws BaseException {
1579      UtcT ret = null;
1580      SharkTransaction t = null;
1581      try {
1582         t = SharkUtilities.createTransaction();
1583         ret = last_state_time(t);
1584         //SharkUtilities.commitTransaction(t);
1585
} catch (RootException e) {
1586         //SharkUtilities.rollbackTransaction(t);
1587
SharkUtilities.emptyCaches(t);
1588         if (e instanceof BaseException)
1589            throw (BaseException)e;
1590         else
1591            throw new BaseException(e);
1592      } finally {
1593         SharkUtilities.releaseTransaction(t);
1594      }
1595      return ret;
1596   }
1597
1598   public UtcT last_state_time (SharkTransaction t) throws BaseException {
1599      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1600      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1601      if (sm!=null) {
1602         try {
1603            sm.check_activity_last_state_time(t,
1604                                              processId,
1605                                              id,
1606                                              userAuth,
1607                                              actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1608                                              actInternal.getResourceUsername(t),
1609                                              actInternal.getAssignmentResourceIds(t));
1610         } catch (Exception JavaDoc ex) {
1611            throw new BaseException(ex);
1612         }
1613      }
1614
1615      return actInternal.last_state_time(t);
1616   }
1617
1618   /**
1619    * Gets the number of processes.
1620    */

1621   public int how_many_performer () throws BaseException {
1622      int ret = -1;
1623      SharkTransaction t = null;
1624      try {
1625         t = SharkUtilities.createTransaction();
1626         ret = how_many_performer(t);
1627         //SharkUtilities.commitTransaction(t);
1628
} catch (RootException e) {
1629         //SharkUtilities.rollbackTransaction(t);
1630
SharkUtilities.emptyCaches(t);
1631         if (e instanceof BaseException)
1632            throw (BaseException)e;
1633         else
1634            throw new BaseException(e);
1635      } finally {
1636         SharkUtilities.releaseTransaction(t);
1637      }
1638      return ret;
1639   }
1640
1641   public int how_many_performer (SharkTransaction t) throws BaseException {
1642      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1643      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1644      if (sm!=null) {
1645         try {
1646            sm.check_activity_how_many_performer(t,
1647                                                 processId,
1648                                                 id,
1649                                                 userAuth,
1650                                                 actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1651                                                 actInternal.getResourceUsername(t),
1652                                                 actInternal.getAssignmentResourceIds(t));
1653         } catch (Exception JavaDoc ex) {
1654            throw new BaseException(ex);
1655         }
1656      }
1657      return ((actInternal.getPerformerId(t)!=null) ? 1:0);
1658   }
1659
1660   /**
1661    * Gets an iterator of processes.
1662    */

1663   public WfProcessIterator get_iterator_performer () throws BaseException {
1664      WfProcessIterator ret = null;
1665      SharkTransaction t = null;
1666      try {
1667         t = SharkUtilities.createTransaction();
1668         ret = get_iterator_performer(t);
1669         //SharkUtilities.commitTransaction(t);
1670
} catch (RootException e) {
1671         //SharkUtilities.rollbackTransaction(t);
1672
SharkUtilities.emptyCaches(t);
1673         if (e instanceof BaseException)
1674            throw (BaseException)e;
1675         else
1676            throw new BaseException(e);
1677      } finally {
1678         SharkUtilities.releaseTransaction(t);
1679      }
1680      return ret;
1681   }
1682
1683   public WfProcessIterator get_iterator_performer (SharkTransaction t) throws BaseException {
1684      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1685      if (sm!=null) {
1686         WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1687         try {
1688            sm.check_activity_get_iterator_performer(t,
1689                                                     processId,
1690                                                     id,
1691                                                     userAuth,
1692                                                     actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1693                                                     actInternal.getResourceUsername(t),
1694                                                     actInternal.getAssignmentResourceIds(t));
1695         } catch (Exception JavaDoc ex) {
1696            throw new BaseException(ex);
1697         }
1698      }
1699
1700      return SharkEngineManager.
1701         getInstance().
1702         getObjectFactory().createProcessIteratorWrapper(t,userAuth,processId,id);
1703   }
1704
1705   /**
1706    * A list of processes
1707    * @return List of WfProcess objects.
1708    */

1709   public WfProcess[] get_sequence_performer (int max_number) throws BaseException {
1710      WfProcess[] ret = null;
1711      SharkTransaction t = null;
1712      try {
1713         t = SharkUtilities.createTransaction();
1714         ret = get_sequence_performer(t,max_number);
1715         //SharkUtilities.commitTransaction(t);
1716
} catch (RootException e) {
1717         //SharkUtilities.rollbackTransaction(t);
1718
SharkUtilities.emptyCaches(t);
1719         if (e instanceof BaseException)
1720            throw (BaseException)e;
1721         else
1722            throw new BaseException(e);
1723      } finally {
1724         SharkUtilities.releaseTransaction(t);
1725      }
1726      return ret;
1727   }
1728
1729   public WfProcess[] get_sequence_performer (SharkTransaction t,int max_number) throws BaseException {
1730      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1731      if (sm!=null) {
1732         WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1733         try {
1734            sm.check_activity_get_sequence_performer(t,
1735                                                     processId,
1736                                                     id,
1737                                                     userAuth,
1738                                                     actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1739                                                     actInternal.getResourceUsername(t),
1740                                                     actInternal.getAssignmentResourceIds(t));
1741         } catch (Exception JavaDoc ex) {
1742            throw new BaseException(ex);
1743         }
1744      }
1745
1746      try {
1747         List JavaDoc l=SharkUtilities.createActivityPerformerWrapper(t,userAuth,processId,id);
1748         if (max_number > l.size() || max_number<=0) {
1749            max_number = l.size();
1750         }
1751         WfProcess[] ret = new WfProcess[l.size()];
1752         l.subList(0, max_number).toArray(ret);
1753         return ret;
1754      } catch (Exception JavaDoc ex) {
1755         throw new BaseException(ex);
1756      }
1757   }
1758
1759   /**
1760    * Checks if a WfProcess is associated with this requester object
1761    * @return true if the process is found.
1762    */

1763   public boolean is_member_of_performer (WfProcess member) throws BaseException {
1764      boolean ret = false;
1765      SharkTransaction t = null;
1766      try {
1767         t = SharkUtilities.createTransaction();
1768         ret = is_member_of_performer(t,member);
1769         //SharkUtilities.commitTransaction(t);
1770
} catch (RootException e) {
1771         //SharkUtilities.rollbackTransaction(t);
1772
SharkUtilities.emptyCaches(t);
1773         if (e instanceof BaseException)
1774            throw (BaseException)e;
1775         else
1776            throw new BaseException(e);
1777      } finally {
1778         SharkUtilities.releaseTransaction(t);
1779      }
1780      return ret;
1781   }
1782
1783   public boolean is_member_of_performer (SharkTransaction t,WfProcess member) throws BaseException {
1784      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1785      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1786      if (sm!=null) {
1787         try {
1788            sm.check_activity_is_member_of_performer(t,
1789                                                     processId,
1790                                                     id,
1791                                                     userAuth,
1792                                                     actInternal.container(t).requester(t).getResourceRequesterUsername(t),
1793                                                     actInternal.getResourceUsername(t),
1794                                                     actInternal.getAssignmentResourceIds(t));
1795         } catch (Exception JavaDoc ex) {
1796            throw new BaseException(ex);
1797         }
1798      }
1799
1800      String JavaDoc performerId=actInternal.getPerformerId(t);
1801      return (performerId!=null &&member.key(t).equals(performerId));
1802   }
1803
1804   public void receive_event (WfEventAudit event) throws BaseException, InvalidPerformer {
1805      SharkTransaction t = null;
1806      try {
1807         t = SharkUtilities.createTransaction();
1808         receive_event(t,event);
1809         SharkUtilities.commitTransaction(t);
1810      } catch (RootException e) {
1811         SharkUtilities.rollbackTransaction(t,e);
1812         SharkUtilities.emptyCaches(t);
1813         if (e instanceof BaseException)
1814            throw (BaseException)e;
1815         else
1816            throw new BaseException(e);
1817      } finally {
1818         SharkUtilities.releaseTransaction(t);
1819      }
1820   }
1821
1822   public void receive_event (SharkTransaction t,WfEventAudit event) throws BaseException, InvalidPerformer {
1823      WfActivityInternal actInternal=WfActivityWrapper.getActivityImpl(t,processId,id);
1824      actInternal.receive_event(t,event,null);
1825   }
1826
1827   /**
1828    * Method toString
1829    *
1830    * @return a String
1831    */

1832   public String JavaDoc toString () {
1833      return "[pId="+processId+",aId="+id+"]";
1834   }
1835
1836   /**
1837    * It is assumed that there can't be two or more
1838    * activities having the same key.
1839    */

1840   public boolean equals (java.lang.Object JavaDoc obj) {
1841      if (!(obj instanceof WfActivity)) return false;
1842      WfActivity act=(WfActivity)obj;
1843      try {
1844         if (obj instanceof WfActivityWrapper) {
1845            return ((WfActivityWrapper)obj).id.equals(id);
1846         } else {
1847            return act.key().equals(id);
1848         }
1849      } catch (Exception JavaDoc ex) {
1850         return false;
1851      }
1852   }
1853
1854   private static WfActivityInternal getActivityImpl (SharkTransaction t,String JavaDoc processId,String JavaDoc actId) throws BaseException {
1855      WfActivityInternal actImpl=SharkUtilities.getActivity(t,processId,actId);
1856      if (actImpl==null) throw new BaseException("Activity does not exist");
1857      return actImpl;
1858   }
1859
1860}
1861
Popular Tags