KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark;
2
3
4 import java.util.ArrayList JavaDoc;
5 import java.util.HashMap 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.wfbase.BaseException;
11 import org.enhydra.shark.api.client.wfmodel.WfProcessMgr;
12 import org.enhydra.shark.api.client.wfmodel.process_mgr_stateType;
13 import org.enhydra.shark.api.client.wfservice.WfProcessMgrIterator;
14 import org.enhydra.shark.api.common.SharkConstants;
15 import org.enhydra.shark.api.internal.instancepersistence.ProcessMgrPersistenceInterface;
16 import org.enhydra.shark.api.internal.scripting.Evaluator;
17
18 /**
19  * Iterator for engine's process managers.
20  * The following names may be used for expressions: packageId, processDefinitionId,
21  * name, category, createdTime_ms, version, enabled.
22  * @author Sasa Bojanic
23  */

24 public class WfProcessMgrIteratorWrapper extends BaseIteratorWrapper implements WfProcessMgrIterator {
25
26    protected WfProcessMgrIteratorWrapper (SharkTransaction t,String JavaDoc userAuth) throws BaseException {
27       super(userAuth);
28    }
29
30    public WfProcessMgr get_next_object () throws BaseException {
31       WfProcessMgr ret=null;
32       SharkTransaction t = null;
33       try {
34          t = SharkUtilities.createTransaction();
35          ret = get_next_object(t);
36          //SharkUtilities.commitTransaction(t);
37
} catch (RootException e) {
38          //SharkUtilities.rollbackTransaction(t);
39
SharkUtilities.emptyCaches(t);
40          if (e instanceof BaseException)
41             throw (BaseException)e;
42          else
43             throw new BaseException(e);
44       } finally {
45          SharkUtilities.releaseTransaction(t);
46       }
47       return ret;
48    }
49
50    public WfProcessMgr get_next_object (SharkTransaction t) throws BaseException {
51       return (WfProcessMgr)super.getNextObject(t);
52    }
53
54    public WfProcessMgr get_previous_object () throws BaseException {
55       WfProcessMgr ret=null;
56       SharkTransaction t = null;
57       try {
58          t = SharkUtilities.createTransaction();
59          ret = get_previous_object(t);
60          //SharkUtilities.commitTransaction(t);
61
} catch (RootException e) {
62          //SharkUtilities.rollbackTransaction(t);
63
SharkUtilities.emptyCaches(t);
64          if (e instanceof BaseException)
65             throw (BaseException)e;
66          else
67             throw new BaseException(e);
68       } finally {
69          SharkUtilities.releaseTransaction(t);
70       }
71       return ret;
72    }
73
74    public WfProcessMgr get_previous_object (SharkTransaction t) throws BaseException {
75       return (WfProcessMgr)super.getPreviousObject(t);
76    }
77
78    public WfProcessMgr[] get_next_n_sequence (int max_number) throws BaseException {
79       WfProcessMgr[] ret=null;
80       SharkTransaction t = null;
81       try {
82          t = SharkUtilities.createTransaction();
83          ret = get_next_n_sequence(t,max_number);
84          //SharkUtilities.commitTransaction(t);
85
} catch (RootException e) {
86          //SharkUtilities.rollbackTransaction(t);
87
SharkUtilities.emptyCaches(t);
88          if (e instanceof BaseException)
89             throw (BaseException)e;
90          else
91             throw new BaseException(e);
92       } finally {
93          SharkUtilities.releaseTransaction(t);
94       }
95       return ret;
96    }
97
98    public WfProcessMgr[] get_next_n_sequence (SharkTransaction t,int max_number) throws BaseException {
99       List JavaDoc l=super.getNextNSequence(t,max_number);
100       WfProcessMgr[] ret=new WfProcessMgr[l.size()];
101       l.toArray(ret);
102       return ret;
103    }
104
105    public WfProcessMgr[] get_previous_n_sequence (int max_number) throws BaseException {
106       WfProcessMgr[] ret=null;
107       SharkTransaction t = null;
108       try {
109          t = SharkUtilities.createTransaction();
110          ret = get_previous_n_sequence(t,max_number);
111          //SharkUtilities.commitTransaction(t);
112
} catch (RootException e) {
113          //SharkUtilities.rollbackTransaction(t);
114
SharkUtilities.emptyCaches(t);
115          if (e instanceof BaseException)
116             throw (BaseException)e;
117          else
118             throw new BaseException(e);
119       } finally {
120          SharkUtilities.releaseTransaction(t);
121       }
122       return ret;
123    }
124
125    public WfProcessMgr[] get_previous_n_sequence (SharkTransaction t,int max_number) throws BaseException {
126       List JavaDoc l=super.getPreviousNSequence(t,max_number);
127       WfProcessMgr[] ret=new WfProcessMgr[l.size()];
128       l.toArray(ret);
129       return ret;
130    }
131
132    protected void fillObjectList (SharkTransaction t) throws BaseException {
133       if (objectList!=null) return;
134       try {
135          List JavaDoc mgrs=new ArrayList JavaDoc();
136          List JavaDoc l=SharkEngineManager
137             .getInstance()
138             .getInstancePersistenceManager()
139             .getProcessMgrsWhere(t, sqlWhere);
140
141          Evaluator evaluator=SharkEngineManager
142             .getInstance()
143             .getScriptingManager()
144             .getEvaluator(t,queryGrammar);
145
146          for (int i=0; i<l.size(); i++) {
147             ProcessMgrPersistenceInterface po=(ProcessMgrPersistenceInterface)l.get(i);
148             boolean toAdd=true;
149             if (eval) {
150                Map JavaDoc context=new HashMap JavaDoc();
151                context.put("name",po.getName());
152
153                if (ignoreUsedContext || (!ignoreUsedContext &&
154                      0 <= usedContext.indexOf(SharkConstants.MGR_CATEGORY))) {
155                   String JavaDoc cat = SharkUtilities.getWorkflowProcess(po.getPackageId(),
156                                                                  po.getVersion(),
157                                                                  po.getProcessDefinitionId())
158                      .getAccessLevel();
159                   context.put(SharkConstants.MGR_CATEGORY, cat);
160                }
161                if (ignoreUsedContext || (!ignoreUsedContext &&
162                      0 <= usedContext.indexOf(SharkConstants.MGR_VERSION))) {
163                   context.put(SharkConstants.MGR_VERSION,po.getVersion());
164                }
165                if (ignoreUsedContext || (!ignoreUsedContext &&
166                      0 <= usedContext.indexOf(SharkConstants.MGR_CREATED_TIME_MS))) {
167                   context.put(SharkConstants.MGR_CREATED_TIME_MS,new Long JavaDoc(po.getCreated()));
168                }
169                if (ignoreUsedContext || (!ignoreUsedContext &&
170                      0 <= usedContext.indexOf(SharkConstants.MGR_PACKAGE_ID))) {
171                   context.put(SharkConstants.MGR_PACKAGE_ID,po.getPackageId());
172                }
173                if (ignoreUsedContext || (!ignoreUsedContext && 0 <= usedContext.indexOf(SharkConstants.MGR_PROCESS_DEFINITION_ID))) {
174                   context.put(SharkConstants.MGR_PROCESS_DEFINITION_ID,
175                               po.getProcessDefinitionId());
176                }
177                if (ignoreUsedContext || (!ignoreUsedContext &&
178                      0 <= usedContext.indexOf(SharkConstants.MGR_ENABLED))) {
179                   context.put(SharkConstants.MGR_ENABLED,
180                               new Boolean JavaDoc(po.getState() == process_mgr_stateType._enabled));
181                }
182                toAdd=evaluator.evaluateCondition(t,queryExpression,context);
183             }
184             if (toAdd) {
185                mgrs.add(SharkEngineManager.getInstance().getObjectFactory().createProcessMgrWrapper(userAuth,po.getName()));
186             }
187          }
188          setObjectList(mgrs);
189       } catch (Exception JavaDoc ex) {
190          throw new BaseException(ex);
191       }
192    }
193
194 }
195
Popular Tags