KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.enhydra.shark;
2
3 import java.io.File JavaDoc;
4 import java.io.FileFilter JavaDoc;
5 import java.text.DateFormat JavaDoc;
6 import java.text.ParseException JavaDoc;
7 import java.util.ArrayList JavaDoc;
8 import java.util.Arrays JavaDoc;
9 import java.util.Collection JavaDoc;
10 import java.util.Collections JavaDoc;
11 import java.util.Date JavaDoc;
12 import java.util.HashMap JavaDoc;
13 import java.util.HashSet JavaDoc;
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Map JavaDoc;
17 import java.util.Set JavaDoc;
18
19 import org.enhydra.shark.api.ApplicationMappingTransaction;
20 import org.enhydra.shark.api.ParticipantMappingTransaction;
21 import org.enhydra.shark.api.RepositoryTransaction;
22 import org.enhydra.shark.api.RootError;
23 import org.enhydra.shark.api.RootException;
24 import org.enhydra.shark.api.ScriptMappingTransaction;
25 import org.enhydra.shark.api.SharkTransaction;
26 import org.enhydra.shark.api.TransactionException;
27 import org.enhydra.shark.api.UserTransaction;
28 import org.enhydra.shark.api.client.wfbase.BaseException;
29 import org.enhydra.shark.api.client.wfmodel.WfAssignment;
30 import org.enhydra.shark.api.common.SharkConstants;
31 import org.enhydra.shark.api.internal.appmappersistence.ApplicationMappingManager;
32 import org.enhydra.shark.api.internal.assignment.AssignmentManager;
33 import org.enhydra.shark.api.internal.assignment.PerformerData;
34 import org.enhydra.shark.api.internal.authentication.AuthenticationManager;
35 import org.enhydra.shark.api.internal.caching.CacheMgr;
36 import org.enhydra.shark.api.internal.caching.ProcessCache;
37 import org.enhydra.shark.api.internal.caching.ResourceCache;
38 import org.enhydra.shark.api.internal.eventaudit.AssignmentEventAuditPersistenceInterface;
39 import org.enhydra.shark.api.internal.eventaudit.CreateProcessEventAuditPersistenceInterface;
40 import org.enhydra.shark.api.internal.eventaudit.DataEventAuditPersistenceInterface;
41 import org.enhydra.shark.api.internal.eventaudit.EventAuditManagerInterface;
42 import org.enhydra.shark.api.internal.eventaudit.EventAuditPersistenceInterface;
43 import org.enhydra.shark.api.internal.eventaudit.StateEventAuditPersistenceInterface;
44 import org.enhydra.shark.api.internal.instancepersistence.AssignmentPersistenceInterface;
45 import org.enhydra.shark.api.internal.instancepersistence.PersistenceException;
46 import org.enhydra.shark.api.internal.instancepersistence.PersistentManagerInterface;
47 import org.enhydra.shark.api.internal.instancepersistence.ProcessMgrPersistenceInterface;
48 import org.enhydra.shark.api.internal.instancepersistence.ProcessPersistenceInterface;
49 import org.enhydra.shark.api.internal.instancepersistence.ResourcePersistenceInterface;
50 import org.enhydra.shark.api.internal.partmappersistence.ParticipantMappingManager;
51 import org.enhydra.shark.api.internal.processlocking.LockMaster;
52 import org.enhydra.shark.api.internal.repositorypersistence.RepositoryPersistenceManager;
53 import org.enhydra.shark.api.internal.scripting.Evaluator;
54 import org.enhydra.shark.api.internal.scriptmappersistence.ScriptMappingManager;
55 import org.enhydra.shark.api.internal.security.SecurityManager;
56 import org.enhydra.shark.api.internal.toolagent.ToolAgentGeneralException;
57 import org.enhydra.shark.api.internal.transaction.SharkInternalTransaction;
58 import org.enhydra.shark.api.internal.transaction.TransactionFactory;
59 import org.enhydra.shark.api.internal.usertransaction.UserTransactionFactory;
60 import org.enhydra.shark.api.internal.working.CallbackUtilities;
61 import org.enhydra.shark.api.internal.working.ObjectFactory;
62 import org.enhydra.shark.api.internal.working.WfActivityInternal;
63 import org.enhydra.shark.api.internal.working.WfAssignmentInternal;
64 import org.enhydra.shark.api.internal.working.WfProcessInternal;
65 import org.enhydra.shark.api.internal.working.WfProcessMgrInternal;
66 import org.enhydra.shark.api.internal.working.WfResourceInternal;
67 import org.enhydra.shark.utilities.MiscUtilities;
68 import org.enhydra.shark.utilities.SequencedHashMap;
69 import org.enhydra.shark.xpdl.Version;
70 import org.enhydra.shark.xpdl.XMLCollectionElement;
71 import org.enhydra.shark.xpdl.XMLElement;
72 import org.enhydra.shark.xpdl.XMLInterface;
73 import org.enhydra.shark.xpdl.XMLInterfaceForJDK13;
74 import org.enhydra.shark.xpdl.XMLUtil;
75 import org.enhydra.shark.xpdl.XPDLConstants;
76 import org.enhydra.shark.xpdl.elements.Activities;
77 import org.enhydra.shark.xpdl.elements.Activity;
78 import org.enhydra.shark.xpdl.elements.ActivitySet;
79 import org.enhydra.shark.xpdl.elements.ActualParameter;
80 import org.enhydra.shark.xpdl.elements.ActualParameters;
81 import org.enhydra.shark.xpdl.elements.Application;
82 import org.enhydra.shark.xpdl.elements.BlockActivity;
83 import org.enhydra.shark.xpdl.elements.DataField;
84 import org.enhydra.shark.xpdl.elements.DataFields;
85 import org.enhydra.shark.xpdl.elements.DataType;
86 import org.enhydra.shark.xpdl.elements.ExtendedAttribute;
87 import org.enhydra.shark.xpdl.elements.ExtendedAttributes;
88 import org.enhydra.shark.xpdl.elements.ExternalPackage;
89 import org.enhydra.shark.xpdl.elements.FormalParameter;
90 import org.enhydra.shark.xpdl.elements.FormalParameters;
91 import org.enhydra.shark.xpdl.elements.Package;
92 import org.enhydra.shark.xpdl.elements.Participant;
93 import org.enhydra.shark.xpdl.elements.WorkflowProcess;
94
95
96 /**
97  * The various utilities needed for shark.
98  * @author Sasa Bojanic
99  * @author Vladimir Puskas
100  * @author Zoran Milakovic
101  */

