KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark;
2
3 import java.util.List JavaDoc;
4 import org.enhydra.shark.api.RootException;
5 import org.enhydra.shark.api.SharkTransaction;
6 import org.enhydra.shark.api.client.wfbase.BaseException;
7 import org.enhydra.shark.api.client.wfservice.LimitAdministration;
8 import org.enhydra.shark.api.internal.limitagent.LimitAgentManager;
9
10 /**
11  * The implementation of client interface through which client can check limits.
12  * @author Sasa Bojanic
13  */

14 public class LimitAdmin implements LimitAdministration {
15
16    private String JavaDoc userId="Unknown";
17
18    protected LimitAdmin () {
19    }
20
21    public void connect (String JavaDoc userId) {
22       this.userId=userId;
23    }
24
25    public void checkLimits () throws BaseException {
26       SharkTransaction t = null;
27       List JavaDoc pos;
28       try {
29          t = SharkUtilities.createTransaction();
30          checkLimits(t);
31          SharkUtilities.commitTransaction(t);
32       } catch (RootException e) {
33          SharkUtilities.rollbackTransaction(t,e);
34          if (e instanceof BaseException)
35             throw (BaseException)e;
36          else
37             throw new BaseException(e);
38       } finally {
39          SharkUtilities.releaseTransaction(t);
40       }
41    }
42
43    public void checkLimits (SharkTransaction t) throws BaseException {
44       LimitAgentManager lam=SharkEngineManager.getInstance().getLimitAgentManager();
45       if (lam==null) throw new BaseException("Shark is working without implementation of Limit API!");
46       try {
47          lam.checkLimits(t);
48       } catch (Exception JavaDoc ex) {
49          throw new BaseException(ex);
50       }
51    }
52
53    public void checkLimits (String JavaDoc[] procIds) throws BaseException {
54       SharkTransaction t = null;
55       try {
56          t = SharkUtilities.createTransaction();
57          checkLimits(t,procIds);
58          SharkUtilities.commitTransaction(t);
59       } catch (RootException e) {
60          SharkUtilities.rollbackTransaction(t,e);
61          if (e instanceof BaseException)
62             throw (BaseException)e;
63          else
64             throw new BaseException(e);
65       } finally {
66          SharkUtilities.releaseTransaction(t);
67       }
68    }
69
70    public void checkLimits (SharkTransaction t,String JavaDoc[] procIds) throws BaseException {
71       LimitAgentManager lam=SharkEngineManager.getInstance().getLimitAgentManager();
72       if (lam==null) throw new BaseException("Shark is working without implementation of Limit API!");
73       if (procIds==null) throw new BaseException("Invalid null value for parameter procIds");
74       try {
75          for (int i=0; i<procIds.length; i++) {
76             lam.checkLimits(t,procIds[i]);
77          }
78       } catch (Exception JavaDoc ex) {
79          throw new BaseException(ex);
80       }
81    }
82
83    public void checkLimits (String JavaDoc procId) throws BaseException {
84       SharkTransaction t = null;
85       try {
86          t = SharkUtilities.createTransaction();
87          checkLimits(t,procId);
88          SharkUtilities.commitTransaction(t);
89       } catch (RootException e) {
90          SharkUtilities.rollbackTransaction(t,e);
91          if (e instanceof BaseException)
92             throw (BaseException)e;
93          else
94             throw new BaseException(e);
95       } finally {
96          SharkUtilities.releaseTransaction(t);
97       }
98    }
99
100    public void checkLimits (SharkTransaction t,String JavaDoc procId) throws BaseException {
101       LimitAgentManager lam=SharkEngineManager.getInstance().getLimitAgentManager();
102       if (lam==null) throw new BaseException("Shark is working without implementation of Limit API!");
103       if (procId==null) throw new BaseException("Invalid null value for parameter procId");
104       try {
105          lam.checkLimits(t,procId);
106       } catch (Exception JavaDoc ex) {
107          throw new BaseException(ex);
108       }
109    }
110
111    public void checkProcessLimit (String JavaDoc procId) throws BaseException {
112       SharkTransaction t = null;
113       try {
114          t = SharkUtilities.createTransaction();
115          checkProcessLimit(t,procId);
116          SharkUtilities.commitTransaction(t);
117       } catch (RootException e) {
118          SharkUtilities.rollbackTransaction(t,e);
119          if (e instanceof BaseException)
120             throw (BaseException)e;
121          else
122             throw new BaseException(e);
123       } finally {
124          SharkUtilities.releaseTransaction(t);
125       }
126    }
127
128    public void checkProcessLimit (SharkTransaction t,String JavaDoc procId) throws BaseException {
129       LimitAgentManager lam=SharkEngineManager.getInstance().getLimitAgentManager();
130       if (lam==null) throw new BaseException("Shark is working without implementation of Limit API!");
131       if (procId==null) throw new BaseException("Invalid null value for parameter procId");
132       try {
133          lam.checkProcessLimit(t,procId);
134       } catch (Exception JavaDoc ex) {
135          throw new BaseException(ex);
136       }
137    }
138
139    public void checkActivityLimit (String JavaDoc procId,String JavaDoc actId) throws BaseException {
140       SharkTransaction t = null;
141       try {
142          t = SharkUtilities.createTransaction();
143          checkActivityLimit(t,procId,actId);
144          SharkUtilities.commitTransaction(t);
145       } catch (RootException e) {
146          SharkUtilities.rollbackTransaction(t,e);
147          if (e instanceof BaseException)
148             throw (BaseException)e;
149          else
150             throw new BaseException(e);
151       } finally {
152          SharkUtilities.releaseTransaction(t);
153       }
154    }
155
156    public void checkActivityLimit (SharkTransaction t,String JavaDoc procId,String JavaDoc actId) throws BaseException {
157       LimitAgentManager lam=SharkEngineManager.getInstance().getLimitAgentManager();
158       if (lam==null) throw new BaseException("Shark is working without implementation of Limit API!");
159       if (procId==null) throw new BaseException("Invalid null value for parameter procId");
160       if (actId==null) throw new BaseException("Invalid null value for parameter actId");
161       try {
162          lam.checkActivityLimit(t,procId,actId);
163       } catch (Exception JavaDoc ex) {
164          throw new BaseException(ex);
165       }
166    }
167
168 }
169
Popular Tags