KickJava   Java API By Example, From Geeks To Geeks.

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


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.client.wfbase.InvalidQuery;
13 import org.enhydra.shark.api.client.wfbase.NameMismatch;
14 import org.enhydra.shark.api.common.SharkConstants;
15 import org.enhydra.shark.api.internal.eventaudit.EventAuditManagerInterface;
16 import org.enhydra.shark.api.internal.security.SecurityManager;
17 import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException;
18 import org.enhydra.shark.api.internal.working.WfActivityInternal;
19 import org.enhydra.shark.api.internal.working.WfProcessInternal;
20 import org.enhydra.shark.api.internal.working.WfRequesterInternal;
21
22 /**
23  * WfProcessWrapper - Workflow Process Object implementation.
24  * @author Sasa Bojanic, Vladimir Puskas
25  * @version 1.0.1
26  */

27 public class WfProcessWrapper implements WfProcess {
28
29    private String JavaDoc userAuth;
30    private String JavaDoc mgrName;
31    private String JavaDoc processId;
32
33    /**
34     * Creates new WfProcessWrapper.
35     */

36    protected WfProcessWrapper(String JavaDoc userAuth,String JavaDoc mgrName,String JavaDoc processId) {
37       this.userAuth=userAuth;
38       this.mgrName=mgrName;
39       this.processId = processId;
40    }
41
42
43    /**
44     * Retrieves the requestor of this process.
45     *
46     * @return a WfRequester.
47     *
48     * @exception BaseException.
49     */

50    public WfRequester requester() throws BaseException {
51       WfRequester ret = null;
52       SharkTransaction t = null;
53       try {
54          t = SharkUtilities.createTransaction();
55          ret = requester(t);
56          //SharkUtilities.commitTransaction(t);
57
} catch (RootException e) {
58          //SharkUtilities.rollbackTransaction(t);
59
SharkUtilities.emptyCaches(t);
60          if (e instanceof BaseException)
61             throw (BaseException)e;
62          else
63             throw new BaseException(e);
64       } finally {
65          SharkUtilities.releaseTransaction(t);
66       }
67       return ret;
68    }
69
70    /**
71     * Method requester.
72     *
73     * @param t a SharkTransaction.
74     *
75     * @return a WfRequester
76     *
77     * @exception BaseException
78     */

79    public WfRequester requester(SharkTransaction t) throws BaseException {
80       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
81       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
82       if (sm!=null) {
83          try {
84             sm.check_process_requester(t,
85                                        processId,
86                                        userAuth,
87                                        procInternal.requester(t).getResourceRequesterUsername(t));
88          } catch (Exception JavaDoc ex) {
89             throw new BaseException(ex);
90          }
91       }
92
93       try {
94          WfRequester req=null;
95          WfRequesterInternal requester=procInternal.requester(t);
96          if (requester instanceof WfActivityInternal) {
97             WfActivityInternal act=(WfActivityInternal)requester;
98             req=SharkEngineManager.getInstance().getObjectFactory().createActivityWrapper(userAuth,act.manager_name(t),act.process_id(t),act.key(t));
99          } else {
100             WfRequester r=requester.getExternalRequester(t);
101             if (r!=null) {
102                req=r;
103             } else {
104                String JavaDoc reqUname=((WfRequesterInternal)requester).getResourceRequesterUsername(t);
105                req=SharkEngineManager.getInstance().getObjectFactory().createRequesterWrapper(userAuth,reqUname);
106             }
107          }
108          return req;
109       } catch (Exception JavaDoc ex) {
110          throw new BaseException(ex);
111       }
112    }
113
114    /**
115     * Set the requester for this process.
116     *
117     * @param new_value a WfRequester
118     *
119     * @exception BaseException
120     * @exception CannotChangeRequester
121     */

122    public void set_requester (WfRequester new_value) throws BaseException, CannotChangeRequester {
123       SharkTransaction t = null;
124       try {
125          t = SharkUtilities.createTransaction();
126          set_requester(t, new_value);
127          SharkUtilities.commitTransaction(t);
128       } catch (RootException e) {
129          SharkUtilities.rollbackTransaction(t,e);
130          if (e instanceof CannotChangeRequester)
131             throw (CannotChangeRequester)e;
132          else if (e instanceof BaseException)
133             throw (BaseException)e;
134          else
135             throw new BaseException(e);
136       } finally {
137          SharkUtilities.releaseTransaction(t);
138       }
139    }
140
141    /**
142     * Method set_requester
143     *
144     * @param t a SharkTransaction
145     * @param new_value a WfRequester
146     *
147     * @exception BaseException
148     * @exception CannotChangeRequester
149     */

150    public void set_requester(SharkTransaction t,WfRequester new_value) throws BaseException, CannotChangeRequester {
151       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
152       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
153       if (sm!=null) {
154          try {
155             sm.check_process_set_requester(t,
156                                            processId,
157                                            userAuth,
158                                            procInternal.requester(t).getResourceRequesterUsername(t));
159          } catch (Exception JavaDoc ex) {
160             throw new BaseException(ex);
161          }
162       }
163       WfRequesterInternal requester=procInternal.requester(t);
164       if (requester instanceof WfActivityInternal) {
165          throw new CannotChangeRequester("Can't change requester for a process instantiated as a subflow!");
166       } else {
167          String JavaDoc extReqClassName=null;
168          if (new_value!=null) {
169             extReqClassName=new_value.getClass().getName();
170          }
171          procInternal.setExternalRequesterClassName(t,extReqClassName);
172       }
173    }
174
175    /**
176     * Retrieve the no of activities in this process.
177     *
178     * @return an int
179     *
180     * @exception BaseException
181     */

182    public int how_many_step () throws BaseException {
183       int ret = -1;
184       SharkTransaction t = null;
185       try {
186          t = SharkUtilities.createTransaction();
187          ret = how_many_step(t);
188          //SharkUtilities.commitTransaction(t);
189
} catch (RootException e) {
190          //SharkUtilities.rollbackTransaction(t);
191
SharkUtilities.emptyCaches(t);
192          if (e instanceof BaseException)
193             throw (BaseException)e;
194          else
195             throw new BaseException(e);
196       } finally {
197          SharkUtilities.releaseTransaction(t);
198       }
199       return ret;
200    }
201
202    /**
203     * Method how_many_step
204     *
205     * @param t a SharkTransaction
206     *
207     * @return an int
208     *
209     * @exception BaseException
210     */

211    public int how_many_step (SharkTransaction t) throws BaseException {
212       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
213       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
214       if (sm!=null) {
215          try {
216             sm.check_process_how_many_step(t,
217                                            processId,
218                                            userAuth,
219                                            procInternal.requester(t).getResourceRequesterUsername(t));
220          } catch (Exception JavaDoc ex) {
221             throw new BaseException(ex);
222          }
223       }
224       return procInternal.how_many_step(t);
225    }
226
227    /**
228     * Retrieve the Iterator of active activities of this process.
229     *
230     * @return a WfActivityIterator
231     *
232     * @exception BaseException
233     */

234    public WfActivityIterator get_iterator_step () throws BaseException {
235       WfActivityIterator ret = null;
236       SharkTransaction t = null;
237       try {
238          t = SharkUtilities.createTransaction();
239          ret = get_iterator_step(t);
240          //SharkUtilities.commitTransaction(t);
241
} catch (RootException e) {
242          //SharkUtilities.rollbackTransaction(t);
243
SharkUtilities.emptyCaches(t);
244          if (e instanceof BaseException)
245             throw (BaseException)e;
246          else
247             throw new BaseException(e);
248       } finally {
249          SharkUtilities.releaseTransaction(t);
250       }
251       return ret;
252    }
253
254    /**
255     * Method get_iterator_step
256     *
257     * @param t a SharkTransaction
258     *
259     * @return a WfActivityIterator
260     *
261     * @exception BaseException
262     */

263    public WfActivityIterator get_iterator_step (SharkTransaction t) throws BaseException {
264       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
265       if (sm!=null) {
266          WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
267          try {
268             sm.check_process_get_iterator_step(t,
269                                                processId,
270                                                userAuth,
271                                                procInternal.requester(t).getResourceRequesterUsername(t));
272          } catch (Exception JavaDoc ex) {
273             throw new BaseException(ex);
274          }
275       }
276       return SharkEngineManager.getInstance().getObjectFactory().createActivityIteratorWrapper(t,userAuth,processId);
277    }
278
279    /**
280     * Retrieve the List of activities of this process.
281     *
282     * @param max_number High limit of elements in the result set (0->all).
283     *
284     * @return a WfActivity[]
285     *
286     * @exception BaseException
287     */

288    public WfActivity[] get_sequence_step (int max_number) throws BaseException {
289       WfActivity[] ret = null;
290       SharkTransaction t = null;
291       try {
292          t = SharkUtilities.createTransaction();
293          ret = get_sequence_step(t, max_number);
294          //SharkUtilities.commitTransaction(t);
295
} catch (RootException e) {
296          //SharkUtilities.rollbackTransaction(t);
297
SharkUtilities.emptyCaches(t);
298          if (e instanceof BaseException)
299             throw (BaseException)e;
300          else
301             throw new BaseException(e);
302       } finally {
303          SharkUtilities.releaseTransaction(t);
304       }
305       return ret;
306    }
307
308    /**
309     * Method get_sequence_step
310     *
311     * @param t a SharkTransaction
312     * @param max_number an int
313     *
314     * @return a WfActivity[]
315     *
316     * @exception BaseException
317     *
318     */

319    public WfActivity[] get_sequence_step (SharkTransaction t,int max_number) throws BaseException {
320       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
321       if (sm!=null) {
322          WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
323          try {
324             sm.check_process_get_sequence_step(t,
325                                                processId,
326                                                userAuth,
327                                                procInternal.requester(t).getResourceRequesterUsername(t));
328          } catch (Exception JavaDoc ex) {
329             throw new BaseException(ex);
330          }
331       }
332
333       // TODO: see OMG/WfMC docu which acitivities to consider:
334
// all or active ones only
335
List JavaDoc alist = SharkUtilities.createProcessActivityWrappers(t,userAuth,processId);
336       if (max_number > alist.size() || max_number<=0) {
337          max_number = alist.size();
338       }
339       WfActivity[] ret = new WfActivity[max_number];
340       alist.subList(0, max_number).toArray(ret);
341       return ret;
342    }
343
344    /**
345     * Check if some activity is a member of this process.
346     *
347     * @param member a WfActivity
348     *
349     * @return true if the specific activity is a member of this process,
350     * false otherwise.
351     *
352     * @exception BaseException
353     */

354    public boolean is_member_of_step (WfActivity member) throws BaseException {
355       boolean ret = false;
356       SharkTransaction t = null;
357       try {
358          t = SharkUtilities.createTransaction();
359          ret = is_member_of_step(t, member);
360          //SharkUtilities.commitTransaction(t);
361
} catch (RootException e) {
362          //SharkUtilities.rollbackTransaction(t);
363
SharkUtilities.emptyCaches(t);
364          if (e instanceof BaseException)
365             throw (BaseException)e;
366          else
367             throw new BaseException(e);
368       } finally {
369          SharkUtilities.releaseTransaction(t);
370       }
371       return ret;
372    }
373
374    /**
375     * Method is_member_of_step
376     *
377     * @param t a SharkTransaction
378     * @param member a WfActivity
379     *
380     * @return a boolean
381     *
382     * @exception BaseException
383     */

384    public boolean is_member_of_step (SharkTransaction t,WfActivity member) throws BaseException {
385       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
386       if (sm!=null) {
387          WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
388          try {
389             sm.check_process_is_member_of_step(t,
390                                                processId,
391                                                userAuth,
392                                                procInternal.requester(t).getResourceRequesterUsername(t));
393          } catch (Exception JavaDoc ex) {
394             throw new BaseException(ex);
395          }
396       }
397       String JavaDoc pId=member.container(t).key(t);
398       return pId.equals(this.processId);
399    }
400
401    /**
402     * Retrieve the WfProcessMgr of this process.
403     *
404     * @return a WfProcessMgr
405     *
406     * @exception BaseException
407     */

408    public WfProcessMgr manager () throws BaseException {
409       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
410       if (sm==null) {
411          return SharkEngineManager
412          .getInstance()
413          .getObjectFactory()
414          .createProcessMgrWrapper(userAuth,mgrName);
415       }
416       WfProcessMgr ret = null;
417       SharkTransaction t = null;
418       try {
419          t = SharkUtilities.createTransaction();
420          ret = manager(t);
421          //SharkUtilities.commitTransaction(t);
422
} catch (RootException e) {
423          //SharkUtilities.rollbackTransaction(t);
424
SharkUtilities.emptyCaches(t);
425          if (e instanceof BaseException)
426             throw (BaseException)e;
427          else
428             throw new BaseException(e);
429       } finally {
430          SharkUtilities.releaseTransaction(t);
431       }
432       return ret;
433    }
434
435    /**
436     * Method manager
437     *
438     * @param t a SharkTransaction
439     *
440     * @return a WfProcessMgr
441     *
442     * @exception BaseException
443     */

444    public WfProcessMgr manager (SharkTransaction t) throws BaseException {
445       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
446       if (sm!=null) {
447          try {
448             WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
449             sm.check_process_manager(t,
450                                      processId,
451                                      userAuth,
452                                      procInternal.requester(t).getResourceRequesterUsername(t));
453          } catch (Exception JavaDoc ex) {
454             throw new BaseException(ex);
455          }
456       }
457       return SharkEngineManager
458          .getInstance()
459          .getObjectFactory()
460          .createProcessMgrWrapper(userAuth,mgrName);
461    }
462
463    /**
464     * Retrieve the result for this process.
465     *
466     * @return a Map
467     *
468     * @exception BaseException
469     * @exception ResultNotAvailable
470     *
471     */

472    public Map JavaDoc result () throws BaseException, ResultNotAvailable {
473       Map JavaDoc ret = null;
474       SharkTransaction t = null;
475       try {
476          t = SharkUtilities.createTransaction();
477          ret = result(t);
478          //SharkUtilities.commitTransaction(t);
479
} catch (RootException e) {
480          //SharkUtilities.rollbackTransaction(t);
481
SharkUtilities.emptyCaches(t);
482          if (e instanceof ResultNotAvailable)
483             throw (ResultNotAvailable)e;
484          else if (e instanceof BaseException)
485             throw (BaseException)e;
486          else
487             throw new BaseException(e);
488       } finally {
489          SharkUtilities.releaseTransaction(t);
490       }
491       return ret;
492    }
493
494    /**
495     * Method result
496     *
497     * @param t a SharkTransaction
498     *
499     * @return a Map
500     *
501     * @exception BaseException
502     * @exception ResultNotAvailable
503     */

504    public Map JavaDoc result (SharkTransaction t) throws BaseException, ResultNotAvailable {
505       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
506       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
507       if (sm!=null) {
508          try {
509             sm.check_process_result(t,
510                                     processId,
511                                     userAuth,
512                                     procInternal.requester(t).getResourceRequesterUsername(t));
513          } catch (Exception JavaDoc ex) {
514             throw new BaseException(ex);
515          }
516       }
517       return procInternal.result(t);
518    }
519
520    /**
521     * Starts the process - creates a separate thread.
522     *
523     * @exception BaseException
524     * @exception CannotStart
525     * @exception AlreadyRunning
526     */

527    public void start() throws BaseException, CannotStart, AlreadyRunning {
528       SharkTransaction t = null;
529       try {
530          t = SharkUtilities.createTransaction();
531          start(t);
532          SharkUtilities.commitTransaction(t);
533       } catch (RootException e) {
534          SharkUtilities.rollbackTransaction(t,e);
535          if (e instanceof CannotStart)
536             throw (CannotStart)e;
537          else if (e instanceof AlreadyRunning)
538             throw (AlreadyRunning)e;
539          else if (e instanceof BaseException)
540             throw (BaseException)e;
541          else
542             throw new BaseException(e);
543       } finally {
544          SharkUtilities.releaseTransaction(t);
545       }
546    }
547
548    /**
549     * Method start
550     *
551     * @param t a SharkTransaction
552     *
553     * @exception BaseException
554     * @exception CannotStart
555     * @exception AlreadyRunning
556     */

557    public void start(SharkTransaction t) throws BaseException, CannotStart, AlreadyRunning {
558       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
559       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
560       if (sm!=null) {
561          try {
562             sm.check_process_start(t,
563                                    processId,
564                                    userAuth,
565                                    procInternal.requester(t).getResourceRequesterUsername(t));
566          } catch (Exception JavaDoc ex) {
567             throw new BaseException(ex);
568          }
569       }
570       try {
571          procInternal.start(t);
572       } catch (ToolAgentGeneralException tage) {
573          throw new BaseException(tage);
574       }
575    }
576
577    /**
578     * Retrieve the iterator of activities in some specific state.
579     *
580     * @param state a String
581     *
582     * @return a WfActivityIterator
583     *
584     * @exception BaseException
585     * @exception InvalidState
586     */

587    public WfActivityIterator get_activities_in_state (String JavaDoc state) throws BaseException, InvalidState {
588       WfActivityIterator ret = null;
589       SharkTransaction t = null;
590       try {
591          t = SharkUtilities.createTransaction();
592          ret = get_activities_in_state(t, state);
593          //SharkUtilities.commitTransaction(t);
594
} catch (RootException e) {
595          //SharkUtilities.rollbackTransaction(t);
596
SharkUtilities.emptyCaches(t);
597          if (e instanceof InvalidState)
598             throw (InvalidState)e;
599          else if (e instanceof BaseException)
600             throw (BaseException)e;
601          else
602             throw new BaseException(e);
603       } finally {
604          SharkUtilities.releaseTransaction(t);
605       }
606       return ret;
607    }
608
609    /**
610     * Method get_activities_in_state
611     *
612     * @param t a SharkTransaction
613     * @param state a String
614     *
615     * @return a WfActivityIterator
616     *
617     * @exception BaseException
618     * @exception InvalidState
619     */

620    public WfActivityIterator get_activities_in_state (SharkTransaction t,String JavaDoc state) throws BaseException, InvalidState {
621       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
622       if (sm!=null) {
623          WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
624          try {
625             sm.check_process_get_activities_in_state(t,
626                                                      processId,
627                                                      userAuth,
628                                                      procInternal.requester(t).getResourceRequesterUsername(t));
629          } catch (Exception JavaDoc ex) {
630             throw new BaseException(ex);
631          }
632       }
633       if (!SharkConstants.possibleActivityStates.contains(state)) {
634          throw new InvalidState("The activity state "+state+" is not valid - can't get activities in such state!");
635       }
636
637       WfActivityIterator ret = SharkEngineManager.getInstance().getObjectFactory().createActivityIteratorWrapper(t,userAuth, processId);
638       try {
639          ret.set_query_expression(t, SharkConstants.QUERY_STATE_PREFIX+"state.equals(\""+state+"\")");
640       } catch (InvalidQuery iq) {
641          throw new BaseException(iq);
642       }
643       return ret;
644    }
645
646    /**
647     * Method workflow_state
648     *
649     * @return a workflow_stateType
650     *
651     * @exception BaseException
652     */

653    public workflow_stateType workflow_state () throws BaseException {
654       workflow_stateType ret = null;
655       SharkTransaction t = null;
656       try {
657          t = SharkUtilities.createTransaction();
658          ret = workflow_state(t);
659          //SharkUtilities.commitTransaction(t);
660
} catch (RootException e) {
661          //SharkUtilities.rollbackTransaction(t);
662
SharkUtilities.emptyCaches(t);
663          if (e instanceof BaseException)
664             throw (BaseException)e;
665          else
666             throw new BaseException(e);
667       } finally {
668          SharkUtilities.releaseTransaction(t);
669       }
670       return ret;
671    }
672
673    /**
674     * Method workflow_state
675     *
676     * @param t a SharkTransaction
677     *
678     * @return a workflow_stateType
679     *
680     * @exception BaseException
681     */

682    public workflow_stateType workflow_state (SharkTransaction t) throws BaseException {
683       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
684       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
685       if (sm!=null) {
686          try {
687             sm.check_process_workflow_state(t,
688                                             processId,
689                                             userAuth,
690                                             procInternal.requester(t).getResourceRequesterUsername(t));
691          } catch (Exception JavaDoc ex) {
692             throw new BaseException(ex);
693          }
694       }
695       String JavaDoc state=procInternal.state(t);
696       if (state.startsWith(SharkConstants.STATEPREFIX_CLOSED)) {
697          return workflow_stateType.closed;
698       } else {
699          return workflow_stateType.open;
700       }
701    }
702
703    public while_openType while_open () throws BaseException {
704       while_openType ret = null;
705       SharkTransaction t = null;
706       try {
707          t = SharkUtilities.createTransaction();
708          ret = while_open(t);
709          //SharkUtilities.commitTransaction(t);
710
} catch (RootException e) {
711          //SharkUtilities.rollbackTransaction(t);
712
SharkUtilities.emptyCaches(t);
713          if (e instanceof BaseException)
714             throw (BaseException)e;
715          else
716             throw new BaseException(e);
717       } finally {
718          SharkUtilities.releaseTransaction(t);
719       }
720       return ret;
721    }
722
723    /**
724     * Method while_open
725     *
726     * @param t a SharkTransaction
727     *
728     * @return a while_openType
729     *
730     * @exception BaseException
731     */

732    public while_openType while_open (SharkTransaction t) throws BaseException {
733       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
734       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
735       if (sm!=null) {
736          try {
737             sm.check_process_while_open(t,
738                                         processId,
739                                         userAuth,
740                                         procInternal.requester(t).getResourceRequesterUsername(t));
741          } catch (Exception JavaDoc ex) {
742             throw new BaseException(ex);
743          }
744       }
745       String JavaDoc state=procInternal.state(t);
746       if (state.equals(SharkConstants.STATE_OPEN_RUNNING)) {
747          return while_openType.running;
748       } else {
749          return while_openType.not_running;
750       }
751    }
752
753    /**
754     * Method why_not_running
755     *
756     * @return a why_not_runningType
757     *
758     * @exception BaseException
759     */

760    public why_not_runningType why_not_running () throws BaseException {
761       why_not_runningType ret = null;
762       SharkTransaction t = null;
763       try {
764          t = SharkUtilities.createTransaction();
765          ret = why_not_running(t);
766          //SharkUtilities.commitTransaction(t);
767
} catch (RootException e) {
768          //SharkUtilities.rollbackTransaction(t);
769
SharkUtilities.emptyCaches(t);
770          if (e instanceof BaseException)
771             throw (BaseException)e;
772          else
773             throw new BaseException(e);
774       } finally {
775          SharkUtilities.releaseTransaction(t);
776       }
777       return ret;
778    }
779
780    /**
781     * Method why_not_running
782     *
783     * @param t a SharkTransaction
784     *
785     * @return a why_not_runningType
786     *
787     * @exception BaseException
788     */

789    public why_not_runningType why_not_running (SharkTransaction t) throws BaseException {
790       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
791       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
792       if (sm!=null) {
793          try {
794             sm.check_process_why_not_running(t,
795                                              processId,
796                                              userAuth,
797                                              procInternal.requester(t).getResourceRequesterUsername(t));
798          } catch (Exception JavaDoc ex) {
799             throw new BaseException(ex);
800          }
801       }
802
803       String JavaDoc state=procInternal.state(t);
804       if (state.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED)) {
805          return why_not_runningType.suspended;
806       } else {
807          return why_not_runningType.not_started;
808       }
809    }
810
811    /**
812     * Method how_closed
813     *
814     * @return a how_closedType
815     *
816     * @exception BaseException
817     */