102 public class SharkUtilities {
103    // TODO: implement Enumeration type handling
104
// TODO: if some data from XPDL Package are wanted, sometimes
105
// they are not retrieved (i.e. if one asks for variable name, and
106
// the variable's XPDL is not cached -> exception happens)
107

108    private static Map JavaDoc validActivityStates=new HashMap JavaDoc();
109    static {
110       List JavaDoc vsList=new ArrayList JavaDoc();
111       validActivityStates.put(SharkConstants.STATE_CLOSED_ABORTED,vsList);
112       validActivityStates.put(SharkConstants.STATE_CLOSED_COMPLETED,vsList);
113       validActivityStates.put(SharkConstants.STATE_CLOSED_TERMINATED,vsList);
114
115       vsList=new ArrayList JavaDoc(SharkConstants.possibleActivityStates);
116       vsList.remove(SharkConstants.STATE_OPEN_RUNNING);
117       validActivityStates.put(SharkConstants.STATE_OPEN_RUNNING,vsList);
118
119       vsList=new ArrayList JavaDoc(SharkConstants.possibleActivityStates);
120       vsList.remove(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED);
121       vsList.remove(SharkConstants.STATE_CLOSED_COMPLETED);
122       validActivityStates.put(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED,vsList);
123
124       vsList=new ArrayList JavaDoc(SharkConstants.possibleActivityStates);
125       vsList.remove(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED);
126       vsList.remove(SharkConstants.STATE_CLOSED_COMPLETED);
127       validActivityStates.put(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED,vsList);
128    }
129
130    static final List JavaDoc valid_activity_states (String JavaDoc currentState) {
131       return (List JavaDoc)validActivityStates.get(currentState);
132    }
133
134
135
136    private static Map JavaDoc validProcessStates=new HashMap JavaDoc();
137    static {
138       List JavaDoc vsList=new ArrayList JavaDoc();
139       validProcessStates.put(SharkConstants.STATE_CLOSED_ABORTED,vsList);
140       validProcessStates.put(SharkConstants.STATE_CLOSED_COMPLETED,vsList);
141       validProcessStates.put(SharkConstants.STATE_CLOSED_TERMINATED,vsList);
142
143       vsList=new ArrayList JavaDoc(SharkConstants.possibleProcessStates);
144       vsList.remove(SharkConstants.STATE_OPEN_RUNNING);
145       vsList.remove(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED);
146       validProcessStates.put(SharkConstants.STATE_OPEN_RUNNING,vsList);
147
148       vsList=new ArrayList JavaDoc(SharkConstants.possibleProcessStates);
149       vsList.remove(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED);
150       vsList.remove(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED);
151       vsList.remove(SharkConstants.STATE_CLOSED_COMPLETED);
152       validProcessStates.put(SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED,vsList);
153
154       vsList=new ArrayList JavaDoc(SharkConstants.possibleProcessStates);
155       vsList.remove(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED);
156       vsList.remove(SharkConstants.STATE_CLOSED_COMPLETED);
157       validProcessStates.put(SharkConstants.STATE_OPEN_NOT_RUNNING_SUSPENDED,vsList);
158    }
159
160    static final List JavaDoc valid_process_states (String JavaDoc currentState) {
161       return (List JavaDoc)validProcessStates.get(currentState);
162    }
163
164    // The locations to various repositories
165
public static final String JavaDoc EXTERNAL_PACKAGES_REPOSITORY=
166       SharkUtilities.getRepository("EXTERNAL_PACKAGES_REPOSITORY");
167
168    // counts connections to engine
169
private static int nextConnectionKey=1;
170    static synchronized String JavaDoc getNextConnectionKey(){
171       String JavaDoc ck= Integer.toString(nextConnectionKey);
172       nextConnectionKey++;
173       return ck;
174    }
175
176    // a cache of loaded objects
177
private static Map JavaDoc loggedUsers=new SequencedHashMap();
178
179    private static Map JavaDoc currentPkgVersions=new HashMap JavaDoc();
180
181    private static PackageFileFilter packageFileFilter=new PackageFileFilter();
182
183    static String JavaDoc connect (String JavaDoc userId) {
184       String JavaDoc connectionKey=getNextConnectionKey();
185       loggedUsers.put(connectionKey,userId);
186       return connectionKey;
187    }
188
189    static void disconnect (String JavaDoc connectionKey) {
190       loggedUsers.remove(connectionKey);
191    }
192
193    static Map JavaDoc getLoggedUsers () throws Exception JavaDoc {
194       return Collections.unmodifiableMap(loggedUsers);
195    }
196
197    static List JavaDoc getDefinedPackageFiles (String JavaDoc repository,boolean traverse) {
198       File JavaDoc startingFolder=new File JavaDoc(repository);
199       List JavaDoc packageFiles=new ArrayList JavaDoc();
200       if (!startingFolder.exists()) {
201          SharkEngineManager.getInstance().getCallbackUtilities().warn("SharkUtilities -> Repository "+startingFolder+" doesn't exist");
202       }
203       if (traverse) {
204          MiscUtilities.traverse(startingFolder,packageFiles,null);
205       } else {
206          packageFiles=Arrays.asList(startingFolder.listFiles(packageFileFilter));
207       }
208       return packageFiles;
209    }
210
211
212    static String JavaDoc convertToAbsolutePath (String JavaDoc relativePathToPackage) {
213       String JavaDoc absolutePath=relativePathToPackage;
214       List JavaDoc packageFiles=SharkUtilities.getDefinedPackageFiles(EXTERNAL_PACKAGES_REPOSITORY,true);
215       String JavaDoc dirName= new File JavaDoc(EXTERNAL_PACKAGES_REPOSITORY)
216          .getAbsolutePath();
217       Iterator JavaDoc pfi=packageFiles.iterator();
218       while (pfi.hasNext()) {
219          File JavaDoc f=(File JavaDoc)pfi.next();
220          String JavaDoc fileName=f.getAbsolutePath();
221          fileName=fileName.substring(dirName.length()+1);
222          if (fileName.equals(relativePathToPackage)) {
223             absolutePath=f.getAbsolutePath();
224             break;
225          }
226       }
227       return absolutePath;
228    }
229
230
231
232
233    static List JavaDoc createAllProcessMgrWrappers (SharkTransaction t,String JavaDoc userAuth) throws BaseException {
234       try {
235          List JavaDoc mgrs=new ArrayList JavaDoc();
236          List JavaDoc l=SharkEngineManager
237             .getInstance()
238             .getInstancePersistenceManager()
239             .getAllProcessMgrs(t);
240          for (int i=0; i<l.size(); i++) {
241             ProcessMgrPersistenceInterface po=(ProcessMgrPersistenceInterface)l.get(i);
242             mgrs.add(SharkEngineManager.getInstance().getObjectFactory().createProcessMgrWrapper(userAuth,po.getName()));
243          }
244          return mgrs;
245       } catch (Exception JavaDoc ex) {
246          throw new BaseException(ex);
247       }
248    }
249
250    static List JavaDoc createProcessMgrsProcessWrappers (SharkTransaction t,String JavaDoc userAuth,String JavaDoc mgrName) throws BaseException {
251       try {
252          List JavaDoc l=SharkEngineManager.getInstance().getInstancePersistenceManager().getAllProcessesForMgr(mgrName,t);
253          List JavaDoc ret=new ArrayList JavaDoc();
254          for (int i=0; i<l.size(); i++) {
255             ProcessPersistenceInterface po=(ProcessPersistenceInterface)l.get(i);
256             ret.add(SharkEngineManager.getInstance().getObjectFactory().createProcessWrapper(userAuth,po.getProcessMgrName(),po.getId()));
257          }
258          return ret;
259       } catch (Exception JavaDoc ex) {
260          throw new BaseException(ex);
261       }
262    }
263
264    static List JavaDoc createActivityPerformerWrapper (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId,String JavaDoc actId) throws BaseException {
265       WfActivityInternal act=SharkUtilities.getActivity(t,procId,actId);
266       String JavaDoc performerId=act.getPerformerId(t);
267       List JavaDoc ret=new ArrayList JavaDoc();
268       if (performerId!=null) {
269          ret.add(SharkEngineManager.getInstance().getObjectFactory().createProcessWrapper(userAuth,act.manager_name(t),performerId));
270       }
271       return ret;
272    }
273
274    static List JavaDoc createResourceRequesterPerformersWrapper (SharkTransaction t,String JavaDoc userAuth,String JavaDoc username) throws BaseException {
275       try {
276          PersistentManagerInterface ipi=SharkEngineManager
277          .getInstance()
278          .getInstancePersistenceManager();
279          List JavaDoc l=ipi.getResourceRequestersProcessIds(username,t);
280          List JavaDoc ret=new ArrayList JavaDoc();
281          for (int i=0; i<l.size(); i++) {
282             String JavaDoc pId=(String JavaDoc)l.get(i);
283             ProcessPersistenceInterface po=ipi.restoreProcess(pId, t);
284             // TODO: decide if we have to check here about external requesters
285
// (or maybe already in instance persistence layer). This is all due
286
// to a change of persisting external requesters
287
ret.add(SharkEngineManager.getInstance().getObjectFactory().createProcessWrapper(userAuth,po.getId(),po.getProcessMgrName()));
288          }
289          return ret;
290       } catch (Exception JavaDoc ex) {
291          throw new BaseException(ex);
292       }
293    }
294
295    static List JavaDoc createProcessActivityWrappers (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId) throws BaseException {
296       try {
297          WfProcessInternal proc=SharkUtilities.getProcess(t,procId);
298          List JavaDoc l=proc.getAllActivities(t);
299          List JavaDoc ret=new ArrayList JavaDoc();
300          for (int i=0; i<l.size(); i++) {
301             WfActivityInternal act=(WfActivityInternal)l.get(i);
302             ret.add(SharkEngineManager.getInstance().getObjectFactory().createActivityWrapper(userAuth,proc.manager_name(t),procId,act.key(t)));
303          }
304          //System.err.println("AllProcesses for mgr "+mgr.getProcessDefinitionId()+" are "+ret);
305
return ret;
306       } catch (Exception JavaDoc ex) {
307          throw new BaseException(ex);
308       }
309    }
310
311    static List JavaDoc createAssignmentWrappers (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId,String JavaDoc actId) throws BaseException {
312       try {
313          List JavaDoc objs=SharkEngineManager
314             .getInstance()
315             .getInstancePersistenceManager()
316             .getAllValidAssignmentsForActivity(actId,t);
317
318          List JavaDoc pobjs=new ArrayList JavaDoc();
319          for (Iterator JavaDoc i=objs.iterator();i.hasNext();) {
320             AssignmentPersistenceInterface po=(AssignmentPersistenceInterface)i.next();
321             pobjs.add(SharkEngineManager.getInstance().getObjectFactory().createAssignmentWrapper(userAuth,po.getProcessMgrName(),procId,actId,po.getResourceUsername()));
322          }
323          return pobjs;
324       } catch (Exception JavaDoc ex) {
325          throw new BaseException(ex);
326       }
327    }
328
329    static List JavaDoc createAssignmentWrappers (SharkTransaction t,String JavaDoc userAuth,String JavaDoc username) throws BaseException {
330       try {
331          List JavaDoc objs=SharkUtilities.getResource(t,username).getAssignments(t);
332          List JavaDoc pobjs=new ArrayList JavaDoc();
333          for (Iterator JavaDoc i=objs.iterator();i.hasNext();) {
334             WfAssignmentInternal ass=(WfAssignmentInternal)i.next();
335             pobjs.add(SharkEngineManager.getInstance().getObjectFactory().createAssignmentWrapper(userAuth,ass.managerName(t),ass.processId(t),ass.activityId(t),username));
336          }
337          return pobjs;
338       } catch (Exception JavaDoc ex) {
339          throw new BaseException(ex);
340       }
341    }
342
343    static List JavaDoc createAllResourceWrappers (SharkTransaction t,String JavaDoc userAuth) throws BaseException {
344       try {
345          List JavaDoc resources=new ArrayList JavaDoc();
346          List JavaDoc l=SharkEngineManager.getInstance().getInstancePersistenceManager().getAllResources(t);
347          for (int i=0; i<l.size(); i++) {
348             ResourcePersistenceInterface po=(ResourcePersistenceInterface)l.get(i);
349             resources.add(SharkEngineManager.getInstance().getObjectFactory().createResourceWrapper(userAuth,po.getUsername()));
350          }
351          return resources;
352       } catch (Exception JavaDoc ex) {
353          throw new BaseException(ex);
354       }
355    }
356
357    static List JavaDoc createProcessHistoryEvents (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId) throws BaseException {
358       List JavaDoc history=new ArrayList JavaDoc();
359       try {
360          EventAuditManagerInterface eam = SharkEngineManager
361             .getInstance()
362             .getEventAuditManager();
363          if (null == eam)
364             return history;
365          List JavaDoc l = eam.restoreProcessHistory(procId, t);
366          for (int i=0; i<l.size(); i++) {
367             EventAuditPersistenceInterface audit=(EventAuditPersistenceInterface)l.get(i);
368             if (audit instanceof CreateProcessEventAuditPersistenceInterface) {
369                history.add(SharkEngineManager
370                               .getInstance()
371                               .getObjectFactory()
372                               .createCreateProcessEventAuditWrapper
373                               (userAuth,(CreateProcessEventAuditPersistenceInterface)audit));
374             } else if (audit instanceof DataEventAuditPersistenceInterface) {
375                history.add(SharkEngineManager
376                               .getInstance()
377                               .getObjectFactory()
378                               .createDataEventAuditWrapper
379                               (userAuth,(DataEventAuditPersistenceInterface)audit));
380             } else if (audit instanceof StateEventAuditPersistenceInterface) {
381                history.add(SharkEngineManager
382                               .getInstance()
383                               .getObjectFactory()
384                               .createStateEventAuditWrapper
385                               (userAuth,(StateEventAuditPersistenceInterface)audit));
386             }
387          }
388       } catch (Exception JavaDoc ex) {
389          throw new BaseException(ex);
390       }
391       return history;
392    }
393
394    static List JavaDoc createActivityHistoryEvents (SharkTransaction t,String JavaDoc userAuth,String JavaDoc procId,String JavaDoc actId) throws BaseException {
395       List JavaDoc history=new ArrayList JavaDoc();
396       try {
397          EventAuditManagerInterface eam = SharkEngineManager
398             .getInstance()
399             .getEventAuditManager();
400          if (null == eam)
401             return history;
402          List JavaDoc l = eam.restoreActivityHistory(procId,actId,t);
403          for (int i=0; i<l.size(); i++) {
404             EventAuditPersistenceInterface audit=(EventAuditPersistenceInterface)l.get(i);
405             if (audit instanceof AssignmentEventAuditPersistenceInterface) {
406                history.add(SharkEngineManager.getInstance().
407                               getObjectFactory().createAssignmentEventAuditWrapper(userAuth,(AssignmentEventAuditPersistenceInterface)audit));
408             } else if (audit instanceof DataEventAuditPersistenceInterface) {
409                history.add(SharkEngineManager.getInstance().
410                               getObjectFactory().createDataEventAuditWrapper(userAuth,(DataEventAuditPersistenceInterface)audit));
411             } else if (audit instanceof StateEventAuditPersistenceInterface) {
412                history.add(SharkEngineManager.getInstance().
413                               getObjectFactory().createStateEventAuditWrapper(userAuth,(StateEventAuditPersistenceInterface)audit));
414             }
415          }
416          return history;
417       } catch (Exception JavaDoc ex) {
418          throw new BaseException(ex);
419       }
420    }
421
422    static void reevaluateAssignments (SharkTransaction t) throws BaseException {
423       try {
424          List JavaDoc mgrs=new ArrayList JavaDoc();
425          List JavaDoc l=SharkEngineManager
426             .getInstance()
427             .getInstancePersistenceManager()
428             .getAllProcessMgrs(t);
429          for (int i=0; i<l.size(); i++) {
430             ProcessMgrPersistenceInterface po=(ProcessMgrPersistenceInterface)l.get(i);
431             reevalAssignments(t,po.getName());
432          }
433       } catch (Exception JavaDoc ex) {
434          throw new BaseException(ex);
435       }
436    }
437
438    static void reevalAssignments (SharkTransaction t,String JavaDoc mgrName) throws BaseException {
439       try {
440          List JavaDoc l=SharkEngineManager.getInstance().getInstancePersistenceManager().getAllProcessesForMgr(mgrName,t);
441          List JavaDoc ret=new ArrayList JavaDoc();
442          for (int i=0; i<l.size(); i++) {
443             ProcessPersistenceInterface po=(ProcessPersistenceInterface)l.get(i);
444             WfProcessInternal proc=SharkUtilities.getProcess(t,po.getId());
445             List JavaDoc acts=proc.getActiveActivities(t);
446             Iterator JavaDoc itActs=acts.iterator();
447             while (itActs.hasNext()) {
448                WfActivityInternal aint=(WfActivityInternal)itActs.next();
449                aint.reevaluateAssignments(t);
450             }
451          }
452       } catch (Exception JavaDoc ex) {
453          throw new BaseException(ex);
454       }
455    }
456
457    static boolean lock(SharkTransaction t, String JavaDoc processId) throws BaseException {
458       LockMaster lm = SharkEngineManager
459          .getInstance()
460          .getLockMaster();
461       try {
462          return (null != lm)? lm.lock(t, processId):true;
463       } catch (RootException e) {
464          throw new BaseException("lock not acquired",e);
465       }
466    }
467
468    static void unlock(SharkTransaction t) throws TransactionException {
469       LockMaster lm = SharkEngineManager
470          .getInstance()
471          .getLockMaster();
472       try {
473          if (null != lm)
474             lm.unlock(t);
475       } catch (RootException e) {
476          throw new TransactionException("lock not acquired",e);
477       }
478    }
479
480    static ParticipantMappingTransaction createParticipantMappingTransaction() throws TransactionException {
481       try {
482          ParticipantMappingManager mm = SharkEngineManager
483             .getInstance()
484             .getParticipantMapPersistenceManager();
485          return (null != mm) ? mm.getParticipantMappingTransaction() : null;
486       }catch(RootException e) {
487          throw new TransactionException(e);
488       }
489    }
490
491    static ApplicationMappingTransaction createApplicationMappingTransaction() throws TransactionException {
492       try {
493          ApplicationMappingManager mm = SharkEngineManager
494             .getInstance()
495             .getApplicationMapPersistenceManager();
496          return (null != mm) ? mm.getApplicationMappingTransaction() : null;
497       }catch(RootException e) {
498          throw new TransactionException(e);
499       }
500    }
501
502    static ScriptMappingTransaction createScriptMappingTransaction() throws TransactionException {
503       try {
504          ScriptMappingManager mm = SharkEngineManager
505             .getInstance()
506             .getScriptMapPersistenceManager();
507          return (null != mm) ? mm.getScriptMappingTransaction() : null;
508       }catch(RootException e) {
509          throw new TransactionException(e);
510       }
511    }
512
513    static void commitMappingTransaction(ParticipantMappingTransaction t) throws BaseException {
514       try {
515          if (null != t) {
516             t.commit();
517          }
518       } catch (TransactionException e) {
519          throw new BaseException(e);
520       }
521    }
522
523    static void rollbackMappingTransaction(ParticipantMappingTransaction t,RootException ex) throws BaseException {
524       SharkEngineManager.getInstance().getCallbackUtilities().error("Rollback of Participant transaction happened.",ex);
525       try {
526          if (null != t) {
527             t.rollback();
528          }
529       } catch (TransactionException e) {
530          throw new BaseException(e);
531       }
532    }
533
534    static void releaseMappingTransaction(ParticipantMappingTransaction t) throws BaseException {
535       try {
536          if (null != t) {
537             t.release();
538          }
539       } catch (TransactionException e) {
540          throw new BaseException(e);
541       }
542    }
543
544    static void commitMappingTransaction(ApplicationMappingTransaction t) throws BaseException {
545       try {
546          if (null != t) {
547             t.commit();
548          }
549       } catch (TransactionException e) {
550          throw new BaseException(e);
551       }
552    }
553
554    static void rollbackMappingTransaction(ApplicationMappingTransaction t,RootException ex) throws BaseException {
555       SharkEngineManager.getInstance().getCallbackUtilities().error("Rollback of ApplicationMapping transaction happened.",ex);
556       try {
557          if (null != t) {
558             t.rollback();
559          }
560       } catch (TransactionException e) {
561          throw new BaseException(e);
562       }
563    }
564
565    static void releaseMappingTransaction(ApplicationMappingTransaction t) throws BaseException {
566       try {
567          if (null != t) {
568             t.release();
569          }
570       } catch (TransactionException e) {
571          throw new BaseException(e);
572       }
573    }
574
575    static void commitMappingTransaction(ScriptMappingTransaction t) throws BaseException {
576       try {
577          if (null != t) {
578             t.commit();
579          }
580       } catch (TransactionException e) {
581          throw new BaseException(e);
582       }
583    }
584
585    static void rollbackMappingTransaction(ScriptMappingTransaction t,RootException ex) throws BaseException {
586       SharkEngineManager.getInstance().getCallbackUtilities().error("Rollback of ScriptMapping transaction happened.",ex);
587       try {
588          if (null != t) {
589             t.rollback();
590          }
591       } catch (TransactionException e) {
592          throw new BaseException(e);
593       }
594    }
595
596    static void releaseMappingTransaction(ScriptMappingTransaction t) throws BaseException {
597       try {
598          if (null != t) {
599             t.release();
600          }
601       } catch (TransactionException e) {
602          throw new BaseException(e);
603       }
604    }
605
606    static UserTransaction createUserTransaction() throws TransactionException {
607       UserTransactionFactory utf = SharkEngineManager
608          .getInstance()
609          .getUserTransactionFactory();
610       return (null != utf)?utf.createTransaction():null;
611    }
612
613    static void commitUserTransaction(UserTransaction t) throws BaseException {
614       try {
615          if (null != t) {
616             t.commit();
617          }
618       } catch (TransactionException e) {
619          throw new BaseException(e);
620       }
621    }
622
623    static void rollbackUserTransaction(UserTransaction t,RootException ex) throws BaseException {
624       SharkEngineManager.getInstance().getCallbackUtilities().error("Rollback of User transaction happened.",ex);
625       try {
626          if (null != t) {
627             t.rollback();
628          }
629       } catch (TransactionException e) {
630          throw new BaseException(e);
631       }
632    }
633
634    static void releaseUserTransaction(UserTransaction t) throws BaseException {
635       try {
636          if (null != t) {
637             t.release();
638          }
639       } catch (TransactionException e) {
640          throw new BaseException(e);
641       }
642    }
643
644    static RepositoryTransaction createRepositoryTransaction() throws TransactionException {
645       RepositoryPersistenceManager rpm = SharkEngineManager
646          .getInstance()
647          .getRepositoryPersistenceManager();
648       return (null != rpm)?rpm.createTransaction():null;
649    }
650
651    static void commitRepositoryTransaction(RepositoryTransaction t) throws BaseException {
652       try {
653          if (null != t) {
654             t.commit();
655          }
656       } catch (TransactionException e) {
657          throw new BaseException(e);
658       }
659    }
660
661    static void rollbackRepositoryTransaction(RepositoryTransaction t,RootException ex) throws BaseException {
662       SharkEngineManager.getInstance().getCallbackUtilities().error("Rollback of Repository transaction happened.",ex);
663       try {
664          if (null != t) {
665             t.rollback();
666          }
667       } catch (TransactionException e) {
668          throw new BaseException(e);
669       }
670    }
671
672    static void releaseRepositoryTransaction(RepositoryTransaction t) throws BaseException {
673       try {
674          if (null != t) {
675             t.release();
676          }
677       } catch (TransactionException e) {
678          throw new BaseException(e);
679       }
680    }
681
682    static SharkInternalTransaction createTransaction() throws TransactionException {
683       TransactionFactory tf = SharkEngineManager
684          .getInstance()
685          .getTransactionFactory();
686       return (null != tf)?tf.createTransaction():null;
687    }
688
689    static void commitTransaction(SharkTransaction t) throws BaseException {
690       try {
691          if (null != t) {
692             t.commit();
693             //unlock(t);
694
}
695       } catch (TransactionException e) {
696          throw new BaseException(e);
697       }
698    }
699
700    static void releaseTransaction(SharkTransaction t) throws BaseException {
701       try {
702          unlock(t);
703       } catch (TransactionException e) {
704          throw new BaseException(e);
705       } finally {
706          if (null != t) {
707             try {
708                t.release();
709             } catch (Exception JavaDoc ex) {
710                throw new BaseException(ex);
711             }
712          }
713       }
714    }
715
716    static void rollbackTransaction(SharkTransaction t,RootException ex) throws BaseException {
717       SharkEngineManager.getInstance().getCallbackUtilities().error("Rollback of Shark transaction happened.",ex);
718       emptyCaches(t);
719       if (null != t) {
720          try {
721             t.rollback();
722             //unlock(t);
723
} catch (TransactionException oops) {
724             //System.out.println("EXC");
725
throw new BaseException(oops);
726          }
727       }
728    }
729
730    static void emptyCaches (SharkTransaction t) {
731       CacheMgr cm = SharkEngineManager
732          .getInstance()
733          .getCacheManager();
734       if (null != cm) {
735          ProcessCache procache = cm.getProcessCache();
736          ResourceCache rescache=cm.getResourceCache();
737          LockMaster lm = SharkEngineManager
738             .getInstance()
739             .getLockMaster();
740          if (null != lm) {
741             try {
742                List JavaDoc processLocks = lm.getLocks(t);
743                for (Iterator JavaDoc it = processLocks.iterator(); it.hasNext();) {
744                   String JavaDoc pLock = (String JavaDoc)it.next();
745                   procache.remove(pLock);
746                }
747             } catch (RootException e) {}
748          } else {
749             try {
750                int size=procache.getSize();
751                procache.setSize(0);
752                procache.setSize(size);
753             } catch (RootException e) {}
754          }
755          try {
756             int size=rescache.getSize();
757             rescache.setSize(0);
758             rescache.setSize(size);
759          } catch (RootException e) {}
760       }
761    }
762
763    static void addResourceToCache(SharkTransaction t,WfResourceInternal r) throws BaseException {
764       try {
765          ((SharkInternalTransaction)t).addToTransaction(r.resource_key(t),r);
766       } catch (RootException ex) {
767          throw new BaseException(ex);
768       }
769       CacheMgr cm = SharkEngineManager.getInstance().getCacheManager();
770       if (null != cm)
771          try {
772             cm.getResourceCache().add(r.resource_key(t),r);
773          } catch (RootException e) {}
774    }
775
776    static void removeResourceFromCache(SharkTransaction t,WfResourceInternal r) throws RootException {
777       //((SharkInternalTransaction)t).removeResource(r.resource_key(t));
778
CacheMgr cm = SharkEngineManager.getInstance().getCacheManager();
779       if (null != cm)
780          cm.getResourceCache().remove(r.resource_key(t));
781    }
782
783    static WfResourceInternal getResourceFromCache(SharkTransaction t,String JavaDoc username) throws RootException {
784       WfResourceInternal res=((SharkInternalTransaction)t).getResource(username);
785       if (res==null) {
786          CacheMgr cm = SharkEngineManager.getInstance().getCacheManager();
787          if (null != cm) {
788             try {
789                res=cm.getResourceCache().get(username);
790                if (res!=null) {
791                   ((SharkInternalTransaction)t).addToTransaction(username, res);
792                }
793             } catch (RootException ex) {}
794          }
795       }
796       return res;
797    }
798
799    static WfResourceInternal getResource (SharkTransaction t, String JavaDoc username) throws BaseException{
800       try {
801          SharkEngineManager em = SharkEngineManager.getInstance();
802          ObjectFactory objectFactory=em.getObjectFactory();
803
804          WfResourceInternal res=SharkUtilities.getResourceFromCache(t,username);
805          if (res==null) {
806             PersistentManagerInterface pmi=em.getInstancePersistenceManager();
807             ResourcePersistenceInterface po=pmi.restoreResource(username, t);
808             if (po!=null) {
809                res=objectFactory.createResource(po);
810                SharkUtilities.addResourceToCache(t,res);
811             }
812          }
813          return res;
814       } catch (Exception JavaDoc ex) {
815          throw new BaseException(ex);
816       }
817    }
818
819    static void addProcessToCache(SharkTransaction t,WfProcessInternal p) throws BaseException {
820       try {
821          ((SharkInternalTransaction)t).addToTransaction(p.key(t),p);
822       } catch (RootException ex) {
823          throw new BaseException(ex);
824       }
825       CacheMgr cm = SharkEngineManager.getInstance().getCacheManager();
826       if (null != cm)
827          try {
828             cm.getProcessCache().add(p.key(t),p);
829          } catch (RootException e) {}
830    }
831
832    static void removeProcessFromCache(SharkTransaction t,WfProcessInternal p) throws RootException {
833       //((SharkInternalTransaction)t).removeProcess(p.key(t));
834
CacheMgr cm = SharkEngineManager.getInstance().getCacheManager();
835       if (null != cm)
836          cm.getProcessCache().remove(p.key(t));
837    }
838
839    private static WfProcessInternal getProcessFromCache(SharkTransaction t,String JavaDoc procId) throws RootException {
840       WfProcessInternal proc=((SharkInternalTransaction)t).getProcess(procId);
841       if (proc==null) {
842          CacheMgr cm = SharkEngineManager.getInstance().getCacheManager();
843          if (null != cm) {
844             try {
845                proc=cm.getProcessCache().get(procId);
846             } catch (RootException ex) {}
847          }
848       }
849       return proc;
850    }
851
852    static WfProcessInternal getProcess (SharkTransaction t,String JavaDoc procId) throws BaseException {
853       SharkUtilities.lock(t,procId);
854       try {
855          ObjectFactory objectFactory=SharkEngineManager.getInstance().getObjectFactory();
856
857          WfProcessInternal proc=SharkUtilities.getProcessFromCache(t,procId);
858
859          if (proc==null) {
860             PersistentManagerInterface pmi=SharkEngineManager
861                .getInstance()
862                .getInstancePersistenceManager();
863             ProcessPersistenceInterface po=pmi.restoreProcess(procId,t);
864             if (po!=null) {
865                proc=objectFactory.createProcess(po);
866                SharkUtilities.addProcessToCache(t,proc);
867             }
868          }
869          return proc;
870       } catch (Exception JavaDoc ex) {
871          throw new BaseException(ex);
872       }
873    }
874
875    static WfProcessMgrInternal getProcessMgr (SharkTransaction t, String JavaDoc name) throws BaseException {
876       try {
877          WfProcessMgrInternal mgr=null;
878
879          PersistentManagerInterface pmi=SharkEngineManager
880             .getInstance()
881             .getInstancePersistenceManager();
882
883          ProcessMgrPersistenceInterface po=pmi.restoreProcessMgr(name, t);
884          if (po!=null) {
885             mgr=SharkEngineManager.getInstance().getObjectFactory().createProcessMgr(po);
886          }
887          return mgr;
888       } catch (Exception JavaDoc ex) {
889          throw new BaseException(ex);
890       }
891    }
892
893    static WfActivityInternal getActivity (SharkTransaction t,String JavaDoc procId,String JavaDoc actId) throws BaseException{
894       try {
895          //System.out.println("PID="+procId+",aid="+actId);
896
WfProcessInternal proc=getProcess(t,procId);
897          WfActivityInternal act=proc.getActivity(t,actId);
898          return act;
899       } catch (Exception JavaDoc ex) {
900          throw new BaseException(ex);
901       }
902    }
903
904    static WfAssignmentInternal getAssignment (SharkTransaction t, String JavaDoc procId,String JavaDoc actId,String JavaDoc username) throws BaseException {
905       try {
906          WfResourceInternal res=getResource(t,username);
907          WfAssignmentInternal ass=res.getAssignment(t,procId,actId);
908          return ass;
909       } catch (Exception JavaDoc ex) {
910          throw new BaseException(ex);
911       }
912    }
913
914    static WfAssignment getAssignmentWrapper (SharkTransaction t, String JavaDoc userAuth, String JavaDoc procId,String JavaDoc assId) throws BaseException {
915       try {
916          String JavaDoc[] tokens=MiscUtilities.tokenize(assId,"#");
917          String JavaDoc actId=tokens[0];
918          String JavaDoc uname=tokens[1];
919          //WfActivityInternal act=SharkUtilities.getActivity(t,procId,actId);
920
WfResourceInternal res=getResource(t,uname);
921          WfAssignmentInternal ass=null;
922          if (res!=null) {
923             ass=res.getAssignment(t, procId, actId);
924          }
925          if (ass!=null) {
926             return SharkEngineManager
927                .getInstance()
928                .getObjectFactory()
929                .createAssignmentWrapper(userAuth,ass.managerName(t),procId,actId,uname);
930          } else {
931             return null;
932          }
933       } catch (Exception JavaDoc ex) {
934          throw new BaseException ("Invalid process or assignment Id",ex);
935       }
936    }
937
938
939    static List JavaDoc getAssignments (SharkTransaction t,
940                                String JavaDoc engineName,
941                                String JavaDoc procId,
942                                String JavaDoc actId,
943                                List JavaDoc userIds,
944                                List JavaDoc responsibleIds,
945                                String JavaDoc processRequesterId,
946                                PerformerData xpdlParticipant,
947                                List JavaDoc xpdlResponsibleParticipants) throws RootException {
948       AssignmentManager am=SharkEngineManager.getInstance().getAssignmentManager();
949       if (am!=null) {
950          return am.getAssignments(t,
951                                   engineName,
952                                   procId,
953                                   actId,
954                                   userIds,
955                                   responsibleIds,
956                                   processRequesterId,
957                                   xpdlParticipant,
958                                   xpdlResponsibleParticipants);
959       }
960
961       // currently, this code is the same as standard assignment manager's
962
if (userIds!=null && userIds.size()>0) return userIds;
963       if (responsibleIds!=null && responsibleIds.size()>0) return responsibleIds;
964       //if (extAttribs!=null)
965
List JavaDoc ret=new ArrayList JavaDoc();
966       ret.add(processRequesterId);
967       return ret;
968    }
969
970    static List JavaDoc getSecureAssignments(
971       SharkTransaction t,
972       String JavaDoc engineName,
973       String JavaDoc procId,
974       String JavaDoc actId,
975       List JavaDoc userIds) throws RootException {
976
977       SecurityManager JavaDoc sm=SharkEngineManager.getInstance().getSecurityManager();
978       if (sm!=null) {
979          return sm.getAssignments(t,engineName,procId,actId,userIds);
980       }
981       return userIds;
982    }
983
984    static boolean validateUser (String JavaDoc username,String JavaDoc pwd) throws RootException {
985       AuthenticationManager am=SharkEngineManager.getInstance().getAuthenticationManager();
986       boolean ret=true;
987       UserTransaction ut = null;
988       try {
989          ut = SharkUtilities.createUserTransaction();
990          if (am!=null) {
991             ret=am.validateUser(ut,username,pwd);
992          }
993          //SharkUtilities.commitUserTransaction(ut);
994
return ret;
995       }
996       catch (RootException e) {
997          //SharkUtilities.rollbackUserTransaction(ut);
998
throw e;
999       } finally {
1000         SharkUtilities.releaseUserTransaction(ut);
1001      }
1002   }
1003
1004   /**
1005    * Returns true if the data type of attribute coresponds to the required one.
1006    */

1007   static boolean checkDataType (SharkTransaction t,WorkflowProcess wp,String JavaDoc nm,Object JavaDoc oldVal,Object JavaDoc val) throws BaseException {
1008      if (val==null) {
1009         return true;
1010      }
1011      if (oldVal!=null && oldVal.getClass().isInstance(val)) {
1012         return true;
1013      } else {
1014         if (oldVal==null) {
1015            XMLCollectionElement dfOrFp=(XMLCollectionElement)wp.getAllVariables().get(nm);
1016            if (dfOrFp==null) {
1017               throw new BaseException("Can't find variable with Id="+nm+" in XPDL definition");
1018            }
1019            Class JavaDoc cls=SharkUtilities.getJavaClass(dfOrFp);
1020            if (cls.isInstance(val)) {
1021               return true;
1022            }
1023         }
1024      }
1025      return false;
1026   }
1027
1028   static Object JavaDoc getInitialValue(XMLCollectionElement dfOrFp,boolean forceDefaultValueForType) {
1029      String JavaDoc initialValStr=null;
1030      if (dfOrFp instanceof DataField) {
1031         initialValStr=((DataField)dfOrFp).getInitialValue();
1032         if (initialValStr.equalsIgnoreCase("null")) {
1033            return null;
1034         }
1035         if (forceDefaultValueForType) {
1036            initialValStr="";
1037         }
1038      } else {
1039         initialValStr="";
1040      }
1041      //System.err.println("Creating IA for "+dfOrFp.getID()+" - javaType="+javaType+", IV="+initialValStr);
1042
return createInitialValue(initialValStr,dfOrFp);
1043   }
1044
1045   static Class JavaDoc getJavaClass (XMLCollectionElement dfOrFp) {
1046      String JavaDoc jt=((DataType)dfOrFp.get("DataType")).getJavaType();
1047      //System.out.println("GJC-jt for "+dfOrFp.getID()+" is "+jt);
1048
Class JavaDoc cls=java.lang.Object JavaDoc.class;
1049      try {
1050         cls=Class.forName(jt);
1051      } catch (Exception JavaDoc ex) {}
1052      return cls;
1053   }
1054
1055   private static Object JavaDoc createInitialValue (String JavaDoc initialValStr,
1056                                             XMLCollectionElement dfOrFp) {
1057      String JavaDoc javaType=((DataType)dfOrFp.get("DataType")).getJavaType();
1058      //System.out.println("JT from XPDL of dforfp "+dfOrFp+" is "+javaType);
1059

1060      //System.err.println("Creating IA for javaType="+javaType+" for ivs="+initialValStr+",for dfOrFp "+dfOrFp);
1061
Object JavaDoc any=null;
1062      if (javaType.equals("java.lang.Boolean")) {
1063         Boolean JavaDoc value=new Boolean JavaDoc(false);
1064         try {
1065            if (initialValStr.equalsIgnoreCase("true") || initialValStr.equals("1")) {
1066               value=new Boolean JavaDoc(true);
1067            } else if (initialValStr.equalsIgnoreCase("false") || initialValStr.equals("0")) {
1068               value=new Boolean JavaDoc(false);
1069            }
1070         } catch (Exception JavaDoc ex) {}
1071         any=value;
1072      } else if (javaType.equals("java.lang.String")) {
1073         any=initialValStr;
1074      } else if (javaType.equals("java.lang.Long")) {
1075         Long JavaDoc value;
1076         try {
1077            value=new Long JavaDoc(initialValStr);
1078         } catch (NumberFormatException JavaDoc nfe) {
1079            try {
1080               Double JavaDoc d=new Double JavaDoc(initialValStr);
1081               value=new Long JavaDoc(d.longValue());
1082            } catch (Exception JavaDoc ex) {
1083               value=new Long JavaDoc(0);
1084            }
1085         }
1086         any=value;
1087      } else if (javaType.equals("java.lang.Double")) {
1088         Double JavaDoc value;
1089         try {
1090            value=new Double JavaDoc(initialValStr);
1091         } catch (NumberFormatException JavaDoc nfe) {
1092            value=new Double JavaDoc(0);
1093         }
1094         any=value;
1095      } else if (javaType.equals("java.util.Date")) {
1096         Date JavaDoc value;
1097         try {
1098            value=DateFormat.getDateInstance().parse(initialValStr);
1099         } catch (ParseException JavaDoc pe) {
1100            try {
1101               value=new Date JavaDoc(Long.parseLong(initialValStr));
1102            } catch (Exception JavaDoc ex) {
1103               value=new Date JavaDoc();
1104            }
1105         }
1106         any=value;
1107
1108      } else {
1109         try {
1110            /*if (initialValStr!=null && initialValStr.trim().equalsIgnoreCase("null")) {
1111             any=null;
1112             //System.out.println("CREATED NULL OBJ FOR xpdlt "+xpdlType);
1113             } else {*/

1114            Class JavaDoc cls=Class.forName(javaType);
1115            if (!cls.isInterface()) {
1116               any=cls.newInstance();
1117            }
1118            //System.out.println("CREATED OBJ FOR xpdlt "+xpdlType);
1119
//}
1120
} catch (Throwable JavaDoc ex) {
1121            SharkEngineManager.getInstance().getCallbackUtilities().warn("The instantiation of object for class "+javaType+" failed");
1122            //ex.printStackTrace();
1123
}
1124      }
1125      //System.err.println("Created value is "+any);
1126
return any;
1127   }
1128
1129   /**
1130    * Returns the full path to the repository with a given name. The name of
1131    * repository represents an entry in econfig file, where the location of
1132    * the repository is given. If repository doesn't exist, the one is created
1133    * at that location.
1134    * @param rep
1135    * @return String containing full path to the repository
1136    */

1137   static String JavaDoc getRepository (String JavaDoc rep) {
1138      String JavaDoc rdPath=SharkEngineManager
1139         .getInstance()
1140         .getCallbackUtilities()
1141         .getProperty(SharkConstants.ROOT_DIRECTORY_PATH_PROP);
1142      //System.setProperty("user.dir",rdPath);
1143
CallbackUtilities cus=SharkEngineManager.getInstance().getCallbackUtilities();
1144      String JavaDoc path=cus.getProperty(rep);
1145
1146      if (path!=null) {
1147         // if repository don't exist, create it
1148
File JavaDoc f=new File JavaDoc(path);
1149
1150         if (!f.isAbsolute()) {
1151            f=new File JavaDoc(XMLUtil.createPath(rdPath,path));
1152            //f=f.getAbsoluteFile();
1153
}
1154
1155         if (!f.exists()) {
1156            cus.warn("The repository "+rep+" does not exist - trying to create one!");
1157            if (!f.mkdir()) {
1158               cus.warn("The repository "+rep+" can't be created!");
1159               return path;
1160            }
1161         }
1162
1163         try {
1164            String JavaDoc er=f.getCanonicalPath();
1165            cus.info("The repository "+rep+" is at "+er);
1166            return er;
1167         } catch (Exception JavaDoc ex) {
1168            String JavaDoc er=f.getAbsolutePath();
1169            cus.info("The repository "+rep+" is at "+er);
1170            return er;
1171         }
1172      } else {
1173         cus.warn("The repository "+rep+" does not exist!");
1174         return null;
1175      }
1176   }
1177
1178   static Package JavaDoc getPackage (String JavaDoc pkgId,String JavaDoc pkgVer) throws BaseException {
1179      XMLInterface xmlInterface=SharkEngineManager.getInstance().getXMLInterface();
1180      //System.out.println("Getting pkg "+pkgIdWithVersion);
1181
Package JavaDoc pkg=null;
1182      if (pkgVer!=null) {
1183         pkg=xmlInterface.getPackageByIdAndVersion(pkgId, pkgVer);
1184      } else {
1185         pkg=xmlInterface.getPackageById(pkgId);
1186      }
1187      if (pkg==null) {
1188         SharkEngineManager.getInstance().getCallbackUtilities().info("Package ["+pkgId+","+pkgVer+"] is not found - synchronizing XPDL caches ...");
1189         RepositoryTransaction t=null;
1190         try {
1191            t=SharkUtilities.createRepositoryTransaction();
1192            synchronizeXPDLCache(t);
1193            if (pkgVer!=null) {
1194               pkg=xmlInterface.getPackageByIdAndVersion(pkgId, pkgVer);
1195            } else {
1196               pkg=xmlInterface.getPackageById(pkgId);
1197            }
1198            if (pkg==null) {
1199               throw new BaseException("Package with Id="+pkgId+" and version="+pkgVer+" can't be found!");
1200            }
1201         } catch (RootException e) {
1202            //SharkUtilities.rollbackRepositoryTransaction(t,e);
1203
if (e instanceof BaseException)
1204               throw (BaseException)e;
1205            else
1206               throw new BaseException(e);
1207         } finally {
1208            SharkUtilities.releaseRepositoryTransaction(t);
1209         }
1210      }
1211      return pkg;
1212   }
1213
1214   static WorkflowProcess getWorkflowProcess (String JavaDoc pkgId,String JavaDoc pkgVer,String JavaDoc wpId) throws BaseException {
1215      try {
1216         return getPackage(pkgId,pkgVer).getWorkflowProcess(wpId);
1217      } catch (Exception JavaDoc ex) {
1218         return null;
1219      }
1220   }
1221
1222   static Activity getActivityDefinition (String JavaDoc pkgId,
1223                                          String JavaDoc pkgVer,
1224                                          String JavaDoc wpId,
1225                                          String JavaDoc aSetId,
1226                                          String JavaDoc actDefId) throws BaseException {
1227      WorkflowProcess wp=getWorkflowProcess(pkgId,pkgVer,wpId);
1228      Activities acts=null;
1229      if (aSetId!=null) {
1230         ActivitySet as=wp.getActivitySet(aSetId);
1231         acts=as.getActivities();
1232      } else {
1233         acts=wp.getActivities();
1234      }
1235      return acts.getActivity(actDefId);
1236   }
1237
1238   /**
1239    * When activity is within block, this is recursive implementation.
1240    * The recursion is needed because the activities block can be inside
1241    * some other block.
1242    */

1243   static Activity getActivityDefinition (SharkTransaction t,WfActivityInternal act,WorkflowProcess wp,WfActivityInternal parentAct) throws BaseException {
1244      /*if (act.block_activity_id(t)!=null) {
1245       parentAct=getActivity(t,act.process_id(t),act.block_activity_id(t));
1246
1247       //if (parentAct==null) System.err.println("SSSSSSSSSSSSSSSSWWWWWWWWWWWWWWWWWWWWWRRRRRRRRRRRRRRRRRR");
1248
1249       }*/

1250      if (parentAct==null) {
1251         return wp.getActivities().
1252            getActivity(((WfActivityInternal)act).activity_definition_id(t));
1253      } else {
1254         Activity bad=getActivityDefinition(t,parentAct,wp,parentAct.block_activity(t));
1255         BlockActivity ba=bad.getActivityTypes().getBlockActivity();
1256         String JavaDoc asId=ba.getBlockId();
1257         ActivitySet as=wp.getActivitySet(asId);
1258         return as.getActivity(((WfActivityInternal)act).activity_definition_id(t));
1259      }
1260   }
1261
1262   static Map JavaDoc createContextMap (SharkTransaction t,
1263                                WfActivityInternal act,
1264                                ActualParameters actualParameters,
1265                                FormalParameters formalParameters) throws Exception JavaDoc {
1266      String JavaDoc packageId = act.container(t).package_id(t);
1267      String JavaDoc packageVer = act.container(t).manager_version(t);
1268      return createContextMap(t,
1269                              act.process_context(t),
1270                              actualParameters,
1271                              formalParameters,
1272                              packageId,
1273                              packageVer);
1274
1275   }
1276
1277   public static Map JavaDoc createContextMap (SharkTransaction t,
1278                                Map JavaDoc context,
1279                                ActualParameters actualParameters,
1280                                FormalParameters formalParameters,
1281                                String JavaDoc packageId,
1282                                String JavaDoc packageVer) throws Exception JavaDoc {
1283      Evaluator evaluator=SharkEngineManager
1284         .getInstance()
1285         .getScriptingManager()
1286         .getEvaluator(t,
1287                       SharkUtilities.getScriptType(packageId,packageVer));
1288      Map JavaDoc m=new HashMap JavaDoc();
1289      // When this is a subflow or tool activity, it's context contains
1290
// actual parameters to be passed to the referenced
1291
// process or tool in exact order. The map to be passed has to have
1292
// the formal parameter ids of subflow process or application as keys,
1293
// and actual parameter values of subflow or tool activity as values
1294
// We iterate through the actual and formal parameter list
1295
// simultaneously and create a map.
1296
Iterator JavaDoc fps=formalParameters.toElements().iterator();
1297      // Get actual parameters definition of the subflow activity
1298
Iterator JavaDoc aps=actualParameters.toElements().iterator();
1299      while(aps.hasNext() && fps.hasNext()){
1300         ActualParameter ap=(ActualParameter)aps.next();
1301         FormalParameter fp=(FormalParameter)fps.next();
1302         String JavaDoc fpMode=fp.getMode();
1303         Object JavaDoc val=null;
1304         // if the actual param is an expression, calculate it using
1305
// process evaluator
1306
String JavaDoc apVal=ap.toValue().trim();
1307         if (fpMode.equals(XPDLConstants.FORMAL_PARAMETER_MODE_IN)) {
1308            XMLCollectionElement dfOrFp=null;
1309            WorkflowProcess wp=XMLUtil.getWorkflowProcess(ap);
1310            dfOrFp=wp.getDataField(apVal);
1311            if (dfOrFp==null) {
1312               dfOrFp=XMLUtil.getPackage(wp).getDataField(apVal);
1313               if (dfOrFp==null) {
1314                  dfOrFp=wp.getFormalParameter(apVal);
1315               }
1316            }
1317            if (dfOrFp!=null) {
1318               val=context.get(dfOrFp.getId());
1319            }
1320            if (val==null) {
1321               val=evaluator.evaluateExpression(t,apVal,context,getJavaClass(fp));
1322            }
1323
1324            /*if (!isComplexWRD(eval)) {
1325             val=getValue(fp,eval.toString());
1326             } else {
1327             if (!getJavaType(fp).endsWith(eval.getClass().getName())) {
1328             throw new Exception ("Incorrect data type");
1329             } else {
1330             val=eval;
1331             }
1332             }*/

1333            // else, get the value of the activity context variable
1334
} else if (!fpMode.equals(XPDLConstants.FORMAL_PARAMETER_MODE_OUT)) {
1335            if (!context.containsKey(apVal)) {
1336               throw new Exception JavaDoc("There is no variable "+apVal+" in a context");
1337            }
1338            val=context.get(apVal);
1339         } else {
1340            val=getInitialValue(SharkUtilities.getVariable(actualParameters, apVal),true);
1341         }
1342         m.put(fp.getId(),val);
1343      }
1344      return m;
1345   }
1346
1347   static Map JavaDoc createContextMap (SharkTransaction t,
1348                                Map JavaDoc context,
1349                                ActualParameters actualParameters,
1350                                String JavaDoc packageId,
1351                                String JavaDoc packageVer) throws Exception JavaDoc {
1352      Evaluator evaluator=SharkEngineManager
1353         .getInstance()
1354         .getScriptingManager()
1355         .getEvaluator(t,
1356                       SharkUtilities.getScriptType(packageId,packageVer));
1357      Map JavaDoc m=new HashMap JavaDoc();
1358      // Get actual parameters definition of the subflow activity
1359
Iterator JavaDoc aps=actualParameters.toElements().iterator();
1360      int i=0;
1361      while(aps.hasNext()){
1362         ActualParameter ap=(ActualParameter)aps.next();
1363         Object JavaDoc val=null;
1364         // if the actual param is an expression, calculate it using
1365
// process evaluator
1366
String JavaDoc apVal=ap.toValue().trim();
1367         XMLCollectionElement dfOrFp=null;
1368         WorkflowProcess wp=XMLUtil.getWorkflowProcess(ap);
1369         dfOrFp=wp.getDataField(apVal);
1370         if (dfOrFp==null) {
1371            dfOrFp=XMLUtil.getPackage(wp).getDataField(apVal);
1372            if (dfOrFp==null) {
1373               dfOrFp=wp.getFormalParameter(apVal);
1374            }
1375         }
1376
1377         if (dfOrFp!=null) {
1378            val=context.get(apVal);
1379         }
1380         if (val==null) {
1381            apVal=SharkConstants.REMOTE_SUBPROCESS_EVAL_PARAM+String.valueOf(i++);
1382            val=evaluator.evaluateExpression(t,apVal,context,null);
1383         }
1384
1385         m.put(apVal,val);
1386      }
1387      return m;
1388   }
1389
1390
1391   static String JavaDoc[][] getPackageExtendedAttributeNameValuePairs (
1392      SharkTransaction t,
1393      String JavaDoc pkgId) throws Exception JavaDoc {
1394
1395      String JavaDoc curVer=SharkUtilities.getCurrentPkgVersion(pkgId,false);
1396      Package JavaDoc pkg=SharkUtilities.getPackage(pkgId,curVer);
1397      ExtendedAttributes eas=pkg.getExtendedAttributes();
1398      return SharkUtilities.getExtAttribNameValues(eas);
1399   }
1400
1401   static String JavaDoc[] getPackageExtendedAttributeNames (
1402      SharkTransaction t,
1403      String JavaDoc pkgId) throws Exception JavaDoc {
1404
1405      String JavaDoc curVer=SharkUtilities.getCurrentPkgVersion(pkgId,false);
1406      Package JavaDoc pkg=SharkUtilities.getPackage(pkgId,curVer);
1407      ExtendedAttributes eas=pkg.getExtendedAttributes();
1408      return SharkUtilities.getExtAttribNames(eas);
1409   }
1410
1411   static String JavaDoc getPackageExtendedAttributeValue (SharkTransaction t,
1412                                                   String JavaDoc pkgId,
1413                                                   String JavaDoc extAttrName) throws Exception JavaDoc {
1414      String JavaDoc curVer=SharkUtilities.getCurrentPkgVersion(pkgId,false);
1415      Package JavaDoc pkg=SharkUtilities.getPackage(pkgId,curVer);
1416      ExtendedAttributes eas=pkg.getExtendedAttributes();
1417      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1418   }
1419
1420   static String JavaDoc[][] getProcessDefinitionExtendedAttributeNameValuePairs (
1421      SharkTransaction t,
1422      String JavaDoc mgrName) throws Exception JavaDoc {
1423
1424      WfProcessMgrInternal mgr=SharkUtilities.getProcessMgr(t,mgrName);
1425      WorkflowProcess pDef=SharkUtilities.
1426         getWorkflowProcess(mgr.package_id(t),
1427                            mgr.version(t),
1428                            mgr.process_definition_id(t));
1429      ExtendedAttributes eas=pDef.getExtendedAttributes();
1430      return SharkUtilities.getExtAttribNameValues(eas);
1431   }
1432
1433   static String JavaDoc[] getProcessDefinitionExtendedAttributeNames (
1434      SharkTransaction t,
1435      String JavaDoc mgrName) throws Exception JavaDoc {
1436
1437      WfProcessMgrInternal mgr=SharkUtilities.getProcessMgr(t,mgrName);
1438      WorkflowProcess pDef=SharkUtilities.
1439         getWorkflowProcess(mgr.package_id(t),
1440                            mgr.version(t),
1441                            mgr.process_definition_id(t));
1442      ExtendedAttributes eas=pDef.getExtendedAttributes();
1443      return SharkUtilities.getExtAttribNames(eas);
1444   }
1445
1446   static String JavaDoc getProcessDefinitionExtendedAttributeValue (SharkTransaction t,
1447                                                             String JavaDoc mgrName,
1448                                                             String JavaDoc extAttrName) throws Exception JavaDoc {
1449      WfProcessMgrInternal mgr=SharkUtilities.getProcessMgr(t,mgrName);
1450      WorkflowProcess pDef=SharkUtilities.
1451         getWorkflowProcess(mgr.package_id(t),
1452                            mgr.version(t),
1453                            mgr.process_definition_id(t));
1454      ExtendedAttributes eas=pDef.getExtendedAttributes();
1455      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1456   }
1457
1458   static String JavaDoc[][] getProcessExtendedAttributeNameValuePairs (
1459      SharkTransaction t,
1460      String JavaDoc procId) throws Exception JavaDoc {
1461
1462      WfProcessInternal proc=SharkUtilities.getProcess(t,procId);
1463      WorkflowProcess pDef=SharkUtilities.
1464         getWorkflowProcess(proc.package_id(t),
1465                            proc.manager_version(t),
1466                            proc.process_definition_id(t));
1467      ExtendedAttributes eas=pDef.getExtendedAttributes();
1468      return SharkUtilities.getExtAttribNameValues(eas);
1469   }
1470
1471   static String JavaDoc[] getProcessExtendedAttributeNames (
1472      SharkTransaction t,
1473      String JavaDoc procId) throws Exception JavaDoc {
1474
1475      WfProcessInternal proc=SharkUtilities.getProcess(t,procId);
1476      WorkflowProcess pDef=SharkUtilities.
1477         getWorkflowProcess(proc.package_id(t),
1478                            proc.manager_version(t),
1479                            proc.process_definition_id(t));
1480      ExtendedAttributes eas=pDef.getExtendedAttributes();
1481      return SharkUtilities.getExtAttribNames(eas);
1482   }
1483
1484   static String JavaDoc getProcessExtendedAttributeValue (SharkTransaction t,
1485                                                   String JavaDoc procId,
1486                                                   String JavaDoc extAttrName) throws Exception JavaDoc {
1487      WfProcessInternal proc=SharkUtilities.getProcess(t,procId);
1488      WorkflowProcess pDef=SharkUtilities.
1489         getWorkflowProcess(proc.package_id(t),
1490                            proc.manager_version(t),
1491                            proc.process_definition_id(t));
1492      ExtendedAttributes eas=pDef.getExtendedAttributes();
1493      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1494   }
1495
1496   static String JavaDoc getActivitiesExtendedAttributes (SharkTransaction t,
1497                                                  String JavaDoc procId,
1498                                                  String JavaDoc actId) throws Exception JavaDoc {
1499      WfActivityInternal act=SharkUtilities.getActivity(t,procId,actId);
1500      Activity aDef=SharkUtilities.
1501         getActivityDefinition(t,
1502                               act,
1503                               SharkUtilities.
1504                                  getWorkflowProcess(act.container(t).package_id(t),
1505                                                     act.container(t).manager_version(t),
1506                                                     act.container(t).process_definition_id(t)),
1507                               act.block_activity(t));
1508      return aDef.getExtendedAttributes().getExtendedAttributesString();
1509   }
1510
1511   static String JavaDoc[][] getActivitiesExtendedAttributeNameValuePairs (
1512      SharkTransaction t,
1513      String JavaDoc procId,
1514      String JavaDoc actId) throws Exception JavaDoc {
1515
1516      WfActivityInternal act=SharkUtilities.getActivity(t,procId,actId);
1517      Activity aDef=SharkUtilities.
1518         getActivityDefinition(t,
1519                               act,
1520                               SharkUtilities.
1521                                  getWorkflowProcess(act.container(t).package_id(t),
1522                                                     act.container(t).manager_version(t),
1523                                                     act.container(t).process_definition_id(t)),
1524                               act.block_activity(t));
1525      ExtendedAttributes eas=aDef.getExtendedAttributes();
1526      return SharkUtilities.getExtAttribNameValues(eas);
1527   }
1528
1529   static String JavaDoc[] getActivitiesExtendedAttributeNames (
1530      SharkTransaction t,
1531      String JavaDoc procId,
1532      String JavaDoc actId) throws Exception JavaDoc {
1533
1534      WfActivityInternal act=SharkUtilities.getActivity(t,procId,actId);
1535      Activity aDef=SharkUtilities.
1536         getActivityDefinition(t,
1537                               act,
1538                               SharkUtilities.
1539                                  getWorkflowProcess(act.container(t).package_id(t),
1540                                                     act.container(t).manager_version(t),
1541                                                     act.container(t).process_definition_id(t)),
1542                               act.block_activity(t));
1543      ExtendedAttributes eas=aDef.getExtendedAttributes();
1544      return SharkUtilities.getExtAttribNames(eas);
1545   }
1546
1547   static String JavaDoc getActivitiesExtendedAttributeValue (SharkTransaction t,
1548                                                      String JavaDoc procId,
1549                                                      String JavaDoc actId,
1550                                                      String JavaDoc extAttrName) throws Exception JavaDoc {
1551      WfActivityInternal act=SharkUtilities.getActivity(t,procId,actId);
1552      Activity aDef=SharkUtilities.
1553         getActivityDefinition(t,
1554                               act,
1555                               SharkUtilities.
1556                                  getWorkflowProcess(act.container(t).package_id(t),
1557                                                     act.container(t).manager_version(t),
1558                                                     act.container(t).process_definition_id(t)),
1559                               act.block_activity(t));
1560      ExtendedAttributes eas=aDef.getExtendedAttributes();
1561      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1562   }
1563
1564   static String JavaDoc[][] getDefVariableExtendedAttributeNameValuePairs (
1565      SharkTransaction t,
1566      String JavaDoc mgrName,
1567      String JavaDoc variableId) throws Exception JavaDoc {
1568
1569      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,mgrName,variableId,true);
1570      if (dfOrFp instanceof FormalParameter) {
1571         return new String JavaDoc[][] {};
1572         //throw new Exception ("There is no variable "+variableId+" for the process manager "+mgrName);
1573
}
1574
1575      ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes");
1576      return SharkUtilities.getExtAttribNameValues(eas);
1577   }
1578
1579   static String JavaDoc[] getDefVariableExtendedAttributeNames (
1580      SharkTransaction t,
1581      String JavaDoc mgrName,
1582      String JavaDoc variableId) throws Exception JavaDoc {
1583
1584      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,mgrName,variableId,true);
1585      if (dfOrFp instanceof FormalParameter) {
1586         throw new Exception JavaDoc ("There is no variable "+variableId+" for the process manager "+mgrName);
1587      }
1588
1589      ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes");
1590      return SharkUtilities.getExtAttribNames(eas);
1591   }
1592
1593   static String JavaDoc getDefVariableExtendedAttributeValue (SharkTransaction t,
1594                                                       String JavaDoc mgrName,
1595                                                       String JavaDoc variableId,
1596                                                       String JavaDoc extAttrName) throws Exception JavaDoc {
1597      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,mgrName,variableId,true);
1598      if (dfOrFp instanceof FormalParameter) {
1599         throw new Exception JavaDoc ("There is no variable "+variableId+" for the process manager "+mgrName);
1600      }
1601
1602      ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes");
1603      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1604   }
1605
1606   static String JavaDoc[][] getVariableExtendedAttributeNameValuePairs (
1607      SharkTransaction t,
1608      String JavaDoc procId,
1609      String JavaDoc variableId) throws Exception JavaDoc {
1610
1611      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,procId,variableId,false);
1612      if (dfOrFp instanceof FormalParameter) {
1613         return new String JavaDoc[][] {};
1614         //throw new Exception ("There is no variable "+variableId+" in the process "+procId);
1615
}
1616
1617      ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes");
1618      return SharkUtilities.getExtAttribNameValues(eas);
1619   }
1620
1621   static String JavaDoc[] getVariableExtendedAttributeNames (
1622      SharkTransaction t,
1623      String JavaDoc procId,
1624      String JavaDoc variableId) throws Exception JavaDoc {
1625
1626      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,procId,variableId,false);
1627      if (dfOrFp instanceof FormalParameter) {
1628         throw new Exception JavaDoc ("There is no variable "+variableId+" in the process "+procId);
1629      }
1630
1631      ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes");
1632      return SharkUtilities.getExtAttribNames(eas);
1633   }
1634
1635   static String JavaDoc getVariableExtendedAttributeValue (SharkTransaction t,
1636                                                    String JavaDoc procId,
1637                                                    String JavaDoc variableId,
1638                                                    String JavaDoc extAttrName) throws Exception JavaDoc {
1639      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,procId,variableId,false);
1640      if (dfOrFp instanceof FormalParameter) {
1641         throw new Exception JavaDoc ("There is no variable "+variableId+" in the process "+procId);
1642      }
1643
1644      ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes");
1645      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1646   }
1647
1648   static String JavaDoc[][] getParticipantExtendedAttributeNameValuePairs (
1649      SharkTransaction t,
1650      String JavaDoc pkgId,
1651      String JavaDoc pDefId,
1652      String JavaDoc participantId) throws Exception JavaDoc {
1653
1654      ExtendedAttributes eas=SharkUtilities.getParticipant(t,pkgId,pDefId,participantId).getExtendedAttributes();
1655      return SharkUtilities.getExtAttribNameValues(eas);
1656   }
1657
1658   static String JavaDoc[] getParticipantExtendedAttributeNames (
1659      SharkTransaction t,
1660      String JavaDoc pkgId,
1661      String JavaDoc pDefId,
1662      String JavaDoc participantId) throws Exception JavaDoc {
1663
1664      ExtendedAttributes eas=SharkUtilities.getParticipant(t,pkgId,pDefId,participantId).getExtendedAttributes();
1665      return SharkUtilities.getExtAttribNames(eas);
1666   }
1667
1668   static String JavaDoc getParticipantExtendedAttributeValue (
1669      SharkTransaction t,
1670      String JavaDoc pkgId,
1671      String JavaDoc pDefId,
1672      String JavaDoc participantId,
1673      String JavaDoc extAttrName) throws Exception JavaDoc {
1674
1675      ExtendedAttributes eas=SharkUtilities.getParticipant(t,pkgId,pDefId,participantId).getExtendedAttributes();
1676      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1677   }
1678
1679   static String JavaDoc[][] getApplicationExtendedAttributeNameValuePairs (
1680      SharkTransaction t,
1681      String JavaDoc pkgId,
1682      String JavaDoc pDefId,
1683      String JavaDoc applicationId) throws Exception JavaDoc {
1684
1685      ExtendedAttributes eas=SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getExtendedAttributes();
1686      return SharkUtilities.getExtAttribNameValues(eas);
1687   }
1688
1689   static String JavaDoc[] getApplicationExtendedAttributeNames (
1690      SharkTransaction t,
1691      String JavaDoc pkgId,
1692      String JavaDoc pDefId,
1693      String JavaDoc applicationId) throws Exception JavaDoc {
1694
1695      ExtendedAttributes eas=SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getExtendedAttributes();
1696      return SharkUtilities.getExtAttribNames(eas);
1697   }
1698
1699   static String JavaDoc getApplicationExtendedAttributeValue (
1700      SharkTransaction t,
1701      String JavaDoc pkgId,
1702      String JavaDoc pDefId,
1703      String JavaDoc applicationId,
1704      String JavaDoc extAttrName) throws Exception JavaDoc {
1705
1706      ExtendedAttributes eas=SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getExtendedAttributes();
1707      return SharkUtilities.getExtAttribValue(eas,extAttrName);
1708   }
1709
1710   private static String JavaDoc[][] getExtAttribNameValues (ExtendedAttributes eas) {
1711      String JavaDoc[][] eaNVP=new String JavaDoc[eas.size()][2];
1712      Iterator JavaDoc it=eas.toElements().iterator();
1713      int i=0;
1714      while (it.hasNext()) {
1715         ExtendedAttribute ea=(ExtendedAttribute)it.next();
1716         eaNVP[i][0]=ea.getName();
1717         eaNVP[i][1]=ea.getVValue();
1718         i++;
1719      }
1720      return eaNVP;
1721   }
1722
1723   private static String JavaDoc[] getExtAttribNames (ExtendedAttributes eas) {
1724      String JavaDoc[] eaNs=new String JavaDoc[eas.size()];
1725      Iterator JavaDoc it=eas.toElements().iterator();
1726      int i=0;
1727      while (it.hasNext()) {
1728         ExtendedAttribute ea=(ExtendedAttribute)it.next();
1729         eaNs[i++]=ea.getName();
1730      }
1731      return eaNs;
1732   }
1733
1734   private static String JavaDoc getExtAttribValue (ExtendedAttributes eas,String JavaDoc extAttrName) throws Exception JavaDoc {
1735      ExtendedAttribute ea=eas.getFirstExtendedAttributeForName(extAttrName);
1736      if (ea==null) {
1737         throw new Exception JavaDoc("There is no ext. attr. with name "+extAttrName);
1738      } else {
1739         return ea.getVValue();
1740      }
1741   }
1742
1743   /**
1744    * Returns the XPDL name of variable.
1745    */

