KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark;
2
3 import org.enhydra.shark.api.client.wfmodel.*;
4
5 import java.util.List JavaDoc;
6 import java.util.Map JavaDoc;
7 import org.enhydra.shark.api.RootException;
8 import org.enhydra.shark.api.SharkTransaction;
9 import org.enhydra.shark.api.client.wfbase.BaseException;
10 import org.enhydra.shark.api.internal.security.SecurityManager;
11 import org.enhydra.shark.api.internal.working.WfProcessInternal;
12 import org.enhydra.shark.api.internal.working.WfProcessMgrInternal;
13 import org.enhydra.shark.api.internal.working.WfRequesterInternal;
14 import org.enhydra.shark.xpdl.XPDLConstants;
15 import org.enhydra.shark.xpdl.elements.WorkflowProcess;
16
17 /**
18  * WfProcessMgrImplWrapper - Workflow Process Manager implementation
19  * @author Sasa Bojanic
20  * @author Vladimir Puskas
21  */

22 public class WfProcessMgrWrapper implements WfProcessMgr {
23
24    private String JavaDoc userAuth;
25    private String JavaDoc name;
26    /**
27     * Creates new WfProcessMgrImplWrapper
28     * @param name Name of the package where process definition exists.
29     */

30    protected WfProcessMgrWrapper(String JavaDoc userAuth,String JavaDoc name) throws BaseException {
31       this.userAuth=userAuth;
32       this.name=name;
33    }
34
35    public int how_many_process () throws BaseException {
36       int ret=-1;
37       SharkTransaction t = null;
38       try {
39          t = SharkUtilities.createTransaction();
40          ret = how_many_process(t);
41          //SharkUtilities.commitTransaction(t);
42
} catch (RootException e) {
43          //SharkUtilities.rollbackTransaction(t);
44
SharkUtilities.emptyCaches(t);
45          if (e instanceof BaseException)
46             throw (BaseException)e;
47          else
48             throw new BaseException(e);
49       } finally {
50          SharkUtilities.releaseTransaction(t);
51       }
52       return ret;
53    }
54
55    public int how_many_process (SharkTransaction t) throws BaseException {
56       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
57       if (sm!=null) {
58          try {
59             sm.check_processmgr_how_many_process(t,
60                                                  name,
61                                                  userAuth,
62                                                  SharkUtilities.getProcessMgrPkgId(name),
63                                                  SharkUtilities.getProcessMgrVersion(name),
64                                                  SharkUtilities.getProcessMgrProcDefId(name));
65          } catch (Exception JavaDoc ex) {
66             throw new BaseException(ex);
67          }
68       }
69
70       try {
71          return SharkEngineManager.getInstance().getInstancePersistenceManager().getAllProcessesForMgr(name,t).size();
72       } catch (Exception JavaDoc e) {
73          throw new BaseException(e);
74       }
75    }
76
77    public WfProcessIterator get_iterator_process () throws BaseException {
78       WfProcessIterator ret=null;
79       SharkTransaction t = null;
80       try {
81          t = SharkUtilities.createTransaction();
82          ret = get_iterator_process(t);
83          //SharkUtilities.commitTransaction(t);
84
} catch (RootException e) {
85          //SharkUtilities.rollbackTransaction(t);
86
SharkUtilities.emptyCaches(t);
87          if (e instanceof BaseException)
88             throw (BaseException)e;
89          else
90             throw new BaseException(e);
91       } finally {
92          SharkUtilities.releaseTransaction(t);
93       }
94       return ret;
95    }
96
97    public WfProcessIterator get_iterator_process (SharkTransaction t) throws BaseException {
98       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
99       if (sm!=null) {
100          try {
101             sm.check_processmgr_get_iterator_process(t,
102                                                      name,
103                                                      userAuth,
104                                                      SharkUtilities.getProcessMgrPkgId(name),
105                                                      SharkUtilities.getProcessMgrVersion(name),
106                                                      SharkUtilities.getProcessMgrProcDefId(name));
107          } catch (Exception JavaDoc ex) {
108             throw new BaseException(ex);
109          }
110       }
111
112       return SharkEngineManager.getInstance().getObjectFactory().createProcessIteratorWrapper(t,userAuth,name);
113    }
114
115    public WfProcess[] get_sequence_process (int max_number) throws BaseException {
116       WfProcess[] ret=null;
117       SharkTransaction t = null;
118       try {
119          t = SharkUtilities.createTransaction();
120          ret = get_sequence_process(t,max_number);
121          //SharkUtilities.commitTransaction(t);
122
} catch (RootException e) {
123          //SharkUtilities.rollbackTransaction(t);
124
SharkUtilities.emptyCaches(t);
125          if (e instanceof BaseException)
126             throw (BaseException)e;
127          else
128             throw new BaseException(e);
129       } finally {
130          SharkUtilities.releaseTransaction(t);
131       }
132       return ret;
133    }
134
135    public WfProcess[] get_sequence_process (SharkTransaction t,int max_number) throws BaseException {
136       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
137       if (sm!=null) {
138          try {
139             sm.check_processmgr_get_sequence_process(t,
140                                                      name,
141                                                      userAuth,
142                                                      SharkUtilities.getProcessMgrPkgId(name),
143                                                      SharkUtilities.getProcessMgrVersion(name),
144                                                      SharkUtilities.getProcessMgrProcDefId(name));
145          } catch (Exception JavaDoc ex) {
146             throw new BaseException(ex);
147          }
148       }
149
150       List JavaDoc processes=SharkUtilities.createProcessMgrsProcessWrappers(t,userAuth,name);
151       if (max_number>processes.size() || max_number<=0) {
152          max_number=processes.size();
153       }
154       WfProcessWrapper[] procs=new WfProcessWrapper[max_number];
155       processes.subList(0,max_number).toArray(procs);
156       return procs;
157    }
158
159    public boolean is_member_of_process (WfProcess member) throws BaseException {
160       boolean ret=false;
161       SharkTransaction t = null;
162       try {
163          t = SharkUtilities.createTransaction();
164          ret = is_member_of_process(t,member);
165          //SharkUtilities.commitTransaction(t);
166
} catch (RootException e) {
167          //SharkUtilities.rollbackTransaction(t);
168
SharkUtilities.emptyCaches(t);
169          if (e instanceof BaseException)
170             throw (BaseException)e;
171          else
172             throw new BaseException(e);
173       } finally {
174          SharkUtilities.releaseTransaction(t);
175       }
176       return ret;
177    }
178
179    public boolean is_member_of_process (SharkTransaction t,WfProcess member) throws BaseException {
180       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
181       if (sm!=null) {
182          try {
183             sm.check_processmgr_is_member_of_process(t,
184                                                      name,
185                                                      userAuth,
186                                                      SharkUtilities.getProcessMgrPkgId(name),
187                                                      SharkUtilities.getProcessMgrVersion(name),
188                                                      SharkUtilities.getProcessMgrProcDefId(name));
189          } catch (Exception JavaDoc ex) {
190             throw new BaseException(ex);
191          }
192       }
193       String JavaDoc mgrName=member.manager(t).name(t);
194       return mgrName.equals(this.name);
195    }
196
197    public process_mgr_stateType process_mgr_state () throws BaseException {
198       process_mgr_stateType ret=null;
199       SharkTransaction t = null;
200       try {
201          t = SharkUtilities.createTransaction();
202          ret = process_mgr_state(t);
203          //SharkUtilities.commitTransaction(t);
204
} catch (RootException e) {
205          //SharkUtilities.rollbackTransaction(t);
206
SharkUtilities.emptyCaches(t);
207          if (e instanceof BaseException)
208             throw (BaseException)e;
209          else
210             throw new BaseException(e);
211       } finally {
212          SharkUtilities.releaseTransaction(t);
213       }
214       return ret;
215    }
216
217    public process_mgr_stateType process_mgr_state (SharkTransaction t) throws BaseException {
218       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
219       if (sm!=null) {
220          try {
221             sm.check_processmgr_process_mgr_state(t,
222                                                   name,
223                                                   userAuth,
224                                                   SharkUtilities.getProcessMgrPkgId(name),
225                                                   SharkUtilities.getProcessMgrVersion(name),
226                                                   SharkUtilities.getProcessMgrProcDefId(name));
227          } catch (Exception JavaDoc ex) {
228             throw new BaseException(ex);
229          }
230       }
231
232       return WfProcessMgrWrapper.getProcessMgrImpl(t,name).process_mgr_state(t);
233    }
234
235    public void set_process_mgr_state (process_mgr_stateType new_state) throws BaseException, TransitionNotAllowed {
236       SharkTransaction t = null;
237       try {
238          t = SharkUtilities.createTransaction();
239          set_process_mgr_state(t,new_state);
240          SharkUtilities.commitTransaction(t);
241       } catch (RootException e) {
242          SharkUtilities.rollbackTransaction(t,e);
243          if (e instanceof TransitionNotAllowed)
244             throw (TransitionNotAllowed)e;
245          else if (e instanceof BaseException)
246             throw (BaseException)e;
247          else
248             throw new BaseException(e);
249       } finally {
250          SharkUtilities.releaseTransaction(t);
251       }
252    }
253
254    public void set_process_mgr_state (SharkTransaction t,process_mgr_stateType new_state) throws BaseException, TransitionNotAllowed {
255       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
256       if (sm!=null) {
257          try {
258             sm.check_processmgr_set_process_mgr_state(t,
259                                                       name,
260                                                       userAuth,
261                                                       SharkUtilities.getProcessMgrPkgId(name),
262                                                       SharkUtilities.getProcessMgrVersion(name),
263                                                       SharkUtilities.getProcessMgrProcDefId(name));
264          } catch (Exception JavaDoc ex) {
265             throw new BaseException(ex);
266          }
267       }
268
269       WfProcessMgrInternal mgrInternal=WfProcessMgrWrapper.getProcessMgrImpl(t,name);
270       mgrInternal.set_process_mgr_state(t,new_state);
271    }
272
273    public String JavaDoc name () throws BaseException {
274       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
275       if (sm==null) {
276          return name;
277       }
278       String JavaDoc ret=null;
279       SharkTransaction t = null;
280       try {
281          t = SharkUtilities.createTransaction();
282          ret = name(t);
283          //SharkUtilities.commitTransaction(t);
284
} catch (RootException e) {
285          //SharkUtilities.rollbackTransaction(t);
286
SharkUtilities.emptyCaches(t);
287          if (e instanceof BaseException)
288             throw (BaseException)e;
289          else
290             throw new BaseException(e);
291       } finally {
292          SharkUtilities.releaseTransaction(t);
293       }
294       return ret;
295    }
296
297    public String JavaDoc name (SharkTransaction t) throws BaseException {
298       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
299       if (sm!=null) {
300          try {
301             sm.check_processmgr_name(t,
302                                      name,
303                                      userAuth,
304                                      SharkUtilities.getProcessMgrPkgId(name),
305                                      SharkUtilities.getProcessMgrVersion(name),
306                                      SharkUtilities.getProcessMgrProcDefId(name));
307          } catch (Exception JavaDoc ex) {
308             throw new BaseException(ex);
309          }
310       }
311
312       return name;
313    }
314
315    public String JavaDoc description () throws BaseException {
316       String JavaDoc ret=null;
317       SharkTransaction t = null;
318       try {
319          t = SharkUtilities.createTransaction();
320          ret = description(t);
321          //SharkUtilities.commitTransaction(t);
322
} catch (RootException e) {
323          //SharkUtilities.rollbackTransaction(t);
324
SharkUtilities.emptyCaches(t);
325          if (e instanceof BaseException)
326             throw (BaseException)e;
327          else
328             throw new BaseException(e);
329       } finally {
330          SharkUtilities.releaseTransaction(t);
331       }
332       return ret;
333    }
334
335    public String JavaDoc description (SharkTransaction t) throws BaseException {
336       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
337       if (sm!=null) {
338          try {
339             sm.check_processmgr_description(t,
340                                             name,
341                                             userAuth,
342                                             SharkUtilities.getProcessMgrPkgId(name),
343                                             SharkUtilities.getProcessMgrVersion(name),
344                                             SharkUtilities.getProcessMgrProcDefId(name));
345          } catch (Exception JavaDoc ex) {
346             throw new BaseException(ex);
347          }
348       }
349
350       return WfProcessMgrWrapper.getProcessMgrImpl(t,name).description(t);
351    }
352
353    public String JavaDoc category () throws BaseException {
354       String JavaDoc ret=null;
355       SharkTransaction t = null;
356       try {
357          t = SharkUtilities.createTransaction();
358          ret = category(t);
359          //SharkUtilities.commitTransaction(t);
360
} catch (RootException e) {
361          //SharkUtilities.rollbackTransaction(t);
362
SharkUtilities.emptyCaches(t);
363          if (e instanceof BaseException)
364             throw (BaseException)e;
365          else
366             throw new BaseException(e);
367       } finally {
368          SharkUtilities.releaseTransaction(t);
369       }
370       return ret;
371    }
372
373    public String JavaDoc category (SharkTransaction t) throws BaseException {
374       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
375       if (sm!=null) {
376          try {
377             sm.check_processmgr_category(t,
378                                          name,
379                                          userAuth,
380                                          SharkUtilities.getProcessMgrPkgId(name),
381                                          SharkUtilities.getProcessMgrVersion(name),
382                                          SharkUtilities.getProcessMgrProcDefId(name));
383          } catch (Exception JavaDoc ex) {
384             throw new BaseException(ex);
385          }
386       }
387
388       return WfProcessMgrWrapper.getProcessMgrImpl(t,name).category(t);
389    }
390
391    public String JavaDoc version () throws BaseException {
392       String JavaDoc ret=null;
393       SharkTransaction t = null;
394       try {
395          t = SharkUtilities.createTransaction();
396          ret = version(t);
397          //SharkUtilities.commitTransaction(t);
398
} catch (RootException e) {
399          //SharkUtilities.rollbackTransaction(t);
400
SharkUtilities.emptyCaches(t);
401          if (e instanceof BaseException)
402             throw (BaseException)e;
403          else
404             throw new BaseException(e);
405       } finally {
406          SharkUtilities.releaseTransaction(t);
407       }
408       return ret;
409    }
410
411    public String JavaDoc version (SharkTransaction t) throws BaseException {
412       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
413       if (sm!=null) {
414          try {
415             sm.check_processmgr_version(t,
416                                         name,
417                                         userAuth,
418                                         SharkUtilities.getProcessMgrPkgId(name),
419                                         SharkUtilities.getProcessMgrVersion(name),
420                                         SharkUtilities.getProcessMgrProcDefId(name));
421          } catch (Exception JavaDoc ex) {
422             throw new BaseException(ex);
423          }
424       }
425
426       return WfProcessMgrWrapper.getProcessMgrImpl(t,name).version(t);
427    }
428
429    public Map JavaDoc context_signature () throws BaseException {
430       Map JavaDoc ret=null;
431       SharkTransaction t = null;
432       try {
433          t = SharkUtilities.createTransaction();
434          ret = context_signature(t);
435          //SharkUtilities.commitTransaction(t);
436
} catch (RootException e) {
437          //SharkUtilities.rollbackTransaction(t);
438
SharkUtilities.emptyCaches(t);
439          if (e instanceof BaseException)
440             throw (BaseException)e;
441          else
442             throw new BaseException(e);
443       } finally {
444          SharkUtilities.releaseTransaction(t);
445       }
446       return ret;
447    }
448
449    public Map JavaDoc context_signature (SharkTransaction t) throws BaseException {
450       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
451       if (sm!=null) {
452          try {
453             sm.check_processmgr_context_signature(t,
454                                                   name,
455                                                   userAuth,
456                                                   SharkUtilities.getProcessMgrPkgId(name),
457                                                   SharkUtilities.getProcessMgrVersion(name),
458                                                   SharkUtilities.getProcessMgrProcDefId(name));
459          } catch (Exception JavaDoc ex) {
460             throw new BaseException(ex);
461          }
462       }
463
464       return WfProcessMgrWrapper.getProcessMgrImpl(t,name).context_signature(t);
465    }
466
467    public Map JavaDoc result_signature () throws BaseException {
468       Map JavaDoc ret=null;
469       SharkTransaction t = null;
470       try {
471          t = SharkUtilities.createTransaction();
472          ret = result_signature(t);
473          //SharkUtilities.commitTransaction(t);
474
} catch (RootException e) {
475          //SharkUtilities.rollbackTransaction(t);
476
SharkUtilities.emptyCaches(t);
477          if (e instanceof BaseException)
478             throw (BaseException)e;
479          else
480             throw new BaseException(e);
481       } finally {
482          SharkUtilities.releaseTransaction(t);
483       }
484       return ret;
485    }
486
487    public Map JavaDoc result_signature (SharkTransaction t) throws BaseException {
488       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
489       if (sm!=null) {
490          try {
491             sm.check_processmgr_result_signature(t,
492                                                  name,
493                                                  userAuth,
494                                                  SharkUtilities.getProcessMgrPkgId(name),
495                                                  SharkUtilities.getProcessMgrVersion(name),
496                                                  SharkUtilities.getProcessMgrProcDefId(name));
497          } catch (Exception JavaDoc ex) {
498             throw new BaseException(ex);
499          }
500       }
501
502       return WfProcessMgrWrapper.getProcessMgrImpl(t,name).result_signature(t);
503    }
504
505    /**
506     * Create a WfProcess object
507     */

508    public WfProcess create_process (WfRequester requester) throws BaseException,
509       NotEnabled, InvalidRequester, RequesterRequired {
510       WfProcess ret=null;
511       SharkTransaction t = null;
512       try {
513          t = SharkUtilities.createTransaction();
514          ret = create_process(t,requester);
515          SharkUtilities.commitTransaction(t);
516       } catch (RootException e) {
517          SharkUtilities.rollbackTransaction(t,e);
518          if (e instanceof NotEnabled)
519             throw (NotEnabled)e;
520          else if (e instanceof InvalidRequester)
521             throw (InvalidRequester)e;
522          else if (e instanceof RequesterRequired)
523             throw (RequesterRequired)e;
524          else if (e instanceof BaseException)
525             throw (BaseException)e;
526          else
527             throw new BaseException(e);
528       } finally {
529          SharkUtilities.releaseTransaction(t);
530       }
531       return ret;
532    }
533
534    public WfProcess create_process (SharkTransaction t,WfRequester requester) throws BaseException,
535       NotEnabled, InvalidRequester, RequesterRequired {
536       WfProcessMgrInternal mgr=WfProcessMgrWrapper.getProcessMgrImpl(t,name);
537
538       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
539       if (sm!=null) {
540          try {
541             sm.check_processmgr_create_process(t,
542                                                name,
543                                                userAuth,
544                                                SharkUtilities.getProcessMgrPkgId(name),
545                                                SharkUtilities.getProcessMgrVersion(name),
546                                                SharkUtilities.getProcessMgrProcDefId(name));
547          } catch (Exception JavaDoc ex) {
548             throw new BaseException(ex);
549          }
550       }
551
552
553       // check if this process is allowed to be created only internally
554
if (mgr.category(t).equalsIgnoreCase(XPDLConstants.ACCESS_LEVEL_PRIVATE)) {
555          throw new NotEnabled("The process definition defines only PRIVATE access!");
556       }
557
558       WfRequesterInternal req=SharkEngineManager
559          .getInstance()
560          .getObjectFactory()
561          .createDefaultRequester(userAuth,requester);
562
563
564       WfProcessInternal procInternal=mgr.create_process(t,req);
565       WfProcess proc=SharkEngineManager
566          .getInstance()
567          .getObjectFactory()
568          .createProcessWrapper(userAuth,procInternal.manager_name(t),procInternal.key(t));
569       return proc;
570    }
571
572    public String JavaDoc toString () {
573       return "[name="+name+"]";
574    }
575
576    /**
577     * It is assumed that there can't be two or more
578     * processes mgrs having the same name.
579     */

580    public boolean equals (Object JavaDoc obj) {
581       if (!(obj instanceof WfProcessMgr)) return false;
582       WfProcessMgr mgr=(WfProcessMgr)obj;
583       try {
584          if (obj instanceof WfProcessMgrWrapper) {
585             return ((WfProcessMgrWrapper)obj).name.equals(name);
586          } else {
587             return mgr.name().equals(name);
588          }
589       } catch (Exception JavaDoc ex) {
590          return false;
591       }
592    }
593
594    private static WfProcessMgrInternal getProcessMgrImpl (
595       SharkTransaction t,
596       String JavaDoc name) throws BaseException {
597       WfProcessMgrInternal mgr=SharkUtilities.getProcessMgr(t,name);
598       if (mgr==null) throw new BaseException("ProcessMgr does not exist");
599       return mgr;
600    }
601 }
602
603
Popular Tags