818    public how_closedType how_closed () throws BaseException {
819       how_closedType ret = null;
820       SharkTransaction t = null;
821       try {
822          t = SharkUtilities.createTransaction();
823          ret = how_closed(t);
824          //SharkUtilities.commitTransaction(t);
825
} catch (RootException e) {
826          //SharkUtilities.rollbackTransaction(t);
827
SharkUtilities.emptyCaches(t);
828          if (e instanceof BaseException)
829             throw (BaseException)e;
830          else
831             throw new BaseException(e);
832       } finally {
833          SharkUtilities.releaseTransaction(t);
834       }
835       return ret;
836    }
837
838    /**
839     * Method how_closed
840     *
841     * @param t a SharkTransaction
842     *
843     * @return a how_closedType
844     *
845     * @exception BaseException
846     */

847    public how_closedType how_closed (SharkTransaction t) throws BaseException {
848       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
849       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
850       if (sm!=null) {
851          try {
852             sm.check_process_how_closed(t,
853                                         processId,
854                                         userAuth,
855                                         procInternal.requester(t).getResourceRequesterUsername(t));
856          } catch (Exception JavaDoc ex) {
857             throw new BaseException(ex);
858          }
859       }
860       String JavaDoc state=procInternal.state(t);
861       if (state.equals(SharkConstants.STATE_CLOSED_COMPLETED)) {
862          return how_closedType.completed;
863       } else if (state.equals(SharkConstants.STATE_CLOSED_TERMINATED)) {
864          return how_closedType.terminated;
865       } else {
866          return how_closedType.aborted;
867       }
868    }
869
870    /**
871     * Method valid_states
872     *
873     * @return a String[]
874     *
875     * @exception BaseException
876     */