1746   static String JavaDoc getDefVariableName (SharkTransaction t,String JavaDoc mgrName,String JavaDoc variableId) throws Exception JavaDoc {
1747      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,mgrName,variableId,true);
1748      if (dfOrFp instanceof DataField) {
1749         return dfOrFp.get("Name").toValue();
1750      } else {
1751         return variableId;
1752      }
1753   }
1754
1755   /**
1756    * Returns the description of variable (WRD or FP) with a given name.
1757    */

1758   static String JavaDoc getDefVariableDescription (SharkTransaction t,String JavaDoc mgrName,String JavaDoc variableId) throws Exception JavaDoc {
1759      return SharkUtilities.getXPDLVariable(t,mgrName,variableId,true).get("Description").toValue();
1760   }
1761
1762   /**
1763    * Returns the Java class name of process variable.
1764    */

1765   static String JavaDoc getDefVariableJavaClassName (SharkTransaction t,String JavaDoc mgrName,String JavaDoc variableId) throws Exception JavaDoc {
1766      return SharkUtilities.getJavaClass(SharkUtilities.getXPDLVariable(t,mgrName,variableId,true)).getName();
1767   }
1768
1769   /**
1770    * Returns the XPDL name of variable.
1771    */

1772   static String JavaDoc getVariableName (SharkTransaction t,String JavaDoc procId,String JavaDoc variableId) throws Exception JavaDoc {
1773      XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,procId,variableId,false);
1774      if (dfOrFp instanceof DataField) {
1775         return dfOrFp.get("Name").toValue();
1776      } else {
1777         return variableId;
1778      }
1779   }
1780
1781   /**
1782    * Returns the description of variable (WRD or FP) with a given name.
1783    */

