1 package org.enhydra.shark; 2 3 import java.io.File ; 4 import java.io.FileFilter ; 5 import java.text.DateFormat ; 6 import java.text.ParseException ; 7 import java.util.ArrayList ; 8 import java.util.Arrays ; 9 import java.util.Collection ; 10 import java.util.Collections ; 11 import java.util.Date ; 12 import java.util.HashMap ; 13 import java.util.HashSet ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import java.util.Map ; 17 import java.util.Set ; 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 102 public class SharkUtilities { 103 108 private static Map validActivityStates=new HashMap (); 109 static { 110 List vsList=new ArrayList (); 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 (SharkConstants.possibleActivityStates); 116 vsList.remove(SharkConstants.STATE_OPEN_RUNNING); 117 validActivityStates.put(SharkConstants.STATE_OPEN_RUNNING,vsList); 118 119 vsList=new ArrayList (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 (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 valid_activity_states (String currentState) { 131 return (List )validActivityStates.get(currentState); 132 } 133 134 135 136 private static Map validProcessStates=new HashMap (); 137 static { 138 List vsList=new ArrayList (); 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 (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 (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 (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 valid_process_states (String currentState) { 161 return (List )validProcessStates.get(currentState); 162 } 163 164 public static final String EXTERNAL_PACKAGES_REPOSITORY= 166 SharkUtilities.getRepository("EXTERNAL_PACKAGES_REPOSITORY"); 167 168 private static int nextConnectionKey=1; 170 static synchronized String getNextConnectionKey(){ 171 String ck= Integer.toString(nextConnectionKey); 172 nextConnectionKey++; 173 return ck; 174 } 175 176 private static Map loggedUsers=new SequencedHashMap(); 178 179 private static Map currentPkgVersions=new HashMap (); 180 181 private static PackageFileFilter packageFileFilter=new PackageFileFilter(); 182 183 static String connect (String userId) { 184 String connectionKey=getNextConnectionKey(); 185 loggedUsers.put(connectionKey,userId); 186 return connectionKey; 187 } 188 189 static void disconnect (String connectionKey) { 190 loggedUsers.remove(connectionKey); 191 } 192 193 static Map getLoggedUsers () throws Exception { 194 return Collections.unmodifiableMap(loggedUsers); 195 } 196 197 static List getDefinedPackageFiles (String repository,boolean traverse) { 198 File startingFolder=new File (repository); 199 List packageFiles=new ArrayList (); 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 convertToAbsolutePath (String relativePathToPackage) { 213 String absolutePath=relativePathToPackage; 214 List packageFiles=SharkUtilities.getDefinedPackageFiles(EXTERNAL_PACKAGES_REPOSITORY,true); 215 String dirName= new File (EXTERNAL_PACKAGES_REPOSITORY) 216 .getAbsolutePath(); 217 Iterator pfi=packageFiles.iterator(); 218 while (pfi.hasNext()) { 219 File f=(File )pfi.next(); 220 String 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 createAllProcessMgrWrappers (SharkTransaction t,String userAuth) throws BaseException { 234 try { 235 List mgrs=new ArrayList (); 236 List 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 ex) { 246 throw new BaseException(ex); 247 } 248 } 249 250 static List createProcessMgrsProcessWrappers (SharkTransaction t,String userAuth,String mgrName) throws BaseException { 251 try { 252 List l=SharkEngineManager.getInstance().getInstancePersistenceManager().getAllProcessesForMgr(mgrName,t); 253 List ret=new ArrayList (); 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 ex) { 260 throw new BaseException(ex); 261 } 262 } 263 264 static List createActivityPerformerWrapper (SharkTransaction t,String userAuth,String procId,String actId) throws BaseException { 265 WfActivityInternal act=SharkUtilities.getActivity(t,procId,actId); 266 String performerId=act.getPerformerId(t); 267 List ret=new ArrayList (); 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 createResourceRequesterPerformersWrapper (SharkTransaction t,String userAuth,String username) throws BaseException { 275 try { 276 PersistentManagerInterface ipi=SharkEngineManager 277 .getInstance() 278 .getInstancePersistenceManager(); 279 List l=ipi.getResourceRequestersProcessIds(username,t); 280 List ret=new ArrayList (); 281 for (int i=0; i<l.size(); i++) { 282 String pId=(String )l.get(i); 283 ProcessPersistenceInterface po=ipi.restoreProcess(pId, t); 284 ret.add(SharkEngineManager.getInstance().getObjectFactory().createProcessWrapper(userAuth,po.getId(),po.getProcessMgrName())); 288 } 289 return ret; 290 } catch (Exception ex) { 291 throw new BaseException(ex); 292 } 293 } 294 295 static List createProcessActivityWrappers (SharkTransaction t,String userAuth,String procId) throws BaseException { 296 try { 297 WfProcessInternal proc=SharkUtilities.getProcess(t,procId); 298 List l=proc.getAllActivities(t); 299 List ret=new ArrayList (); 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 return ret; 306 } catch (Exception ex) { 307 throw new BaseException(ex); 308 } 309 } 310 311 static List createAssignmentWrappers (SharkTransaction t,String userAuth,String procId,String actId) throws BaseException { 312 try { 313 List objs=SharkEngineManager 314 .getInstance() 315 .getInstancePersistenceManager() 316 .getAllValidAssignmentsForActivity(actId,t); 317 318 List pobjs=new ArrayList (); 319 for (Iterator 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 ex) { 325 throw new BaseException(ex); 326 } 327 } 328 329 static List createAssignmentWrappers (SharkTransaction t,String userAuth,String username) throws BaseException { 330 try { 331 List objs=SharkUtilities.getResource(t,username).getAssignments(t); 332 List pobjs=new ArrayList (); 333 for (Iterator 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 ex) { 339 throw new BaseException(ex); 340 } 341 } 342 343 static List createAllResourceWrappers (SharkTransaction t,String userAuth) throws BaseException { 344 try { 345 List resources=new ArrayList (); 346 List 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 ex) { 353 throw new BaseException(ex); 354 } 355 } 356 357 static List createProcessHistoryEvents (SharkTransaction t,String userAuth,String procId) throws BaseException { 358 List history=new ArrayList (); 359 try { 360 EventAuditManagerInterface eam = SharkEngineManager 361 .getInstance() 362 .getEventAuditManager(); 363 if (null == eam) 364 return history; 365 List 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 ex) { 389 throw new BaseException(ex); 390 } 391 return history; 392 } 393 394 static List createActivityHistoryEvents (SharkTransaction t,String userAuth,String procId,String actId) throws BaseException { 395 List history=new ArrayList (); 396 try { 397 EventAuditManagerInterface eam = SharkEngineManager 398 .getInstance() 399 .getEventAuditManager(); 400 if (null == eam) 401 return history; 402 List 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 ex) { 418 throw new BaseException(ex); 419 } 420 } 421 422 static void reevaluateAssignments (SharkTransaction t) throws BaseException { 423 try { 424 List mgrs=new ArrayList (); 425 List 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 ex) { 434 throw new BaseException(ex); 435 } 436 } 437 438 static void reevalAssignments (SharkTransaction t,String mgrName) throws BaseException { 439 try { 440 List l=SharkEngineManager.getInstance().getInstancePersistenceManager().getAllProcessesForMgr(mgrName,t); 441 List ret=new ArrayList (); 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 acts=proc.getActiveActivities(t); 446 Iterator itActs=acts.iterator(); 447 while (itActs.hasNext()) { 448 WfActivityInternal aint=(WfActivityInternal)itActs.next(); 449 aint.reevaluateAssignments(t); 450 } 451 } 452 } catch (Exception ex) { 453 throw new BaseException(ex); 454 } 455 } 456 457 static boolean lock(SharkTransaction t, String 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 } 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 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 } catch (TransactionException oops) { 724 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 processLocks = lm.getLocks(t); 743 for (Iterator it = processLocks.iterator(); it.hasNext();) { 744 String pLock = (String )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 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 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 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 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 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 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 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 ex) { 871 throw new BaseException(ex); 872 } 873 } 874 875 static WfProcessMgrInternal getProcessMgr (SharkTransaction t, String 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 ex) { 889 throw new BaseException(ex); 890 } 891 } 892 893 static WfActivityInternal getActivity (SharkTransaction t,String procId,String actId) throws BaseException{ 894 try { 895 WfProcessInternal proc=getProcess(t,procId); 897 WfActivityInternal act=proc.getActivity(t,actId); 898 return act; 899 } catch (Exception ex) { 900 throw new BaseException(ex); 901 } 902 } 903 904 static WfAssignmentInternal getAssignment (SharkTransaction t, String procId,String actId,String 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 ex) { 910 throw new BaseException(ex); 911 } 912 } 913 914 static WfAssignment getAssignmentWrapper (SharkTransaction t, String userAuth, String procId,String assId) throws BaseException { 915 try { 916 String [] tokens=MiscUtilities.tokenize(assId,"#"); 917 String actId=tokens[0]; 918 String uname=tokens[1]; 919 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 ex) { 934 throw new BaseException ("Invalid process or assignment Id",ex); 935 } 936 } 937 938 939 static List getAssignments (SharkTransaction t, 940 String engineName, 941 String procId, 942 String actId, 943 List userIds, 944 List responsibleIds, 945 String processRequesterId, 946 PerformerData xpdlParticipant, 947 List 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 if (userIds!=null && userIds.size()>0) return userIds; 963 if (responsibleIds!=null && responsibleIds.size()>0) return responsibleIds; 964 List ret=new ArrayList (); 966 ret.add(processRequesterId); 967 return ret; 968 } 969 970 static List getSecureAssignments( 971 SharkTransaction t, 972 String engineName, 973 String procId, 974 String actId, 975 List userIds) throws RootException { 976 977 SecurityManager 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 username,String 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 return ret; 995 } 996 catch (RootException e) { 997 throw e; 999 } finally { 1000 SharkUtilities.releaseUserTransaction(ut); 1001 } 1002 } 1003 1004 1007 static boolean checkDataType (SharkTransaction t,WorkflowProcess wp,String nm,Object oldVal,Object 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 cls=SharkUtilities.getJavaClass(dfOrFp); 1020 if (cls.isInstance(val)) { 1021 return true; 1022 } 1023 } 1024 } 1025 return false; 1026 } 1027 1028 static Object getInitialValue(XMLCollectionElement dfOrFp,boolean forceDefaultValueForType) { 1029 String 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 return createInitialValue(initialValStr,dfOrFp); 1043 } 1044 1045 static Class getJavaClass (XMLCollectionElement dfOrFp) { 1046 String jt=((DataType)dfOrFp.get("DataType")).getJavaType(); 1047 Class cls=java.lang.Object .class; 1049 try { 1050 cls=Class.forName(jt); 1051 } catch (Exception ex) {} 1052 return cls; 1053 } 1054 1055 private static Object createInitialValue (String initialValStr, 1056 XMLCollectionElement dfOrFp) { 1057 String javaType=((DataType)dfOrFp.get("DataType")).getJavaType(); 1058 1060 Object any=null; 1062 if (javaType.equals("java.lang.Boolean")) { 1063 Boolean value=new Boolean (false); 1064 try { 1065 if (initialValStr.equalsIgnoreCase("true") || initialValStr.equals("1")) { 1066 value=new Boolean (true); 1067 } else if (initialValStr.equalsIgnoreCase("false") || initialValStr.equals("0")) { 1068 value=new Boolean (false); 1069 } 1070 } catch (Exception 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 value; 1076 try { 1077 value=new Long (initialValStr); 1078 } catch (NumberFormatException nfe) { 1079 try { 1080 Double d=new Double (initialValStr); 1081 value=new Long (d.longValue()); 1082 } catch (Exception ex) { 1083 value=new Long (0); 1084 } 1085 } 1086 any=value; 1087 } else if (javaType.equals("java.lang.Double")) { 1088 Double value; 1089 try { 1090 value=new Double (initialValStr); 1091 } catch (NumberFormatException nfe) { 1092 value=new Double (0); 1093 } 1094 any=value; 1095 } else if (javaType.equals("java.util.Date")) { 1096 Date value; 1097 try { 1098 value=DateFormat.getDateInstance().parse(initialValStr); 1099 } catch (ParseException pe) { 1100 try { 1101 value=new Date (Long.parseLong(initialValStr)); 1102 } catch (Exception ex) { 1103 value=new Date (); 1104 } 1105 } 1106 any=value; 1107 1108 } else { 1109 try { 1110 1114 Class cls=Class.forName(javaType); 1115 if (!cls.isInterface()) { 1116 any=cls.newInstance(); 1117 } 1118 } catch (Throwable ex) { 1121 SharkEngineManager.getInstance().getCallbackUtilities().warn("The instantiation of object for class "+javaType+" failed"); 1122 } 1124 } 1125 return any; 1127 } 1128 1129 1137 static String getRepository (String rep) { 1138 String rdPath=SharkEngineManager 1139 .getInstance() 1140 .getCallbackUtilities() 1141 .getProperty(SharkConstants.ROOT_DIRECTORY_PATH_PROP); 1142 CallbackUtilities cus=SharkEngineManager.getInstance().getCallbackUtilities(); 1144 String path=cus.getProperty(rep); 1145 1146 if (path!=null) { 1147 File f=new File (path); 1149 1150 if (!f.isAbsolute()) { 1151 f=new File (XMLUtil.createPath(rdPath,path)); 1152 } 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 er=f.getCanonicalPath(); 1165 cus.info("The repository "+rep+" is at "+er); 1166 return er; 1167 } catch (Exception ex) { 1168 String 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 getPackage (String pkgId,String pkgVer) throws BaseException { 1179 XMLInterface xmlInterface=SharkEngineManager.getInstance().getXMLInterface(); 1180 Package 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 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 pkgId,String pkgVer,String wpId) throws BaseException { 1215 try { 1216 return getPackage(pkgId,pkgVer).getWorkflowProcess(wpId); 1217 } catch (Exception ex) { 1218 return null; 1219 } 1220 } 1221 1222 static Activity getActivityDefinition (String pkgId, 1223 String pkgVer, 1224 String wpId, 1225 String aSetId, 1226 String 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 1243 static Activity getActivityDefinition (SharkTransaction t,WfActivityInternal act,WorkflowProcess wp,WfActivityInternal parentAct) throws BaseException { 1244 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 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 createContextMap (SharkTransaction t, 1263 WfActivityInternal act, 1264 ActualParameters actualParameters, 1265 FormalParameters formalParameters) throws Exception { 1266 String packageId = act.container(t).package_id(t); 1267 String 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 createContextMap (SharkTransaction t, 1278 Map context, 1279 ActualParameters actualParameters, 1280 FormalParameters formalParameters, 1281 String packageId, 1282 String packageVer) throws Exception { 1283 Evaluator evaluator=SharkEngineManager 1284 .getInstance() 1285 .getScriptingManager() 1286 .getEvaluator(t, 1287 SharkUtilities.getScriptType(packageId,packageVer)); 1288 Map m=new HashMap (); 1289 Iterator fps=formalParameters.toElements().iterator(); 1297 Iterator aps=actualParameters.toElements().iterator(); 1299 while(aps.hasNext() && fps.hasNext()){ 1300 ActualParameter ap=(ActualParameter)aps.next(); 1301 FormalParameter fp=(FormalParameter)fps.next(); 1302 String fpMode=fp.getMode(); 1303 Object val=null; 1304 String 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 1333 } else if (!fpMode.equals(XPDLConstants.FORMAL_PARAMETER_MODE_OUT)) { 1335 if (!context.containsKey(apVal)) { 1336 throw new Exception ("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 createContextMap (SharkTransaction t, 1348 Map context, 1349 ActualParameters actualParameters, 1350 String packageId, 1351 String packageVer) throws Exception { 1352 Evaluator evaluator=SharkEngineManager 1353 .getInstance() 1354 .getScriptingManager() 1355 .getEvaluator(t, 1356 SharkUtilities.getScriptType(packageId,packageVer)); 1357 Map m=new HashMap (); 1358 Iterator aps=actualParameters.toElements().iterator(); 1360 int i=0; 1361 while(aps.hasNext()){ 1362 ActualParameter ap=(ActualParameter)aps.next(); 1363 Object val=null; 1364 String 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 [][] getPackageExtendedAttributeNameValuePairs ( 1392 SharkTransaction t, 1393 String pkgId) throws Exception { 1394 1395 String curVer=SharkUtilities.getCurrentPkgVersion(pkgId,false); 1396 Package pkg=SharkUtilities.getPackage(pkgId,curVer); 1397 ExtendedAttributes eas=pkg.getExtendedAttributes(); 1398 return SharkUtilities.getExtAttribNameValues(eas); 1399 } 1400 1401 static String [] getPackageExtendedAttributeNames ( 1402 SharkTransaction t, 1403 String pkgId) throws Exception { 1404 1405 String curVer=SharkUtilities.getCurrentPkgVersion(pkgId,false); 1406 Package pkg=SharkUtilities.getPackage(pkgId,curVer); 1407 ExtendedAttributes eas=pkg.getExtendedAttributes(); 1408 return SharkUtilities.getExtAttribNames(eas); 1409 } 1410 1411 static String getPackageExtendedAttributeValue (SharkTransaction t, 1412 String pkgId, 1413 String extAttrName) throws Exception { 1414 String curVer=SharkUtilities.getCurrentPkgVersion(pkgId,false); 1415 Package pkg=SharkUtilities.getPackage(pkgId,curVer); 1416 ExtendedAttributes eas=pkg.getExtendedAttributes(); 1417 return SharkUtilities.getExtAttribValue(eas,extAttrName); 1418 } 1419 1420 static String [][] getProcessDefinitionExtendedAttributeNameValuePairs ( 1421 SharkTransaction t, 1422 String mgrName) throws Exception { 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 [] getProcessDefinitionExtendedAttributeNames ( 1434 SharkTransaction t, 1435 String mgrName) throws Exception { 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 getProcessDefinitionExtendedAttributeValue (SharkTransaction t, 1447 String mgrName, 1448 String extAttrName) throws Exception { 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 [][] getProcessExtendedAttributeNameValuePairs ( 1459 SharkTransaction t, 1460 String procId) throws Exception { 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 [] getProcessExtendedAttributeNames ( 1472 SharkTransaction t, 1473 String procId) throws Exception { 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 getProcessExtendedAttributeValue (SharkTransaction t, 1485 String procId, 1486 String extAttrName) throws Exception { 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 getActivitiesExtendedAttributes (SharkTransaction t, 1497 String procId, 1498 String actId) throws Exception { 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 [][] getActivitiesExtendedAttributeNameValuePairs ( 1512 SharkTransaction t, 1513 String procId, 1514 String actId) throws Exception { 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 [] getActivitiesExtendedAttributeNames ( 1530 SharkTransaction t, 1531 String procId, 1532 String actId) throws Exception { 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 getActivitiesExtendedAttributeValue (SharkTransaction t, 1548 String procId, 1549 String actId, 1550 String extAttrName) throws Exception { 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 [][] getDefVariableExtendedAttributeNameValuePairs ( 1565 SharkTransaction t, 1566 String mgrName, 1567 String variableId) throws Exception { 1568 1569 XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,mgrName,variableId,true); 1570 if (dfOrFp instanceof FormalParameter) { 1571 return new String [][] {}; 1572 } 1574 1575 ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes"); 1576 return SharkUtilities.getExtAttribNameValues(eas); 1577 } 1578 1579 static String [] getDefVariableExtendedAttributeNames ( 1580 SharkTransaction t, 1581 String mgrName, 1582 String variableId) throws Exception { 1583 1584 XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,mgrName,variableId,true); 1585 if (dfOrFp instanceof FormalParameter) { 1586 throw new Exception ("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 getDefVariableExtendedAttributeValue (SharkTransaction t, 1594 String mgrName, 1595 String variableId, 1596 String extAttrName) throws Exception { 1597 XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,mgrName,variableId,true); 1598 if (dfOrFp instanceof FormalParameter) { 1599 throw new Exception ("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 [][] getVariableExtendedAttributeNameValuePairs ( 1607 SharkTransaction t, 1608 String procId, 1609 String variableId) throws Exception { 1610 1611 XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,procId,variableId,false); 1612 if (dfOrFp instanceof FormalParameter) { 1613 return new String [][] {}; 1614 } 1616 1617 ExtendedAttributes eas=(ExtendedAttributes)dfOrFp.get("ExtendedAttributes"); 1618 return SharkUtilities.getExtAttribNameValues(eas); 1619 } 1620 1621 static String [] getVariableExtendedAttributeNames ( 1622 SharkTransaction t, 1623 String procId, 1624 String variableId) throws Exception { 1625 1626 XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,procId,variableId,false); 1627 if (dfOrFp instanceof FormalParameter) { 1628 throw new Exception ("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 getVariableExtendedAttributeValue (SharkTransaction t, 1636 String procId, 1637 String variableId, 1638 String extAttrName) throws Exception { 1639 XMLCollectionElement dfOrFp=SharkUtilities.getXPDLVariable(t,procId,variableId,false); 1640 if (dfOrFp instanceof FormalParameter) { 1641 throw new Exception ("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 [][] getParticipantExtendedAttributeNameValuePairs ( 1649 SharkTransaction t, 1650 String pkgId, 1651 String pDefId, 1652 String participantId) throws Exception { 1653 1654 ExtendedAttributes eas=SharkUtilities.getParticipant(t,pkgId,pDefId,participantId).getExtendedAttributes(); 1655 return SharkUtilities.getExtAttribNameValues(eas); 1656 } 1657 1658 static String [] getParticipantExtendedAttributeNames ( 1659 SharkTransaction t, 1660 String pkgId, 1661 String pDefId, 1662 String participantId) throws Exception { 1663 1664 ExtendedAttributes eas=SharkUtilities.getParticipant(t,pkgId,pDefId,participantId).getExtendedAttributes(); 1665 return SharkUtilities.getExtAttribNames(eas); 1666 } 1667 1668 static String getParticipantExtendedAttributeValue ( 1669 SharkTransaction t, 1670 String pkgId, 1671 String pDefId, 1672 String participantId, 1673 String extAttrName) throws Exception { 1674 1675 ExtendedAttributes eas=SharkUtilities.getParticipant(t,pkgId,pDefId,participantId).getExtendedAttributes(); 1676 return SharkUtilities.getExtAttribValue(eas,extAttrName); 1677 } 1678 1679 static String [][] getApplicationExtendedAttributeNameValuePairs ( 1680 SharkTransaction t, 1681 String pkgId, 1682 String pDefId, 1683 String applicationId) throws Exception { 1684 1685 ExtendedAttributes eas=SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getExtendedAttributes(); 1686 return SharkUtilities.getExtAttribNameValues(eas); 1687 } 1688 1689 static String [] getApplicationExtendedAttributeNames ( 1690 SharkTransaction t, 1691 String pkgId, 1692 String pDefId, 1693 String applicationId) throws Exception { 1694 1695 ExtendedAttributes eas=SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getExtendedAttributes(); 1696 return SharkUtilities.getExtAttribNames(eas); 1697 } 1698 1699 static String getApplicationExtendedAttributeValue ( 1700 SharkTransaction t, 1701 String pkgId, 1702 String pDefId, 1703 String applicationId, 1704 String extAttrName) throws Exception { 1705 1706 ExtendedAttributes eas=SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getExtendedAttributes(); 1707 return SharkUtilities.getExtAttribValue(eas,extAttrName); 1708 } 1709 1710 private static String [][] getExtAttribNameValues (ExtendedAttributes eas) { 1711 String [][] eaNVP=new String [eas.size()][2]; 1712 Iterator 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 [] getExtAttribNames (ExtendedAttributes eas) { 1724 String [] eaNs=new String [eas.size()]; 1725 Iterator 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 getExtAttribValue (ExtendedAttributes eas,String extAttrName) throws Exception { 1735 ExtendedAttribute ea=eas.getFirstExtendedAttributeForName(extAttrName); 1736 if (ea==null) { 1737 throw new Exception ("There is no ext. attr. with name "+extAttrName); 1738 } else { 1739 return ea.getVValue(); 1740 } 1741 } 1742 1743 1746 static String getDefVariableName (SharkTransaction t,String mgrName,String variableId) throws Exception { 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 1758 static String getDefVariableDescription (SharkTransaction t,String mgrName,String variableId) throws Exception { 1759 return SharkUtilities.getXPDLVariable(t,mgrName,variableId,true).get("Description").toValue(); 1760 } 1761 1762 1765 static String getDefVariableJavaClassName (SharkTransaction t,String mgrName,String variableId) throws Exception { 1766 return SharkUtilities.getJavaClass(SharkUtilities.getXPDLVariable(t,mgrName,variableId,true)).getName(); 1767 } 1768 1769 1772 static String getVariableName (SharkTransaction t,String procId,String variableId) throws Exception { 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 1784 static String getVariableDescription (SharkTransaction t,String procId,String variableId) throws Exception { 1785 return SharkUtilities.getXPDLVariable(t,procId,variableId,false).get("Description").toValue(); 1786 } 1787 1788 1791 static String getVariableJavaClassName (SharkTransaction t,String procId,String variableId) throws Exception { 1792 return SharkUtilities.getJavaClass(SharkUtilities.getXPDLVariable(t,procId,variableId,false)).getName(); 1793 } 1794 1795 private static XMLCollectionElement getXPDLVariable (SharkTransaction t,String procIdOrMgrName,String variableId,boolean isManager) throws Exception { 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 FormalParameter fp=wp.getFormalParameter(variableId); 1817 if (fp==null) { 1818 String msg="process "; 1819 if (isManager) msg="process manager "; 1820 throw new Exception ("There is no variable "+variableId+" for the "+msg+procIdOrMgrName); 1821 } else { 1822 return fp; 1823 } 1824 } else { 1825 return df; 1826 } 1827 } 1828 1829 1832 static String getParticipantName (SharkTransaction t,String pkgId,String pDefId,String participantId) throws Exception { 1833 return getParticipant(t,pkgId,pDefId,participantId).getName(); 1834 } 1835 1836 static Participant getParticipant (SharkTransaction t,String pkgId,String pDefId,String participantId) throws Exception { 1837 Package pkg=SharkUtilities 1838 .getPackage(pkgId, 1839 SharkUtilities.getCurrentPkgVersion(pkgId,false)); 1840 Participant p=null; 1841 if (pkg==null) throw new Exception ("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 ("There is no process definition with Id="+pDefId); 1847 p=wp.getParticipant(participantId); 1848 } 1849 if (p==null) throw new Exception ("There is no participant with Id="+participantId+" in pkg "+pkgId); 1850 return p; 1851 } 1852 1853 1856 static String getApplicationName (SharkTransaction t,String pkgId,String pDefId,String applicationId) throws Exception { 1857 return SharkUtilities.getApplication(t,pkgId,pDefId,applicationId).getName(); 1858 } 1859 1860 static Application getApplication (SharkTransaction t,String pkgId,String pDefId,String applicationId) throws Exception { 1861 Package pkg=SharkUtilities 1862 .getPackage(pkgId, 1863 SharkUtilities.getCurrentPkgVersion(pkgId,false)); 1864 Application a=null; 1865 if (pkg==null) throw new Exception ("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 ("There is no process definition with Id="+pDefId); 1871 a=wp.getApplication(applicationId); 1872 } 1873 if (a==null) throw new Exception ("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 Map newCurrentVersions=new HashMap (); 1882 1883 XMLInterface xmlInterface=SharkEngineManager.getInstance().getXMLInterface(); 1884 XMLInterface xpdlHandler=new XMLInterfaceForJDK13(); 1885 xpdlHandler.setValidation(false); 1886 xpdlHandler.synchronizePackages(xmlInterface); 1890 RepositoryPersistenceManager repMgr=SharkEngineManager 1891 .getInstance() 1892 .getRepositoryPersistenceManager(); 1893 try { 1894 long version=Version.getVersion(); 1896 Set enginePkgIds=new HashSet (xpdlHandler.getAllPackageIds()); 1897 Set enginePkgIdsWithVersionAndClassVersion=new HashSet (); 1898 Iterator prep=enginePkgIds.iterator(); 1899 while (prep.hasNext()) { 1900 String epid=(String )prep.next(); 1901 Collection c=xpdlHandler.getAllPackageVersions(epid); 1902 Iterator prepc=c.iterator(); 1903 while (prepc.hasNext()) { 1904 String epidWithVersion=SharkUtilities.createPkgIdWithVersionAndClassVersion(epid, (String )prepc.next(), version); 1905 enginePkgIdsWithVersionAndClassVersion.add(epidWithVersion); 1906 } 1907 } 1908 Set reposPkgIdsWithVersionAndClassVersion=new HashSet (); 1911 Set allPkgIds=new HashSet (repMgr.getExistingXPDLIds(t)); 1912 Iterator it=allPkgIds.iterator(); 1913 while (it.hasNext()) { 1914 String pkgId=(String )it.next(); 1915 Set pkgVers=new HashSet (repMgr.getXPDLVersions(t,pkgId)); 1916 Set pkgVersAndClassVers=new HashSet (); 1917 Iterator pv=pkgVers.iterator(); 1918 while (pv.hasNext()) { 1919 String pkgVer=(String )pv.next(); 1920 pkgVersAndClassVers.add(createPkgVersionAndClassVersion(pkgVer, repMgr.getSerializedXPDLObjectVersion(t, pkgId, pkgVer))); 1921 } 1922 newCurrentVersions.put(pkgId,repMgr.getCurrentVersion(t,pkgId)); 1923 Iterator it2=pkgVersAndClassVers.iterator(); 1925 while (it2.hasNext()) { 1926 String pkgVerAndClassVer=(String )it2.next(); 1927 String pkgIdWithVersionAndClassVersion=SharkUtilities.createPkgIdWithVersionAndClassVersion(pkgId,pkgVerAndClassVer); 1928 reposPkgIdsWithVersionAndClassVersion.add(pkgIdWithVersionAndClassVersion); 1929 } 1930 } 1931 1932 1936 Set pkgsToLoad=new HashSet (reposPkgIdsWithVersionAndClassVersion); 1937 pkgsToLoad.removeAll(enginePkgIdsWithVersionAndClassVersion); 1938 1939 Set pkgsToUnload=new HashSet (enginePkgIdsWithVersionAndClassVersion); 1940 pkgsToUnload.removeAll(reposPkgIdsWithVersionAndClassVersion); 1941 1942 1963 1964 1965 1969 1970 1973 it=pkgsToUnload.iterator(); 1974 while (it.hasNext()) { 1975 String pkgIdWithVersionAndClassVersion=(String )it.next(); 1976 xpdlHandler.closePackageVersion(SharkUtilities.getPkgId(pkgIdWithVersionAndClassVersion), SharkUtilities.getPkgVersion(pkgIdWithVersionAndClassVersion)); 1977 } 1978 it=pkgsToLoad.iterator(); 1979 while (it.hasNext()) { 1980 String pkgIdWithVersionAndClassVersion=(String )it.next(); 1981 String pkgId=SharkUtilities.getPkgId(pkgIdWithVersionAndClassVersion); 1982 String pkgVer=SharkUtilities.getPkgVersion(pkgIdWithVersionAndClassVersion); 1983 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 1995 xmlInterface.synchronizePackages(xpdlHandler); 1996 currentPkgVersions=newCurrentVersions; 1997 xpdlHandler.closeAllPackages(); 1998 xpdlHandler=null; 1999 2002 return hasChanges; 2003 } catch (Exception ex) { 2004 throw new BaseException(ex); 2005 } 2006 } 2007 2008 2023 2024 static void restorePackages () throws BaseException { 2025 RepositoryTransaction t=null; 2026 try { 2027 t=SharkUtilities.createRepositoryTransaction(); 2028 SharkUtilities.synchronizeXPDLCache(t); 2029 } catch (Exception ex) { 2030 throw new BaseException(ex); 2031 } finally { 2032 SharkUtilities.releaseRepositoryTransaction(t); 2033 } 2034 } 2035 2036 static Package restorePackage (RepositoryTransaction t,XMLInterface xmlInterface,String pkgId,String pkgVersion) throws Exception { 2037 RepositoryPersistenceManager repM=SharkEngineManager 2038 .getInstance() 2039 .getRepositoryPersistenceManager(); 2040 long version=Version.getVersion(); 2041 long repVersion=repM.getSerializedXPDLObjectVersion(t, pkgId, pkgVersion); 2042 Package 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 epIds=repM.getReferredXPDLIds(t, pkgId, pkgVersion); 2049 ArrayList 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 )epIds.get(i)); 2053 } 2054 pkg.setInternalVersion(pkgVersion); 2055 pkg.setReadOnly(true); 2056 byte[] cont=XMLUtil.serialize(pkg); 2057 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 createProcessMgrKey (String pkgId,String pkgVer,String pDefId) { 2076 return (pkgId+"#"+pkgVer+"#"+pDefId); 2077 } 2078 2079 public static final String getProcessMgrPkgId (String mgrName) { 2080 String [] tokens=MiscUtilities.tokenize(mgrName,"#"); 2081 return tokens[0]; 2082 } 2083 2084 public static final String getProcessMgrVersion (String mgrName) { 2085 String [] tokens=MiscUtilities.tokenize(mgrName,"#"); 2086 return tokens[1]; 2087 } 2088 2089 public static final String getProcessMgrProcDefId (String mgrName) { 2090 String [] tokens=MiscUtilities.tokenize(mgrName,"#"); 2091 return tokens[2]; 2092 } 2093 2094 public static final String createAssignmentKey (String actId,String resUname) { 2095 return (actId+"#"+resUname); 2096 } 2097 2098 public static final String getAssignmentActivityId (String assId) { 2099 String [] tokens=MiscUtilities.tokenize(assId,"#"); 2100 return tokens[0]; 2101 } 2102 2103 public static final String getAssignmentUsername (String assId) { 2104 String [] tokens=MiscUtilities.tokenize(assId,"#"); 2105 return tokens[1]; 2106 } 2107 2108 private static final String createPkgIdWithVersionAndClassVersion (String pkgId,String pkgVersion,long pkgClassVersion) { 2109 return (pkgId+"_"+pkgVersion+"_"+pkgClassVersion); 2110 } 2111 2112 private static final String createPkgIdWithVersionAndClassVersion (String pkgId,String pkgVersionAndClassVersion) { 2113 return (pkgId+"_"+pkgVersionAndClassVersion); 2114 } 2115 2116 private static final String createPkgVersionAndClassVersion (String pkgVersion,long pkgClassVersion) { 2117 return (pkgVersion+"_"+pkgClassVersion); 2118 } 2119 2120 private static final String getPkgId (String pkgIdWithVersionAndClassVersion) { 2121 String [] 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 getPkgVersion (String pkgIdWithVersion) { 2131 String [] tokens=MiscUtilities.tokenize(pkgIdWithVersion,"_"); 2132 return tokens[tokens.length-2]; 2133 } 2134 2135 private static final String getPkgVersion2 (String versionAndClassVersion) { 2136 String [] tokens=MiscUtilities.tokenize(versionAndClassVersion,"_"); 2137 return tokens[0]; 2138 } 2139 2140 static String getCurrentPkgVersion (String pkgId,boolean fromCache) throws BaseException { 2141 String curVer=null; 2142 if (fromCache) { 2143 curVer=(String )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 ex) { 2156 throw new BaseException(ex); 2157 } finally { 2158 SharkUtilities.releaseRepositoryTransaction(rt); 2159 } 2160 2161 return curVer; 2162 } 2163 2164 2165 static String getScriptType (String pkgId,String pkgVer) throws BaseException { 2166 Package pkg=getPackage(pkgId,pkgVer); 2167 String scriptType=pkg.getScript().getType(); 2168 return scriptType; 2169 } 2170 2171 static String getNextId(String 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 extractExceptionName (ToolAgentGeneralException tage) { 2183 String causeClassName=""; 2184 if (tage!=null) { 2185 Throwable 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 procDefId) throws BaseException { 2194 Package pkg=XMLUtil.getPackage(el); 2195 WorkflowProcess wp=pkg.getWorkflowProcess(procDefId); 2196 if (wp==null) { 2197 Iterator it=XMLUtil.getAllExternalPackageIds(SharkEngineManager.getInstance().getXMLInterface(), pkg).iterator(); 2198 while (it.hasNext()) { 2199 String pkgId=(String )it.next(); 2200 Package 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 appId) throws BaseException { 2209 Application app=null; 2210 WorkflowProcess wp=XMLUtil.getWorkflowProcess(el); 2211 app=wp.getApplication(appId); 2212 if (app==null) { 2213 Package pkg=XMLUtil.getPackage(wp); 2214 app=pkg.getApplication(appId); 2215 if (app==null) { 2216 Iterator it=XMLUtil.getAllExternalPackageIds(SharkEngineManager.getInstance().getXMLInterface(), pkg).iterator(); 2217 while (it.hasNext()) { 2218 String pkgId=(String )it.next(); 2219 Package 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 partId) throws BaseException { 2229 Participant p=null; 2230 WorkflowProcess wp=XMLUtil.getWorkflowProcess(el); 2231 p=wp.getParticipant(partId); 2232 if (p==null) { 2233 Package pkg=XMLUtil.getPackage(wp); 2234 p=pkg.getParticipant(partId); 2235 if (p==null) { 2236 Iterator it=XMLUtil.getAllExternalPackageIds(SharkEngineManager.getInstance().getXMLInterface(), pkg).iterator(); 2237 while (it.hasNext()) { 2238 String pkgId=(String )it.next(); 2239 Package 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 varId) throws BaseException { 2249 XMLCollectionElement dfOrFP=null; 2250 WorkflowProcess wp=XMLUtil.getWorkflowProcess(el); 2251 Map m=wp.getAllVariables(); 2252 return (XMLCollectionElement)m.get(varId); 2253 } 2254 2255} 2256 2257class PackageFileFilter implements FileFilter { 2258 public boolean accept (File pathname) { 2259 return !pathname.isDirectory(); 2260 } 2261} 2262 2263 | Popular Tags |