877    public String JavaDoc[] valid_states () throws BaseException {
878       String JavaDoc[] ret = null;
879       SharkTransaction t = null;
880       try {
881          t = SharkUtilities.createTransaction();
882          ret = valid_states(t);
883          //SharkUtilities.commitTransaction(t);
884
} catch (RootException e) {
885          //SharkUtilities.rollbackTransaction(t);
886
SharkUtilities.emptyCaches(t);
887          if (e instanceof BaseException)
888             throw (BaseException)e;
889          else
890             throw new BaseException(e);
891       } finally {
892          SharkUtilities.releaseTransaction(t);
893       }
894       return ret;
895    }
896
897    /**
898     * Method valid_states
899     *
900     * @param t a SharkTransaction
901     *
902     * @return a String[]
903     *
904     * @exception BaseException
905     */

906    public String JavaDoc[] valid_states (SharkTransaction t) throws BaseException {
907       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
908       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
909       if (sm!=null) {
910          try {
911             sm.check_process_valid_states(t,
912                                           processId,
913                                           userAuth,
914                                           procInternal.requester(t).getResourceRequesterUsername(t));
915          } catch (Exception JavaDoc ex) {
916             throw new BaseException(ex);
917          }
918       }
919       List JavaDoc vs=SharkUtilities.valid_process_states(procInternal.state(t));
920       String JavaDoc[] vss=new String JavaDoc[vs.size()];
921       vs.toArray(vss);
922       return vss;
923    }
924
925    /**
926     * Method state
927     *
928     * @return a String
929     *
930     * @exception BaseException
931     */