1784   static String JavaDoc getVariableDescription (SharkTransaction t,String JavaDoc procId,String JavaDoc variableId) throws Exception JavaDoc {
1785      return SharkUtilities.getXPDLVariable(t,procId,variableId,false).get("Description").toValue();
1786   }
1787
1788   /**
1789    * Returns the Java class name of process variable.
1790    */

1791   static String JavaDoc getVariableJavaClassName (SharkTransaction t,String JavaDoc procId,String JavaDoc variableId) throws Exception JavaDoc {
1792      return SharkUtilities.getJavaClass(SharkUtilities.getXPDLVariable(t,procId,variableId,false)).getName();
1793   }
1794
1795   private static XMLCollectionElement getXPDLVariable (SharkTransaction t,String JavaDoc procIdOrMgrName,String JavaDoc variableId,boolean isManager) throws Exception JavaDoc {
1796      WorkflowProcess wp=null;
1797      if (isManager) {
1798         WfProcessMgrInternal mgr=SharkUtilities.getProcessMgr(t,procIdOrMgrName);
1799         wp=SharkUtilities
1800            .getWorkflowProcess(mgr.package_id(t),
1801                                mgr.version(t),
1802                                mgr.process_definition_id(t));
1803      } else {
1804         WfProcessInternal proc=SharkUtilities.getProcess(t,procIdOrMgrName);
1805         wp=SharkUtilities
1806            .getWorkflowProcess(proc.package_id(t),
1807                                proc.manager_version(t),
1808                                proc.process_definition_id(t));
1809      }
1810      DataField df=wp.getDataField(variableId);
1811      if (df==null) {
1812         df=XMLUtil.getPackage(wp).getDataField(variableId);
1813      }
1814      if (df==null) {
1815         // maybe this is a formal parameter of the process
1816
FormalParameter fp=wp.getFormalParameter(variableId);
1817         if (fp==null) {
1818            String JavaDoc msg="process ";
1819            if (isManager) msg="process manager ";
1820            throw new Exception JavaDoc ("There is no variable "+variableId+" for the "+msg+procIdOrMgrName);
1821         } else {
1822            return fp;
1823         }
1824      } else {
1825         return df;
1826      }
1827   }
1828
1829   /**
1830    * Returns the XPDL name of Participant.
1831    */

