KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5 import org.enhydra.shark.api.RootException;
6 import org.enhydra.shark.api.SharkTransaction;
7 import org.enhydra.shark.api.client.wfbase.BaseException;
8 import org.enhydra.shark.api.client.wfmodel.InvalidPerformer;
9 import org.enhydra.shark.api.client.wfmodel.WfEventAudit;
10 import org.enhydra.shark.api.client.wfmodel.WfProcess;
11 import org.enhydra.shark.api.client.wfmodel.WfProcessIterator;
12 import org.enhydra.shark.api.client.wfmodel.WfRequester;
13 import org.enhydra.shark.api.internal.instancepersistence.ProcessPersistenceInterface;
14 import org.enhydra.shark.api.internal.security.SecurityManager;
15
16
17 /**
18  * WfRequesterWrapper - Workflow Requester implementation.
19  * @author Sasa Bojanic
20  */

21 public class WfRequesterWrapper implements WfRequester {
22
23    private String JavaDoc userAuth;
24    private String JavaDoc resourceUsername;
25
26    protected WfRequesterWrapper (String JavaDoc userAuth,String JavaDoc resUsername) {
27       this.userAuth=userAuth;
28       this.resourceUsername=resUsername;
29    }
30
31    /**
32     * Gets the number of processes.
33     */

34    public int how_many_performer () throws BaseException {
35       int ret=-1;
36       SharkTransaction t = null;
37       try {
38          t = SharkUtilities.createTransaction();
39          ret = how_many_performer(t);
40          //SharkUtilities.commitTransaction(t);
41
} catch (RootException e) {
42          //SharkUtilities.rollbackTransaction(t);
43
SharkUtilities.emptyCaches(t);
44          throw (BaseException)e;
45       } finally {
46          SharkUtilities.releaseTransaction(t);
47       }
48       return ret;
49    }
50
51    public int how_many_performer (SharkTransaction t) throws BaseException {
52       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
53       if (sm!=null) {
54          try {
55             sm.check_requester_how_many_performer(t,
56                                                   resourceUsername,
57                                                   userAuth);
58          } catch (Exception JavaDoc ex) {
59             throw new BaseException(ex);
60          }
61       }
62       try {
63          return SharkEngineManager
64             .getInstance()
65             .getInstancePersistenceManager()
66             .getResourceRequestersProcessIds(resourceUsername,t).size();
67       } catch (Exception JavaDoc ex) {
68          throw new BaseException(ex);
69       }
70    }
71
72    /**
73     * Gets an iterator of processes.
74     */

75    public WfProcessIterator get_iterator_performer () throws BaseException {
76       WfProcessIterator ret=null;
77       SharkTransaction t = null;
78       try {
79          t = SharkUtilities.createTransaction();
80          ret = get_iterator_performer(t);
81          //SharkUtilities.commitTransaction(t);
82
} catch (RootException e) {
83          //SharkUtilities.rollbackTransaction(t);
84
SharkUtilities.emptyCaches(t);
85          throw (BaseException)e;
86       } finally {
87          SharkUtilities.releaseTransaction(t);
88       }
89       return ret;
90    }
91
92    public WfProcessIterator get_iterator_performer (SharkTransaction t) throws BaseException {
93       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
94       if (sm!=null) {
95          try {
96             sm.check_requester_get_iterator_performer(t,
97                                                       resourceUsername,
98                                                       userAuth);
99          } catch (Exception JavaDoc ex) {
100             throw new BaseException(ex);
101          }
102       }
103       return SharkEngineManager.getInstance().getObjectFactory().createProcessIteratorWrapper(t,userAuth,resourceUsername,true);
104    }
105
106    /**
107     * Returns a list of processes.
108     * @return List of WfProcess objects.
109     */

110    public WfProcess[] get_sequence_performer (int max_number) throws BaseException {
111       WfProcess[] ret=null;
112       SharkTransaction t = null;
113       try {
114          t = SharkUtilities.createTransaction();
115          ret = get_sequence_performer(t,max_number);
116          //SharkUtilities.commitTransaction(t);
117
} catch (RootException e) {
118          //SharkUtilities.rollbackTransaction(t);
119
SharkUtilities.emptyCaches(t);
120          throw (BaseException)e;
121       } finally {
122          SharkUtilities.releaseTransaction(t);
123       }
124       return ret;
125    }
126
127    public WfProcess[] get_sequence_performer (SharkTransaction t,int max_number) throws BaseException {
128       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
129       if (sm!=null) {
130          try {
131             sm.check_requester_get_sequence_performer(t,
132                                                       resourceUsername,
133                                                       userAuth);
134          } catch (Exception JavaDoc ex) {
135             throw new BaseException(ex);
136          }
137       }
138       List JavaDoc alist = SharkUtilities.createResourceRequesterPerformersWrapper(t,userAuth,resourceUsername);
139       if (max_number > alist.size() || max_number<=0) {
140          max_number = alist.size();
141       }
142       WfProcess[] ret = new WfProcess[max_number];
143       alist.subList(0, max_number).toArray(ret);
144       return ret;
145    }
146
147    /**
148     * Checks if a WfProcess is associated with this requester object.
149     * @return true if the process is found.
150     */

151    public boolean is_member_of_performer (WfProcess member) throws BaseException {
152       boolean ret=false;
153       SharkTransaction t = null;
154       try {
155          t = SharkUtilities.createTransaction();
156          ret = is_member_of_performer(t,member);
157          //SharkUtilities.commitTransaction(t);
158
} catch (RootException e) {
159          //SharkUtilities.rollbackTransaction(t);
160
SharkUtilities.emptyCaches(t);
161          throw (BaseException)e;
162       } finally {
163          SharkUtilities.releaseTransaction(t);
164       }
165       return ret;
166    }
167
168    public boolean is_member_of_performer (SharkTransaction t,WfProcess member) throws BaseException {
169       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
170       if (sm!=null) {
171          try {
172             sm.check_requester_is_member_of_performer(t,
173                                                       resourceUsername,
174                                                       userAuth);
175          } catch (Exception JavaDoc ex) {
176             throw new BaseException(ex);
177          }
178       }
179       try {
180          String JavaDoc procId=member.key(t);
181          List JavaDoc ids=SharkEngineManager.getInstance().getInstancePersistenceManager().getResourceRequestersProcessIds(resourceUsername,t);
182          return ids.contains(procId);
183       } catch (Exception JavaDoc ex) {
184          throw new BaseException(ex);
185       }
186    }
187
188    /**
189     * Receives notice of event status changes.
190     */

191    public void receive_event (WfEventAudit event) throws BaseException, InvalidPerformer {
192       SharkTransaction t = null;
193       try {
194          t = SharkUtilities.createTransaction();
195          receive_event(t,event);
196          //SharkUtilities.commitTransaction(t);
197
} catch (RootException e) {
198          //SharkUtilities.rollbackTransaction(t);
199
SharkUtilities.emptyCaches(t);
200          throw (BaseException)e;
201       } finally {
202          SharkUtilities.releaseTransaction(t);
203       }
204    }
205
206    public void receive_event (SharkTransaction t,WfEventAudit event) throws BaseException, InvalidPerformer {
207       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
208       if (sm!=null) {
209          try {
210             sm.check_requester_receive_event(t,
211                                              resourceUsername,
212                                              userAuth);
213          } catch (Exception JavaDoc ex) {
214             throw new BaseException(ex);
215          }
216       }
217    }
218
219 }
220
221
Popular Tags