932    public String JavaDoc state () throws BaseException {
933       String JavaDoc ret = null;
934       SharkTransaction t = null;
935       try {
936          t = SharkUtilities.createTransaction();
937          ret = state(t);
938          //SharkUtilities.commitTransaction(t);
939
} catch (RootException e) {
940          //SharkUtilities.rollbackTransaction(t);
941
SharkUtilities.emptyCaches(t);
942          if (e instanceof BaseException)
943             throw (BaseException)e;
944          else
945             throw new BaseException(e);
946       } finally {
947          SharkUtilities.releaseTransaction(t);
948       }
949       return ret;
950    }
951
952    /**
953     * Method state
954     *
955     * @param t a SharkTransaction
956     *
957     * @return a String
958     *
959     * @exception BaseException
960     */

961    public String JavaDoc state (SharkTransaction t) throws BaseException {
962       WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
963       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
964       if (sm!=null) {
965          try {
966             sm.check_process_state(t,
967                                    processId,
968                                    userAuth,
969                                    procInternal.requester(t).getResourceRequesterUsername(t));
970          } catch (Exception JavaDoc ex) {
971             throw new BaseException(ex);
972          }
973       }
974       return procInternal.state(t);
975    }
976
977    /**
978     * Method change_state
979     *
980     * @param new_state a String
981     *
982     * @exception BaseException
983     * @exception InvalidState
984     * @exception TransitionNotAllowed
985     */

986    public void change_state (String JavaDoc new_state) throws BaseException, InvalidState, TransitionNotAllowed {
987       SharkTransaction t = null;
988       try {
989          t = SharkUtilities.createTransaction();
990          change_state(t, new_state);
991          SharkUtilities.commitTransaction(t);
992       } catch (RootException e) {
993          SharkUtilities.rollbackTransaction(t,e);
994          if (e instanceof InvalidState)
995             throw (InvalidState)e;
996          else if (e instanceof TransitionNotAllowed)
997             throw (TransitionNotAllowed)e;
998          else if (e instanceof BaseException)
999             throw (BaseException)e;
1000         else
1001            throw new BaseException(e);
1002      } finally {
1003         SharkUtilities.releaseTransaction(t);
1004      }
1005   }
1006
1007   /**
1008    * Method change_state
1009    *
1010    * @param t a SharkTransaction
1011    * @param new_state a String
1012    *
1013    * @exception BaseException
1014    * @exception InvalidState
1015    * @exception TransitionNotAllowed
1016    */

1017   public void change_state (SharkTransaction t,String JavaDoc new_state) throws BaseException, InvalidState, TransitionNotAllowed {
1018      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1019      String JavaDoc curState=procInternal.state(t);
1020      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1021      if (sm!=null) {
1022         try {
1023            sm.check_process_change_state(t,
1024                                          processId,
1025                                          userAuth,
1026                                          procInternal.requester(t).getResourceRequesterUsername(t),
1027                                          curState,
1028                                          new_state);
1029         } catch (Exception JavaDoc ex) {
1030            throw new BaseException(ex);
1031         }
1032      }
1033
1034      if (!SharkConstants.possibleProcessStates.contains(new_state)) {
1035         throw new InvalidState("Can't change process state to "+new_state+" - no such state!");
1036      }
1037      if (!SharkUtilities.valid_process_states(procInternal.state(t)).contains(new_state)) {
1038         throw new TransitionNotAllowed("Current process state is "+curState+" - can't change to state "+new_state+"!");
1039      }
1040      if (new_state.equals(SharkConstants.STATE_CLOSED_ABORTED)) {
1041         try {
1042            procInternal.abort(t);
1043         } catch (CannotStop cns) {
1044            throw new TransitionNotAllowed(cns);
1045         } catch (NotRunning nr) {
1046            throw new TransitionNotAllowed(nr);
1047         }
1048      } else if (new_state.equals(SharkConstants.STATE_CLOSED_COMPLETED)) {
1049         throw new TransitionNotAllowed("Current process state is "+curState+" - can't change to state "+new_state+"!");
1050      } else if (new_state.equals(SharkConstants.STATE_CLOSED_TERMINATED)) {
1051         try {
1052            procInternal.terminate(t);
1053         } catch (CannotStop cns) {
1054            throw new TransitionNotAllowed(cns);
1055         } catch (NotRunning nr) {
1056            throw new TransitionNotAllowed(nr);
1057         }
1058      } else if (new_state.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED)) {
1059         throw new TransitionNotAllowed("Current process state is "+curState+" - can't change to state "+new_state+"!");
1060      } else if (new_state.equals(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED)) {
1061         try {
1062            procInternal.suspend(t);
1063         } catch (AlreadySuspended as) {
1064            throw new TransitionNotAllowed(as);
1065         } catch (CannotSuspend cns) {
1066            throw new TransitionNotAllowed(cns);
1067         } catch (NotRunning nr) {
1068            throw new TransitionNotAllowed(nr);
1069         }
1070      } else { //new state is open.running
1071
try {
1072            procInternal.start(t);
1073         } catch (CannotStart cns) {
1074            throw new TransitionNotAllowed(cns);
1075         } catch (AlreadyRunning ar) {
1076            throw new TransitionNotAllowed(ar);
1077         } catch (ToolAgentGeneralException tage) {
1078            throw new BaseException(tage);
1079         }
1080      }
1081   }
1082
1083   /**
1084    * Method name
1085    *
1086    * @return a String
1087    *
1088    * @exception BaseException
1089    */