1832   static String JavaDoc getParticipantName (SharkTransaction t,String JavaDoc pkgId,String JavaDoc pDefId,String JavaDoc participantId) throws Exception JavaDoc {
1833      return getParticipant(t,pkgId,pDefId,participantId).getName();
1834   }
1835
1836   static Participant getParticipant (SharkTransaction t,String JavaDoc pkgId,String JavaDoc pDefId,String JavaDoc participantId) throws Exception JavaDoc {
1837      Package JavaDoc pkg=SharkUtilities
1838         .getPackage(pkgId,
1839                     SharkUtilities.getCurrentPkgVersion(pkgId,false));
1840      Participant p=null;
1841      if (pkg==null) throw new Exception JavaDoc("There is no package with Id="+pkgId);
1842      if (pDefId==null) {
1843         p=pkg.getParticipant(participantId);
1844      } else {
1845         WorkflowProcess wp=pkg.getWorkflowProcess(pDefId);
1846         if (wp==null) throw new Exception JavaDoc("There is no process definition with Id="+pDefId);
1847         p=wp.getParticipant(participantId);
1848      }
1849      if (p==null) throw new Exception JavaDoc("There is no participant with Id="+participantId+" in pkg "+pkgId);
1850      return p;
1851   }
1852
1853   /**
1854    * Returns the XPDL name of Application.
1855    */