1090   public String JavaDoc name () throws BaseException {
1091      String JavaDoc ret = null;
1092      SharkTransaction t = null;
1093      try {
1094         t = SharkUtilities.createTransaction();
1095         ret = name(t);
1096         //SharkUtilities.commitTransaction(t);
1097
} catch (RootException e) {
1098         //SharkUtilities.rollbackTransaction(t);
1099
SharkUtilities.emptyCaches(t);
1100         if (e instanceof BaseException)
1101            throw (BaseException)e;
1102         else
1103            throw new BaseException(e);
1104      } finally {
1105         SharkUtilities.releaseTransaction(t);
1106      }
1107      return ret;
1108   }
1109
1110   /**
1111    * Method name
1112    *
1113    * @param t a SharkTransaction
1114    *
1115    * @return a String
1116    *
1117    * @exception BaseException
1118    */

1119   public String JavaDoc name (SharkTransaction t) throws BaseException {
1120      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1121      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1122      if (sm!=null) {
1123         try {
1124            sm.check_process_name(t,
1125                                  processId,
1126                                  userAuth,
1127                                  procInternal.requester(t).getResourceRequesterUsername(t));
1128         } catch (Exception JavaDoc ex) {
1129            throw new BaseException(ex);
1130         }
1131      }
1132      return procInternal.name(t);
1133   }
1134
1135   /**
1136    * Method set_name
1137    *
1138    * @param new_value a String
1139    *
1140    * @exception BaseException
1141    */

1142   public void set_name (String JavaDoc new_value) throws BaseException {
1143      SharkTransaction t = null;
1144      try {
1145         t = SharkUtilities.createTransaction();
1146         set_name(t, new_value);
1147         SharkUtilities.commitTransaction(t);
1148      } catch (RootException e) {
1149         SharkUtilities.rollbackTransaction(t,e);
1150         if (e instanceof BaseException)
1151            throw (BaseException)e;
1152         else
1153            throw new BaseException(e);
1154      } finally {
1155         SharkUtilities.releaseTransaction(t);
1156      }
1157   }
1158
1159   /**
1160    * Method set_name
1161    *
1162    * @param t a SharkTransaction
1163    * @param new_value a String
1164    *
1165    * @exception BaseException
1166    */

1167   public void set_name (SharkTransaction t,String JavaDoc new_value) throws BaseException {
1168      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1169      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1170      if (sm!=null) {
1171         try {
1172            sm.check_process_set_name(t,
1173                                      processId,
1174                                      userAuth,
1175                                      procInternal.requester(t).getResourceRequesterUsername(t));
1176         } catch (Exception JavaDoc ex) {
1177            throw new BaseException(ex);
1178         }
1179      }
1180      procInternal.set_name(t, new_value);
1181   }
1182
1183   /**
1184    * Method key
1185    *
1186    * @return a String
1187    *
1188    * @exception BaseException
1189    */

1190   public String JavaDoc key () throws BaseException {
1191      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1192      if (sm==null) {
1193         return processId;
1194      }
1195      String JavaDoc ret = null;
1196      SharkTransaction t = null;
1197      try {
1198         t = SharkUtilities.createTransaction();
1199         ret = key(t);
1200         //SharkUtilities.commitTransaction(t);
1201
} catch (RootException e) {
1202         //SharkUtilities.rollbackTransaction(t);
1203
SharkUtilities.emptyCaches(t);
1204         if (e instanceof BaseException)
1205            throw (BaseException)e;
1206         else
1207            throw new BaseException(e);
1208      } finally {
1209         SharkUtilities.releaseTransaction(t);
1210      }
1211      return ret;
1212   }
1213
1214   /**
1215    * Method key
1216    *
1217    * @param t a SharkTransaction
1218    *
1219    * @return a String
1220    *
1221    * @exception BaseException
1222    */

1223   public String JavaDoc key (SharkTransaction t) throws BaseException {
1224      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1225      if (sm!=null) {
1226         WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1227         try {
1228            sm.check_process_key(t,
1229                                 processId,
1230                                 userAuth,
1231                                 procInternal.requester(t).getResourceRequesterUsername(t));
1232         } catch (Exception JavaDoc ex) {
1233            throw new BaseException(ex);
1234         }
1235      }
1236      return processId;
1237   }
1238
1239   /**
1240    * Method description
1241    *
1242    * @return a String
1243    *
1244    * @exception BaseException
1245    */

1246   public String JavaDoc description () throws BaseException {
1247      String JavaDoc ret = null;
1248      SharkTransaction t = null;
1249      try {
1250         t = SharkUtilities.createTransaction();
1251         ret = description(t);
1252         //SharkUtilities.commitTransaction(t);
1253
} catch (RootException e) {
1254         //SharkUtilities.rollbackTransaction(t);
1255
SharkUtilities.emptyCaches(t);
1256         if (e instanceof BaseException)
1257            throw (BaseException)e;
1258         else
1259            throw new BaseException(e);
1260      } finally {
1261         SharkUtilities.releaseTransaction(t);
1262      }
1263      return ret;
1264   }
1265
1266   /**
1267    * Method description
1268    *
1269    * @param t a SharkTransaction
1270    *
1271    * @return a String
1272    *
1273    * @exception BaseException
1274    */

1275   public String JavaDoc description (SharkTransaction t) throws BaseException {
1276      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1277      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1278      if (sm!=null) {
1279         try {
1280            sm.check_process_description(t,
1281                                         processId,
1282                                         userAuth,
1283                                         procInternal.requester(t).getResourceRequesterUsername(t));
1284         } catch (Exception JavaDoc ex) {
1285            throw new BaseException(ex);
1286         }
1287      }
1288      return procInternal.description(t);
1289   }
1290
1291   /**
1292    * Method set_description
1293    *
1294    * @param new_value a String
1295    *
1296    * @exception BaseException
1297    */

1298   public void set_description (String JavaDoc new_value) throws BaseException {
1299      SharkTransaction t = null;
1300      try {
1301         t = SharkUtilities.createTransaction();
1302         set_description(t, new_value);
1303         SharkUtilities.commitTransaction(t);
1304      } catch (RootException e) {
1305         SharkUtilities.rollbackTransaction(t,e);
1306         if (e instanceof BaseException)
1307            throw (BaseException)e;
1308         else
1309            throw new BaseException(e);
1310      } finally {
1311         SharkUtilities.releaseTransaction(t);
1312      }
1313   }
1314
1315   /**
1316    * Method set_description
1317    *
1318    * @param t a SharkTransaction
1319    * @param new_value a String
1320    *
1321    * @exception BaseException
1322    */

1323   public void set_description (SharkTransaction t,String JavaDoc new_value) throws BaseException {
1324      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1325      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1326      if (sm!=null) {
1327         try {
1328            sm.check_process_set_description(t,
1329                                             processId,
1330                                             userAuth,
1331                                             procInternal.requester(t).getResourceRequesterUsername(t));
1332         } catch (Exception JavaDoc ex) {
1333            throw new BaseException(ex);
1334         }
1335      }
1336
1337      procInternal.set_description(t, new_value);
1338   }
1339
1340   /**
1341    * Method process_context
1342    *
1343    * @return a Map
1344    *
1345    * @exception BaseException
1346    */

1347   public Map JavaDoc process_context () throws BaseException {
1348      Map JavaDoc ret = null;
1349      SharkTransaction t = null;
1350      try {
1351         t = SharkUtilities.createTransaction();
1352         ret = process_context(t);
1353         //SharkUtilities.commitTransaction(t);
1354
} catch (RootException e) {
1355         //SharkUtilities.rollbackTransaction(t);
1356
SharkUtilities.emptyCaches(t);
1357         if (e instanceof BaseException)
1358            throw (BaseException)e;
1359         else
1360            throw new BaseException(e);
1361      } finally {
1362         SharkUtilities.releaseTransaction(t);
1363      }
1364      return ret;
1365   }
1366
1367   /**
1368    * Method process_context
1369    *
1370    * @param t a SharkTransaction
1371    *
1372    * @return a Map
1373    *
1374    * @exception BaseException
1375    */

1376   public Map JavaDoc process_context (SharkTransaction t) throws BaseException {
1377      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1378      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1379      if (sm!=null) {
1380         try {
1381            sm.check_process_process_context(t,
1382                                             processId,
1383                                             userAuth,
1384                                             procInternal.requester(t).getResourceRequesterUsername(t));
1385         } catch (Exception JavaDoc ex) {
1386            throw new BaseException(ex);
1387         }
1388      }
1389      return procInternal.process_context(t);
1390   }
1391
1392   /**
1393    * Method set_process_context
1394    *
1395    * @param new_value a Map
1396    *
1397    * @exception BaseException
1398    * @exception InvalidData
1399    * @exception UpdateNotAllowed
1400    */

1401   public void set_process_context (Map JavaDoc new_value) throws BaseException, InvalidData, UpdateNotAllowed {
1402      SharkTransaction t = null;
1403      try {
1404         t = SharkUtilities.createTransaction();
1405         set_process_context(t, new_value);
1406         SharkUtilities.commitTransaction(t);
1407      } catch (RootException e) {
1408         SharkUtilities.rollbackTransaction(t,e);
1409         if (e instanceof InvalidData)
1410            throw (InvalidData)e;
1411         else if (e instanceof UpdateNotAllowed)
1412            throw (UpdateNotAllowed)e;
1413         else if (e instanceof BaseException)
1414            throw (BaseException)e;
1415         else
1416            throw new BaseException(e);
1417      } finally {
1418         SharkUtilities.releaseTransaction(t);
1419      }
1420   }
1421
1422   /**
1423    * Method set_process_context
1424    *
1425    * @param t a SharkTransaction
1426    * @param new_value a Map
1427    *
1428    * @exception BaseException
1429    * @exception InvalidData
1430    * @exception UpdateNotAllowed
1431    */

1432   public void set_process_context (SharkTransaction t,Map JavaDoc new_value) throws BaseException, InvalidData, UpdateNotAllowed {
1433      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1434      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1435      if (sm!=null) {
1436         try {
1437            sm.check_process_set_process_context(t,
1438                                                 processId,
1439                                                 userAuth,
1440                                                 procInternal.requester(t).getResourceRequesterUsername(t));
1441         } catch (Exception JavaDoc ex) {
1442            throw new BaseException(ex);
1443         }
1444      }
1445
1446      procInternal.set_process_context(t, new_value);
1447   }
1448
1449   /**
1450    * Method priority
1451    *
1452    * @return a short
1453    *
1454    * @exception BaseException
1455    */

1456   public short priority () throws BaseException {
1457      short ret = -1;
1458      SharkTransaction t = null;
1459      try {
1460         t = SharkUtilities.createTransaction();
1461         ret = priority(t);
1462         //SharkUtilities.commitTransaction(t);
1463
} catch (RootException e) {
1464         //SharkUtilities.rollbackTransaction(t);
1465
SharkUtilities.emptyCaches(t);
1466         if (e instanceof BaseException)
1467            throw (BaseException)e;
1468         else
1469            throw new BaseException(e);
1470      } finally {
1471         SharkUtilities.releaseTransaction(t);
1472      }
1473      return ret;
1474   }
1475
1476   /**
1477    * Method priority
1478    *
1479    * @param t a SharkTransaction
1480    *
1481    * @return a short
1482    *
1483    * @exception BaseException
1484    */

1485   public short priority (SharkTransaction t) throws BaseException {
1486      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1487      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1488      if (sm!=null) {
1489         try {
1490            sm.check_process_priority(t,
1491                                      processId,
1492                                      userAuth,
1493                                      procInternal.requester(t).getResourceRequesterUsername(t));
1494         } catch (Exception JavaDoc ex) {
1495            throw new BaseException(ex);
1496         }
1497      }
1498      return procInternal.priority(t);
1499   }
1500
1501   /**
1502    * Method set_priority
1503    *
1504    * @param new_value a short
1505    *
1506    * @exception BaseException
1507    */

1508   public void set_priority (short new_value) throws BaseException {
1509      SharkTransaction t = null;
1510      try {
1511         t = SharkUtilities.createTransaction();
1512         set_priority(t, new_value);
1513         SharkUtilities.commitTransaction(t);
1514      } catch (RootException e) {
1515         SharkUtilities.rollbackTransaction(t,e);
1516         if (e instanceof BaseException)
1517            throw (BaseException)e;
1518         else
1519            throw new BaseException(e);
1520      } finally {
1521         SharkUtilities.releaseTransaction(t);
1522      }
1523   }
1524
1525   /**
1526    * Method set_priority
1527    *
1528    * @param t a SharkTransaction
1529    * @param new_value a short
1530    *
1531    * @exception BaseException
1532    */

1533   public void set_priority (SharkTransaction t,short new_value) throws BaseException {
1534      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1535      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1536      if (sm!=null) {
1537         try {
1538            sm.check_process_set_priority(t,
1539                                          processId,
1540                                          userAuth,
1541                                          procInternal.requester(t).getResourceRequesterUsername(t));
1542         } catch (Exception JavaDoc ex) {
1543            throw new BaseException(ex);
1544         }
1545      }
1546
1547      procInternal.set_priority(t, new_value);
1548   }
1549
1550   /**
1551    * Resume this process.
1552    *
1553    * @exception BaseException
1554    * @exception CannotResume
1555    * @exception NotSuspended
1556    */

1557   public void resume() throws BaseException, CannotResume, NotSuspended {
1558      SharkTransaction t = null;
1559      try {
1560         t = SharkUtilities.createTransaction();
1561         resume(t);
1562         SharkUtilities.commitTransaction(t);
1563      } catch (RootException e) {
1564         SharkUtilities.rollbackTransaction(t,e);
1565         if (e instanceof CannotResume)
1566            throw (CannotResume)e;
1567         else if (e instanceof NotSuspended)
1568            throw (NotSuspended)e;
1569         else if (e instanceof BaseException)
1570            throw (BaseException)e;
1571         else
1572            throw new BaseException(e);
1573      } finally {
1574         SharkUtilities.releaseTransaction(t);
1575      }
1576   }
1577
1578   /**
1579    * Method resume
1580    *
1581    * @param t a SharkTransaction
1582    *
1583    * @exception BaseException
1584    * @exception CannotResume
1585    * @exception NotSuspended
1586    */

1587   public void resume(SharkTransaction t) throws BaseException, CannotResume, NotSuspended {
1588      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1589      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1590      if (sm!=null) {
1591         try {
1592            sm.check_process_resume(t,
1593                                    processId,
1594                                    userAuth,
1595                                    procInternal.requester(t).getResourceRequesterUsername(t));
1596         } catch (Exception JavaDoc ex) {
1597            throw new BaseException(ex);
1598         }
1599      }
1600
1601      procInternal.resume(t);
1602   }
1603
1604   /**
1605    * Suspend this process.
1606    *
1607    * @exception BaseException
1608    * @exception CannotSuspend
1609    * @exception NotRunning
1610    * @exception AlreadySuspended
1611    */

1612   public void suspend() throws BaseException, CannotSuspend, NotRunning, AlreadySuspended {
1613      SharkTransaction t = null;
1614      try {
1615         t = SharkUtilities.createTransaction();
1616         suspend(t);
1617         SharkUtilities.commitTransaction(t);
1618      } catch (RootException e) {
1619         SharkUtilities.rollbackTransaction(t,e);
1620         if (e instanceof CannotSuspend)
1621            throw (CannotSuspend)e;
1622         else if (e instanceof NotRunning)
1623            throw (NotRunning)e;
1624         else if (e instanceof AlreadySuspended)
1625            throw (AlreadySuspended)e;
1626         else if (e instanceof BaseException)
1627            throw (BaseException)e;
1628         else
1629            throw new BaseException(e);
1630      } finally {
1631         SharkUtilities.releaseTransaction(t);
1632      }
1633   }
1634
1635   /**
1636    * Method suspend
1637    *
1638    * @param t a SharkTransaction
1639    *
1640    * @exception BaseException
1641    * @exception CannotSuspend
1642    * @exception NotRunning
1643    * @exception AlreadySuspended
1644    */