1856   static String JavaDoc getApplicationName (SharkTransaction t,String JavaDoc pkgId,String JavaDoc pDefId,String JavaDoc applicationId) throws Exception JavaDoc {
1857      return SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getName();
1858   }
1859
1860   static Application getApplication (SharkTransaction t,String JavaDoc pkgId,String JavaDoc pDefId,String JavaDoc applicationId) throws Exception JavaDoc {
1861      Package JavaDoc pkg=SharkUtilities
1862         .getPackage(pkgId,
1863                     SharkUtilities.getCurrentPkgVersion(pkgId,false));
1864      Application a=null;
1865      if (pkg==null) throw new Exception JavaDoc("There is no package with Id="+pkgId);
1866      if (pDefId==null) {
1867         a=pkg.getApplication(applicationId);
1868      } else {
1869         WorkflowProcess wp=pkg.getWorkflowProcess(pDefId);
1870         if (wp==null) throw new Exception JavaDoc("There is no process definition with Id="+pDefId);
1871         a=wp.getApplication(applicationId);
1872      }
1873      if (a==null) throw new Exception JavaDoc("There is no application with Id="+applicationId+" in pkg "+pkgId);
1874      return a;
1875   }
1876
1877   public static synchronized boolean synchronizeXPDLCache (RepositoryTransaction t) throws BaseException {
1878      boolean hasChanges=false;
1879      SharkEngineManager.getInstance().getCallbackUtilities().info("SharkUtilities -> synchronizing XPDL cache");
1880      //long st=System.currentTimeMillis();
1881
Map JavaDoc newCurrentVersions=new HashMap JavaDoc();
1882
1883      XMLInterface xmlInterface=SharkEngineManager.getInstance().getXMLInterface();
1884      XMLInterface xpdlHandler=new XMLInterfaceForJDK13();
1885      xpdlHandler.setValidation(false);
1886      // synchronizing XPDL handler, so all operations will be performed
1887
// on the copy of XPDL cache, and after synchronizing is finished, the changes are
1888
// applied to original.
1889
xpdlHandler.synchronizePackages(xmlInterface);
1890      RepositoryPersistenceManager repMgr=SharkEngineManager
1891         .getInstance()
1892         .getRepositoryPersistenceManager();
1893      try {
1894         // get info about engine XPDL caches
1895
long version=Version.getVersion();
1896         Set JavaDoc enginePkgIds=new HashSet JavaDoc(xpdlHandler.getAllPackageIds());
1897         Set JavaDoc enginePkgIdsWithVersionAndClassVersion=new HashSet JavaDoc();
1898         Iterator JavaDoc prep=enginePkgIds.iterator();
1899         while (prep.hasNext()) {
1900            String JavaDoc epid=(String JavaDoc)prep.next();
1901            Collection JavaDoc c=xpdlHandler.getAllPackageVersions(epid);
1902            Iterator JavaDoc prepc=c.iterator();
1903            while (prepc.hasNext()) {
1904               String JavaDoc epidWithVersion=SharkUtilities.createPkgIdWithVersionAndClassVersion(epid, (String JavaDoc)prepc.next(), version);
1905               enginePkgIdsWithVersionAndClassVersion.add(epidWithVersion);
1906            }
1907         }
1908         // get current state from repository
1909
//Map reposPkgIdsToVersionsAndClassVersions=new HashMap();
1910
Set JavaDoc reposPkgIdsWithVersionAndClassVersion=new HashSet JavaDoc();
1911         Set JavaDoc allPkgIds=new HashSet JavaDoc(repMgr.getExistingXPDLIds(t));
1912         Iterator JavaDoc it=allPkgIds.iterator();
1913         while (it.hasNext()) {
1914            String JavaDoc pkgId=(String JavaDoc)it.next();
1915            Set JavaDoc pkgVers=new HashSet JavaDoc(repMgr.getXPDLVersions(t,pkgId));
1916            Set JavaDoc pkgVersAndClassVers=new HashSet JavaDoc();
1917            Iterator JavaDoc pv=pkgVers.iterator();
1918            while (pv.hasNext()) {
1919               String JavaDoc pkgVer=(String JavaDoc)pv.next();
1920               pkgVersAndClassVers.add(createPkgVersionAndClassVersion(pkgVer, repMgr.getSerializedXPDLObjectVersion(t, pkgId, pkgVer)));
1921            }
1922            newCurrentVersions.put(pkgId,repMgr.getCurrentVersion(t,pkgId));
1923            //reposPkgIdsToVersionsAndClassVersions.put(pkgId,pkgVersAndClassVers);
1924
Iterator JavaDoc it2=pkgVersAndClassVers.iterator();
1925            while (it2.hasNext()) {
1926               String JavaDoc pkgVerAndClassVer=(String JavaDoc)it2.next();
1927               String JavaDoc pkgIdWithVersionAndClassVersion=SharkUtilities.createPkgIdWithVersionAndClassVersion(pkgId,pkgVerAndClassVer);
1928               reposPkgIdsWithVersionAndClassVersion.add(pkgIdWithVersionAndClassVersion);
1929            }
1930         }
1931
1932         //System.out.println("E="+enginePkgIdsWithVersionAndClassVersion);
1933
//System.out.println("R="+reposPkgIdsWithVersionAndClassVersion);
1934
// find packages that need to be loaded/reloaded/unloaded
1935

1936         Set JavaDoc pkgsToLoad=new HashSet JavaDoc(reposPkgIdsWithVersionAndClassVersion);
1937         pkgsToLoad.removeAll(enginePkgIdsWithVersionAndClassVersion);
1938
1939         Set JavaDoc pkgsToUnload=new HashSet JavaDoc(enginePkgIdsWithVersionAndClassVersion);
1940         pkgsToUnload.removeAll(reposPkgIdsWithVersionAndClassVersion);
1941
1942         /*Set pkgsToReload=new HashSet();
1943         it=pkgsToLoad.iterator();
1944         while (it.hasNext()) {
1945            String pkgToLoad=SharkUtilities.getPkgId((String)it.next());
1946            //Set refIds=new HashSet(repMgr.getReferringXPDLIds(t,pkgToLoad));
1947            Set refIds=SharkUtilities.getAllReferences(t,repMgr,pkgToLoad); //new HashSet(repMgr.getReferringXPDLIds(t,pkgToLoad));
1948            //System.out.println("RefIds for "+pkgToLoad+"="+refIds);
1949            Iterator it2=refIds.iterator();
1950            while (it2.hasNext()) {
1951               String refId=(String)it2.next();
1952               Set vers=(Set)reposPkgIdsToVersionsAndClassVersions.get(refId);
1953               Iterator itv=vers.iterator();
1954               while (itv.hasNext()) {
1955                  String refVer=(String)itv.next();
1956                  String pkgIdWithVer=SharkUtilities.createPkgIdWithVersionAndClassVersion(refId,refVer,repMgr.getSerializedXPDLObjectVersion(t, refId, refVer));
1957                  if (!pkgsToLoad.contains(pkgIdWithVer)) {
1958                     pkgsToReload.add(pkgIdWithVer);
1959                  }
1960               }
1961            }
1962         }*/

1963
1964
1965         /*System.out.println("EPIDWW="+enginePkgIdsWithVersion);
1966          System.out.println("PTU="+pkgsToUnload);
1967          System.out.println("PTL="+pkgsToLoad);
1968          System.out.println("PTRL="+pkgsToReload);*/

1969
1970         //pkgsToUnload.addAll(pkgsToReload);
1971
//pkgsToLoad.addAll(pkgsToReload);
1972

1973         it=pkgsToUnload.iterator();
1974         while (it.hasNext()) {
1975            String JavaDoc pkgIdWithVersionAndClassVersion=(String JavaDoc)it.next();
1976            xpdlHandler.closePackageVersion(SharkUtilities.getPkgId(pkgIdWithVersionAndClassVersion), SharkUtilities.getPkgVersion(pkgIdWithVersionAndClassVersion));
1977         }
1978         it=pkgsToLoad.iterator();
1979         while (it.hasNext()) {
1980            String JavaDoc pkgIdWithVersionAndClassVersion=(String JavaDoc)it.next();
1981            String JavaDoc pkgId=SharkUtilities.getPkgId(pkgIdWithVersionAndClassVersion);
1982            String JavaDoc pkgVer=SharkUtilities.getPkgVersion(pkgIdWithVersionAndClassVersion);
1983            //SharkEngineManager.getInstance().getCallbackUtilities().info("Restoring pkg "+pkgIdWithVersion);
1984
if (SharkUtilities.restorePackage(t,xpdlHandler,pkgId,pkgVer)==null) {
1985               throw new BaseException("Problems while restoring packages!");
1986            }
1987         }
1988
1989         if (pkgsToLoad.size()>0 || pkgsToUnload.size()>0) {
1990            hasChanges=true;
1991         }
1992         /*if (pkgsToReload.size()>0) {
1993            SharkUtilities.clearProcessCache();
1994         }*/

1995         xmlInterface.synchronizePackages(xpdlHandler);
1996         currentPkgVersions=newCurrentVersions;
1997         xpdlHandler.closeAllPackages();
1998         xpdlHandler=null;
1999         /*System.gc();
2000          ((XMLInterfaceForJDK13)xmlInterface).printDebug();
2001          */

2002         return hasChanges;
2003      } catch (Exception JavaDoc ex) {
2004         throw new BaseException(ex);
2005      }
2006   }
2007
2008   /*private static Set getAllReferences (RepositoryTransaction t,
2009                                        RepositoryPersistenceManager repMgr,
2010                                        String pkgId) throws Exception {
2011      Set refs=new HashSet();
2012
2013      Set refIds=new HashSet(repMgr.getReferringXPDLIds(t,pkgId));
2014      refs.addAll(refIds);
2015      Iterator it=refIds.iterator();
2016      while (it.hasNext()) {
2017         String refId=(String)it.next();
2018         refs.addAll(SharkUtilities.getAllReferences(t,repMgr,refId));
2019      }
2020      //System.out.println("pkgid="+pkgId+", refs="+refs);
2021      return refs;
2022   }*/