1645   public void suspend(SharkTransaction t) throws BaseException, CannotSuspend, NotRunning, AlreadySuspended {
1646      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1647      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1648      if (sm!=null) {
1649         try {
1650            sm.check_process_suspend(t,
1651                                     processId,
1652                                     userAuth,
1653                                     procInternal.requester(t).getResourceRequesterUsername(t));
1654         } catch (Exception JavaDoc ex) {
1655            throw new BaseException(ex);
1656         }
1657      }
1658
1659      procInternal.suspend(t);
1660   }
1661
1662   /**
1663    * Terminate this process.
1664    *
1665    * @exception BaseException
1666    * @exception CannotStop
1667    * @exception NotRunning
1668    */

1669   public void terminate() throws BaseException, CannotStop, NotRunning {
1670      SharkTransaction t = null;
1671      try {
1672         t = SharkUtilities.createTransaction();
1673         terminate(t);
1674         SharkUtilities.commitTransaction(t);
1675      } catch (RootException e) {
1676         SharkUtilities.rollbackTransaction(t,e);
1677         if (e instanceof CannotStop)
1678            throw (CannotStop)e;
1679         else if (e instanceof NotRunning)
1680            throw (NotRunning)e;
1681         else if (e instanceof BaseException)
1682            throw (BaseException)e;
1683         else
1684            throw new BaseException(e);
1685      } finally {
1686         SharkUtilities.releaseTransaction(t);
1687      }
1688   }
1689
1690   /**
1691    * Method terminate
1692    *
1693    * @param t a SharkTransaction
1694    *
1695    * @exception BaseException
1696    * @exception CannotStop
1697    * @exception NotRunning
1698    */

1699   public void terminate(SharkTransaction t) throws BaseException, CannotStop, NotRunning {
1700      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1701      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1702      if (sm!=null) {
1703         try {
1704            sm.check_process_terminate(t,
1705                                       processId,
1706                                       userAuth,
1707                                       procInternal.requester(t).getResourceRequesterUsername(t));
1708         } catch (Exception JavaDoc ex) {
1709            throw new BaseException(ex);
1710         }
1711      }
1712
1713      procInternal.terminate(t);
1714   }
1715
1716   /**
1717    * Abort the execution of this process.
1718    *
1719    * @exception BaseException
1720    * @exception CannotStop
1721    * @exception NotRunning
1722    */

1723   public void abort() throws BaseException, CannotStop, NotRunning {
1724      SharkTransaction t = null;
1725      try {
1726         t = SharkUtilities.createTransaction();
1727         abort(t);
1728         SharkUtilities.commitTransaction(t);
1729      } catch (RootException e) {
1730         SharkUtilities.rollbackTransaction(t,e);
1731         if (e instanceof CannotStop)
1732            throw (CannotStop)e;
1733         else if (e instanceof NotRunning)
1734            throw (NotRunning)e;
1735         else if (e instanceof BaseException)
1736            throw (BaseException)e;
1737         else
1738            throw new BaseException(e);
1739      } finally {
1740         SharkUtilities.releaseTransaction(t);
1741      }
1742   }
1743
1744   /**
1745    * Method abort
1746    *
1747    * @param t a SharkTransaction
1748    *
1749    * @exception BaseException
1750    * @exception CannotStop
1751    * @exception NotRunning
1752    */

1753   public void abort(SharkTransaction t) throws BaseException, CannotStop, NotRunning {
1754      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1755      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1756      if (sm!=null) {
1757         try {
1758            sm.check_process_abort(t,
1759                                   processId,
1760                                   userAuth,
1761                                   procInternal.requester(t).getResourceRequesterUsername(t));
1762         } catch (Exception JavaDoc ex) {
1763            throw new BaseException(ex);
1764         }
1765      }
1766
1767      procInternal.abort(t);
1768   }
1769
1770   /**
1771    * Method how_many_history
1772    *
1773    * @return an int
1774    *
1775    * @exception BaseException
1776    * @exception HistoryNotAvailable
1777    */

1778   public int how_many_history() throws BaseException, HistoryNotAvailable {
1779      int ret = -1;
1780      SharkTransaction t = null;
1781      try {
1782         t = SharkUtilities.createTransaction();
1783         ret = how_many_history(t);
1784         //SharkUtilities.commitTransaction(t);
1785
} catch (RootException e) {
1786         //SharkUtilities.rollbackTransaction(t);
1787
SharkUtilities.emptyCaches(t);
1788         if (e instanceof HistoryNotAvailable)
1789            throw (HistoryNotAvailable)e;
1790         else if (e instanceof BaseException)
1791            throw (BaseException)e;
1792         else
1793            throw new BaseException(e);
1794      } finally {
1795         SharkUtilities.releaseTransaction(t);
1796      }
1797      return ret;
1798   }
1799
1800   /**
1801    * Method how_many_history
1802    *
1803    * @param t a SharkTransaction
1804    *
1805    * @return an int
1806    *
1807    * @exception BaseException
1808    * @exception HistoryNotAvailable
1809    */

1810   public int how_many_history(SharkTransaction t) throws BaseException, HistoryNotAvailable {
1811      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1812      if (sm!=null) {
1813         WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1814         try {
1815            sm.check_process_how_many_history(t,
1816                                              processId,
1817                                              userAuth,
1818                                              procInternal.requester(t).getResourceRequesterUsername(t));
1819         } catch (Exception JavaDoc ex) {
1820            throw new BaseException(ex);
1821         }
1822      }
1823
1824      try {
1825         EventAuditManagerInterface eam = SharkEngineManager
1826            .getInstance()
1827            .getEventAuditManager();
1828         if (null == eam)
1829            return 0;
1830         return eam.restoreProcessHistory(processId,t).size();
1831      } catch (Exception JavaDoc ex) {
1832         throw new BaseException(ex);
1833      }
1834   }
1835
1836   /**
1837    * Search in the history for specific elements.
1838    *
1839    * @param query a String
1840    * @param names_in_query a Map
1841    *
1842    * @return Found history elements that meet the search criteria.
1843    *
1844    * @exception BaseException
1845    * @exception HistoryNotAvailable
1846    */

1847   public WfEventAuditIterator get_iterator_history (String JavaDoc query, Map JavaDoc names_in_query) throws BaseException, HistoryNotAvailable {
1848      WfEventAuditIterator ret = null;
1849      SharkTransaction t = null;
1850      try {
1851         t = SharkUtilities.createTransaction();
1852         ret = get_iterator_history(t, query, names_in_query);
1853         //SharkUtilities.commitTransaction(t);
1854
} catch (RootException e) {
1855         //SharkUtilities.rollbackTransaction(t);
1856
SharkUtilities.emptyCaches(t);
1857         if (e instanceof HistoryNotAvailable)
1858            throw (HistoryNotAvailable)e;
1859         else if (e instanceof BaseException)
1860            throw (BaseException)e;
1861         else
1862            throw new BaseException(e);
1863      } finally {
1864         SharkUtilities.releaseTransaction(t);
1865      }
1866      return ret;
1867   }
1868
1869   /**
1870    * Method get_iterator_history
1871    *
1872    * @param t a SharkTransaction
1873    * @param query a String
1874    * @param names_in_query a Map
1875    *
1876    * @return a WfEventAuditIterator
1877    *
1878    * @exception BaseException
1879    * @exception HistoryNotAvailable
1880    */

1881   public WfEventAuditIterator get_iterator_history (SharkTransaction t,String JavaDoc query, Map JavaDoc names_in_query) throws BaseException, HistoryNotAvailable {
1882      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1883      if (sm!=null) {
1884         WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1885         try {
1886            sm.check_process_get_iterator_history(t,
1887                                                  processId,
1888                                                  userAuth,
1889                                                  procInternal.requester(t).getResourceRequesterUsername(t));
1890         } catch (Exception JavaDoc ex) {
1891            throw new BaseException(ex);
1892         }
1893      }
1894
1895      WfEventAuditIterator ret = SharkEngineManager.getInstance().getObjectFactory().createEventAuditIteratorWrapper(t,userAuth,processId);
1896      try {
1897         ret.set_query_expression(t, query);
1898         ret.set_names_in_expression(t, names_in_query);
1899      } catch (NameMismatch e) {
1900         throw new HistoryNotAvailable(e);
1901      } catch (InvalidQuery e) {
1902         throw new HistoryNotAvailable(e);
1903      }
1904      return ret;
1905   }
1906
1907   /**
1908    * Getter for history sequence.
1909    *
1910    * @param max_number an int
1911    *
1912    * @return List of History objects.
1913    *
1914    * @exception BaseException
1915    * @exception HistoryNotAvailable
1916    *
1917    */

1918   public WfEventAudit[] get_sequence_history (int max_number) throws BaseException, HistoryNotAvailable {
1919      WfEventAudit[] ret = null;
1920      SharkTransaction t = null;
1921      try {
1922         t = SharkUtilities.createTransaction();
1923         ret = get_sequence_history(t, max_number);
1924         //SharkUtilities.commitTransaction(t);
1925
} catch (RootException e) {
1926         //SharkUtilities.rollbackTransaction(t);
1927
SharkUtilities.emptyCaches(t);
1928         if (e instanceof HistoryNotAvailable)
1929            throw (HistoryNotAvailable)e;
1930         else if (e instanceof BaseException)
1931            throw (BaseException)e;
1932         else
1933            throw new BaseException(e);
1934      } finally {
1935         SharkUtilities.releaseTransaction(t);
1936      }
1937      return ret;
1938   }
1939
1940   /**
1941    * Method get_sequence_history
1942    *
1943    * @param t a SharkTransaction
1944    * @param max_number an int
1945    *
1946    * @return a WfEventAudit[]
1947    *
1948    * @exception BaseException
1949    * @exception HistoryNotAvailable
1950    */

1951   public WfEventAudit[] get_sequence_history (SharkTransaction t,int max_number) throws BaseException, HistoryNotAvailable {
1952      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
1953      if (sm!=null) {
1954         WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
1955         try {
1956            sm.check_process_get_sequence_history(t,
1957                                                  processId,
1958                                                  userAuth,
1959                                                  procInternal.requester(t).getResourceRequesterUsername(t));
1960         } catch (Exception JavaDoc ex) {
1961            throw new BaseException(ex);
1962         }
1963      }
1964
1965      List JavaDoc history=SharkUtilities.createProcessHistoryEvents(t,userAuth,processId);
1966      if (max_number>history.size() || max_number<=0) {
1967         max_number=history.size();
1968      }
1969      WfEventAudit[] eas=new WfEventAudit[max_number];
1970      history.subList(0,max_number).toArray(eas);
1971      return eas;
1972   }
1973
1974   /**
1975    * Checks if a 'member' is an element of the history.
1976    *
1977    * @param member a WfExecutionObject
1978    *
1979    * @return true if the element of the history, false otherwise.
1980    *
1981    * @exception BaseException
1982    */

1983   public boolean is_member_of_history (WfExecutionObject member) throws BaseException {
1984      boolean ret = false;
1985      SharkTransaction t = null;
1986      try {
1987         t = SharkUtilities.createTransaction();
1988         ret = is_member_of_history(t, member);
1989         //SharkUtilities.commitTransaction(t);
1990
} catch (RootException e) {
1991         //SharkUtilities.rollbackTransaction(t);
1992
SharkUtilities.emptyCaches(t);
1993         if (e instanceof BaseException)
1994            throw (BaseException)e;
1995         else
1996            throw new BaseException(e);
1997      } finally {
1998         SharkUtilities.releaseTransaction(t);
1999      }
2000      return ret;
2001   }
2002
2003   /**
2004    * Method is_member_of_history
2005    *
2006    * @param t a SharkTransaction
2007    * @param member a WfExecutionObject
2008    *
2009    * @return a boolean
2010    *
2011    * @exception BaseException
2012    */

2013   public boolean is_member_of_history (SharkTransaction t,WfExecutionObject member) throws BaseException {
2014      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
2015      if (sm!=null) {
2016         WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
2017         try {
2018            sm.check_process_is_member_of_history(t,
2019                                                  processId,
2020                                                  userAuth,
2021                                                  procInternal.requester(t).getResourceRequesterUsername(t));
2022         } catch (Exception JavaDoc ex) {
2023            throw new BaseException(ex);
2024         }
2025      }
2026
2027      boolean ret=false;
2028      List JavaDoc history=SharkUtilities.createProcessHistoryEvents(t,userAuth,processId);
2029      Iterator JavaDoc it=history.iterator();
2030      while (it.hasNext()) {
2031         WfEventAudit ea=(WfEventAudit)it.next();
2032         if (member instanceof WfActivity) {
2033            WfActivity act=(WfActivity)member;
2034            if (act.container(t).key(t).equals(ea.process_key()) &&
2035                act.key(t).equals(ea.activity_key())) {
2036               ret=true;
2037               break;
2038            }
2039         } else {
2040            if (member.key(t).equals(ea.process_key())) {
2041               ret=true;
2042               break;
2043            }
2044         }
2045      }
2046      return ret;
2047   }
2048
2049   /**
2050    * Method last_state_time
2051    *
2052    * @return an UtcT
2053    *
2054    * @exception BaseException
2055    */

2056   public UtcT last_state_time () throws BaseException {
2057      UtcT ret = null;
2058      SharkTransaction t = null;
2059      try {
2060         t = SharkUtilities.createTransaction();
2061         ret = last_state_time(t);
2062         //SharkUtilities.commitTransaction(t);
2063
} catch (RootException e) {
2064         //SharkUtilities.rollbackTransaction(t);
2065
SharkUtilities.emptyCaches(t);
2066         if (e instanceof BaseException)
2067            throw (BaseException)e;
2068         else
2069            throw new BaseException(e);
2070      } finally {
2071         SharkUtilities.releaseTransaction(t);
2072      }
2073      return ret;
2074   }
2075
2076   /**
2077    * Method last_state_time
2078    *
2079    * @param t a SharkTransaction
2080    *
2081    * @return an UtcT
2082    *
2083    * @exception BaseException
2084    */

2085   public UtcT last_state_time (SharkTransaction t) throws BaseException {
2086      WfProcessInternal procInternal=WfProcessWrapper.getProcessImpl(t,processId);
2087      SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
2088      if (sm!=null) {
2089         try {
2090            sm.check_process_last_state_time(t,
2091                                             processId,
2092                                             userAuth,
2093                                             procInternal.requester(t).getResourceRequesterUsername(t));
2094         } catch (Exception JavaDoc ex) {
2095            throw new BaseException(ex);
2096         }
2097      }
2098
2099      return procInternal.last_state_time(t);
2100   }
2101
2102   /**
2103    * Method toString
2104    *
2105    * @return a String
2106    */

2107   public String JavaDoc toString () {
2108      return "[key="+processId+"]";
2109   }
2110
2111   /**
2112    * It is assumed that there can't be two or more
2113    * processes having the same key.
2114    */

2115   public boolean equals (java.lang.Object JavaDoc obj) {
2116      if (!(obj instanceof WfProcess)) return false;
2117      WfProcess proc=(WfProcess)obj;
2118      try {
2119         if (obj instanceof WfProcessWrapper) {
2120            return ((WfProcessWrapper)obj).processId.equals(processId);
2121         } else {
2122            return proc.key().equals(processId);
2123         }
2124      } catch (Exception JavaDoc ex) {
2125         return false;
2126      }
2127   }
2128
2129   private static WfProcessInternal getProcessImpl (
2130      SharkTransaction t,
2131      String JavaDoc procId) throws BaseException {
2132      WfProcessInternal proc=SharkUtilities.getProcess(t,procId);
2133      if (proc==null) throw new BaseException("Process does not exist");
2134      return proc;
2135   }
2136
2137}
2138
2139
Popular Tags