2023
2024   static void restorePackages () throws BaseException {
2025      RepositoryTransaction t=null;
2026      try {
2027         t=SharkUtilities.createRepositoryTransaction();
2028         SharkUtilities.synchronizeXPDLCache(t);
2029      } catch (Exception JavaDoc ex) {
2030         throw new BaseException(ex);
2031      } finally {
2032         SharkUtilities.releaseRepositoryTransaction(t);
2033      }
2034   }
2035
2036   static Package JavaDoc restorePackage (RepositoryTransaction t,XMLInterface xmlInterface,String JavaDoc pkgId,String JavaDoc pkgVersion) throws Exception JavaDoc {
2037      RepositoryPersistenceManager repM=SharkEngineManager
2038         .getInstance()
2039         .getRepositoryPersistenceManager();
2040      long version=Version.getVersion();
2041      long repVersion=repM.getSerializedXPDLObjectVersion(t, pkgId, pkgVersion);
2042      Package JavaDoc pkg=null;
2043      if (version==repVersion) {
2044         pkg=xmlInterface.openPackageFromStream(repM.getSerializedXPDLObject(t,pkgId,pkgVersion),false);
2045      } else {
2046         byte[] contXPDL=repM.getXPDL(t,pkgId,pkgVersion);
2047         pkg=xmlInterface.openPackageFromStream(contXPDL,true);
2048         List JavaDoc epIds=repM.getReferredXPDLIds(t, pkgId, pkgVersion);
2049         ArrayList JavaDoc eps=pkg.getExternalPackages().toElements();
2050         for (int i=0; i<eps.size(); i++) {
2051            ExternalPackage ep=(ExternalPackage)eps.get(i);
2052            pkg.addExternalPackageMapping(ep.getHref(), (String JavaDoc)epIds.get(i));
2053         }
2054         pkg.setInternalVersion(pkgVersion);
2055         pkg.setReadOnly(true);
2056         byte[] cont=XMLUtil.serialize(pkg);
2057         //System.out.println("UPDC for pjg "+pkgId+", "+pkgVersion+" to vers "+version);
2058
repM.updateXPDL(t, pkgId, pkgVersion, contXPDL, cont, version);
2059      }
2060
2061      pkg.initCaches();
2062      return pkg;
2063   }
2064
2065   static void clearProcessCache () throws RootException {
2066      CacheMgr cmgr=SharkEngineManager.getInstance().getCacheManager();
2067      if (cmgr!=null) {
2068         ProcessCache pc=cmgr.getProcessCache();
2069         int size=pc.getSize();
2070         pc.setSize(0);
2071         pc.setSize(size);
2072      }
2073   }
2074
2075   public static final String JavaDoc createProcessMgrKey (String JavaDoc pkgId,String JavaDoc pkgVer,String JavaDoc pDefId) {
2076      return (pkgId+"#"+pkgVer+"#"+pDefId);
2077   }
2078
2079   public static final String JavaDoc getProcessMgrPkgId (String JavaDoc mgrName) {
2080      String JavaDoc[] tokens=MiscUtilities.tokenize(mgrName,"#");
2081      return tokens[0];
2082   }
2083
2084   public static final String JavaDoc getProcessMgrVersion (String JavaDoc mgrName) {
2085      String JavaDoc[] tokens=MiscUtilities.tokenize(mgrName,"#");
2086      return tokens[1];
2087   }
2088
2089   public static final String JavaDoc getProcessMgrProcDefId (String JavaDoc mgrName) {
2090      String JavaDoc[] tokens=MiscUtilities.tokenize(mgrName,"#");
2091      return tokens[2];
2092   }
2093
2094   public static final String JavaDoc createAssignmentKey (String JavaDoc actId,String JavaDoc resUname) {
2095      return (actId+"#"+resUname);
2096   }
2097
2098   public static final String JavaDoc getAssignmentActivityId (String JavaDoc assId) {
2099      String JavaDoc[] tokens=MiscUtilities.tokenize(assId,"#");
2100      return tokens[0];
2101   }
2102
2103   public static final String JavaDoc getAssignmentUsername (String JavaDoc assId) {
2104      String JavaDoc[] tokens=MiscUtilities.tokenize(assId,"#");
2105      return tokens[1];
2106   }
2107
2108   private static final String JavaDoc createPkgIdWithVersionAndClassVersion (String JavaDoc pkgId,String JavaDoc pkgVersion,long pkgClassVersion) {
2109      return (pkgId+"_"+pkgVersion+"_"+pkgClassVersion);
2110   }
2111
2112   private static final String JavaDoc createPkgIdWithVersionAndClassVersion (String JavaDoc pkgId,String JavaDoc pkgVersionAndClassVersion) {
2113      return (pkgId+"_"+pkgVersionAndClassVersion);
2114   }
2115
2116   private static final String JavaDoc createPkgVersionAndClassVersion (String JavaDoc pkgVersion,long pkgClassVersion) {
2117      return (pkgVersion+"_"+pkgClassVersion);
2118   }
2119
2120   private static final String JavaDoc getPkgId (String JavaDoc pkgIdWithVersionAndClassVersion) {
2121      String JavaDoc[] tokens=MiscUtilities.tokenize(pkgIdWithVersionAndClassVersion,"_");
2122      return pkgIdWithVersionAndClassVersion
2123         .substring(0,
2124                    pkgIdWithVersionAndClassVersion.length()
2125                    -tokens[tokens.length-1].length()
2126                    -tokens[tokens.length-2].length()
2127                    -2);
2128   }
2129
2130   private static final String JavaDoc getPkgVersion (String JavaDoc pkgIdWithVersion) {
2131      String JavaDoc[] tokens=MiscUtilities.tokenize(pkgIdWithVersion,"_");
2132      return tokens[tokens.length-2];
2133   }
2134
2135   private static final String JavaDoc getPkgVersion2 (String JavaDoc versionAndClassVersion) {
2136      String JavaDoc[] tokens=MiscUtilities.tokenize(versionAndClassVersion,"_");
2137      return tokens[0];
2138   }
2139
2140   static String JavaDoc getCurrentPkgVersion (String JavaDoc pkgId,boolean fromCache) throws BaseException {
2141      String JavaDoc curVer=null;
2142      if (fromCache) {
2143         curVer=(String JavaDoc)currentPkgVersions.get(pkgId);
2144      }
2145      if (curVer!=null) {
2146         return curVer;
2147      }
2148      RepositoryTransaction rt=null;
2149      try {
2150         rt=SharkUtilities.createRepositoryTransaction();
2151         curVer=SharkEngineManager
2152            .getInstance()
2153            .getRepositoryPersistenceManager()
2154            .getCurrentVersion(rt,pkgId);
2155      } catch (Exception JavaDoc ex) {
2156         throw new BaseException(ex);
2157      } finally {
2158         SharkUtilities.releaseRepositoryTransaction(rt);
2159      }
2160
2161      return curVer;
2162   }
2163
2164
2165   static String JavaDoc getScriptType (String JavaDoc pkgId,String JavaDoc pkgVer) throws BaseException {
2166      Package JavaDoc pkg=getPackage(pkgId,pkgVer);
2167      String JavaDoc scriptType=pkg.getScript().getType();
2168      return scriptType;
2169   }
2170
2171   static String JavaDoc getNextId(String JavaDoc idName) {
2172      try {
2173         return SharkEngineManager
2174            .getInstance()
2175            .getInstancePersistenceManager()
2176            .getNextId(idName);
2177      } catch (PersistenceException pe) {
2178         throw new RootError("Fatal error: couldn't allocate an Id!",pe);
2179      }
2180   }
2181
2182   static String JavaDoc extractExceptionName (ToolAgentGeneralException tage) {
2183      String JavaDoc causeClassName="";
2184      if (tage!=null) {
2185         Throwable JavaDoc cause=tage.getCause();
2186         if (cause!=null) {
2187            causeClassName=cause.getClass().getName();
2188         }
2189      }
2190      return causeClassName;
2191   }
2192
2193   public static WorkflowProcess getWorkflowProcess (XMLElement el,String JavaDoc procDefId) throws BaseException {
2194      Package JavaDoc pkg=XMLUtil.getPackage(el);
2195      WorkflowProcess wp=pkg.getWorkflowProcess(procDefId);
2196      if (wp==null) {
2197         Iterator JavaDoc it=XMLUtil.getAllExternalPackageIds(SharkEngineManager.getInstance().getXMLInterface(), pkg).iterator();
2198         while (it.hasNext()) {
2199            String JavaDoc pkgId=(String JavaDoc)it.next();
2200            Package JavaDoc extPkg=SharkUtilities.getPackage(pkgId,null);
2201            wp=extPkg.getWorkflowProcess(procDefId);
2202            if (wp!=null) break;
2203         }
2204      }
2205      return wp;
2206   }
2207
2208   public static Application getApplication (XMLElement el,String JavaDoc appId) throws BaseException {
2209      Application app=null;
2210      WorkflowProcess wp=XMLUtil.getWorkflowProcess(el);
2211      app=wp.getApplication(appId);
2212      if (app==null) {
2213         Package JavaDoc pkg=XMLUtil.getPackage(wp);
2214         app=pkg.getApplication(appId);
2215         if (app==null) {
2216            Iterator JavaDoc it=XMLUtil.getAllExternalPackageIds(SharkEngineManager.getInstance().getXMLInterface(), pkg).iterator();
2217            while (it.hasNext()) {
2218               String JavaDoc pkgId=(String JavaDoc)it.next();
2219               Package JavaDoc extPkg=SharkUtilities.getPackage(pkgId,null);
2220               app=extPkg.getApplication(appId);
2221               if (app!=null) break;
2222            }
2223         }
2224      }
2225      return app;
2226   }
2227
2228   public static Participant getParticipant (XMLElement el,String JavaDoc partId) throws BaseException {
2229      Participant p=null;
2230      WorkflowProcess wp=XMLUtil.getWorkflowProcess(el);
2231      p=wp.getParticipant(partId);
2232      if (p==null) {
2233         Package JavaDoc pkg=XMLUtil.getPackage(wp);
2234         p=pkg.getParticipant(partId);
2235         if (p==null) {
2236            Iterator JavaDoc it=XMLUtil.getAllExternalPackageIds(SharkEngineManager.getInstance().getXMLInterface(), pkg).iterator();
2237            while (it.hasNext()) {
2238               String JavaDoc pkgId=(String JavaDoc)it.next();
2239               Package JavaDoc extPkg=SharkUtilities.getPackage(pkgId,null);
2240               p=extPkg.getParticipant(partId);
2241               if (p!=null) break;
2242            }
2243         }
2244      }
2245      return p;
2246   }
2247
2248   public static XMLCollectionElement getVariable (XMLElement el,String JavaDoc varId) throws BaseException {
2249      XMLCollectionElement dfOrFP=null;
2250      WorkflowProcess wp=XMLUtil.getWorkflowProcess(el);
2251      Map JavaDoc m=wp.getAllVariables();
2252      return (XMLCollectionElement)m.get(varId);
2253   }
2254
2255}
2256
2257class PackageFileFilter implements FileFilter JavaDoc {
2258   public boolean accept (File JavaDoc pathname) {
2259      return !pathname.isDirectory();
2260   }
2261}
2262
2263
Popular Tags