1 package org.enhydra.shark; 2 3 import org.enhydra.shark.api.client.wfmodel.*; 4 5 import java.util.List ; 6 import java.util.Map ; 7 import org.enhydra.shark.api.RootException; 8 import org.enhydra.shark.api.SharkTransaction; 9 import org.enhydra.shark.api.client.wfbase.BaseException; 10 import org.enhydra.shark.api.internal.security.SecurityManager; 11 import org.enhydra.shark.api.internal.working.WfProcessInternal; 12 import org.enhydra.shark.api.internal.working.WfProcessMgrInternal; 13 import org.enhydra.shark.api.internal.working.WfRequesterInternal; 14 import org.enhydra.shark.xpdl.XPDLConstants; 15 import org.enhydra.shark.xpdl.elements.WorkflowProcess; 16 17 22 public class WfProcessMgrWrapper implements WfProcessMgr { 23 24 private String userAuth; 25 private String name; 26 30 protected WfProcessMgrWrapper(String userAuth,String name) throws BaseException { 31 this.userAuth=userAuth; 32 this.name=name; 33 } 34 35 public int how_many_process () throws BaseException { 36 int ret=-1; 37 SharkTransaction t = null; 38 try { 39 t = SharkUtilities.createTransaction(); 40 ret = how_many_process(t); 41 } catch (RootException e) { 43 SharkUtilities.emptyCaches(t); 45 if (e instanceof BaseException) 46 throw (BaseException)e; 47 else 48 throw new BaseException(e); 49 } finally { 50 SharkUtilities.releaseTransaction(t); 51 } 52 return ret; 53 } 54 55 public int how_many_process (SharkTransaction t) throws BaseException { 56 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 57 if (sm!=null) { 58 try { 59 sm.check_processmgr_how_many_process(t, 60 name, 61 userAuth, 62 SharkUtilities.getProcessMgrPkgId(name), 63 SharkUtilities.getProcessMgrVersion(name), 64 SharkUtilities.getProcessMgrProcDefId(name)); 65 } catch (Exception ex) { 66 throw new BaseException(ex); 67 } 68 } 69 70 try { 71 return SharkEngineManager.getInstance().getInstancePersistenceManager().getAllProcessesForMgr(name,t).size(); 72 } catch (Exception e) { 73 throw new BaseException(e); 74 } 75 } 76 77 public WfProcessIterator get_iterator_process () throws BaseException { 78 WfProcessIterator ret=null; 79 SharkTransaction t = null; 80 try { 81 t = SharkUtilities.createTransaction(); 82 ret = get_iterator_process(t); 83 } catch (RootException e) { 85 SharkUtilities.emptyCaches(t); 87 if (e instanceof BaseException) 88 throw (BaseException)e; 89 else 90 throw new BaseException(e); 91 } finally { 92 SharkUtilities.releaseTransaction(t); 93 } 94 return ret; 95 } 96 97 public WfProcessIterator get_iterator_process (SharkTransaction t) throws BaseException { 98 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 99 if (sm!=null) { 100 try { 101 sm.check_processmgr_get_iterator_process(t, 102 name, 103 userAuth, 104 SharkUtilities.getProcessMgrPkgId(name), 105 SharkUtilities.getProcessMgrVersion(name), 106 SharkUtilities.getProcessMgrProcDefId(name)); 107 } catch (Exception ex) { 108 throw new BaseException(ex); 109 } 110 } 111 112 return SharkEngineManager.getInstance().getObjectFactory().createProcessIteratorWrapper(t,userAuth,name); 113 } 114 115 public WfProcess[] get_sequence_process (int max_number) throws BaseException { 116 WfProcess[] ret=null; 117 SharkTransaction t = null; 118 try { 119 t = SharkUtilities.createTransaction(); 120 ret = get_sequence_process(t,max_number); 121 } catch (RootException e) { 123 SharkUtilities.emptyCaches(t); 125 if (e instanceof BaseException) 126 throw (BaseException)e; 127 else 128 throw new BaseException(e); 129 } finally { 130 SharkUtilities.releaseTransaction(t); 131 } 132 return ret; 133 } 134 135 public WfProcess[] get_sequence_process (SharkTransaction t,int max_number) throws BaseException { 136 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 137 if (sm!=null) { 138 try { 139 sm.check_processmgr_get_sequence_process(t, 140 name, 141 userAuth, 142 SharkUtilities.getProcessMgrPkgId(name), 143 SharkUtilities.getProcessMgrVersion(name), 144 SharkUtilities.getProcessMgrProcDefId(name)); 145 } catch (Exception ex) { 146 throw new BaseException(ex); 147 } 148 } 149 150 List processes=SharkUtilities.createProcessMgrsProcessWrappers(t,userAuth,name); 151 if (max_number>processes.size() || max_number<=0) { 152 max_number=processes.size(); 153 } 154 WfProcessWrapper[] procs=new WfProcessWrapper[max_number]; 155 processes.subList(0,max_number).toArray(procs); 156 return procs; 157 } 158 159 public boolean is_member_of_process (WfProcess member) throws BaseException { 160 boolean ret=false; 161 SharkTransaction t = null; 162 try { 163 t = SharkUtilities.createTransaction(); 164 ret = is_member_of_process(t,member); 165 } catch (RootException e) { 167 SharkUtilities.emptyCaches(t); 169 if (e instanceof BaseException) 170 throw (BaseException)e; 171 else 172 throw new BaseException(e); 173 } finally { 174 SharkUtilities.releaseTransaction(t); 175 } 176 return ret; 177 } 178 179 public boolean is_member_of_process (SharkTransaction t,WfProcess member) throws BaseException { 180 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 181 if (sm!=null) { 182 try { 183 sm.check_processmgr_is_member_of_process(t, 184 name, 185 userAuth, 186 SharkUtilities.getProcessMgrPkgId(name), 187 SharkUtilities.getProcessMgrVersion(name), 188 SharkUtilities.getProcessMgrProcDefId(name)); 189 } catch (Exception ex) { 190 throw new BaseException(ex); 191 } 192 } 193 String mgrName=member.manager(t).name(t); 194 return mgrName.equals(this.name); 195 } 196 197 public process_mgr_stateType process_mgr_state () throws BaseException { 198 process_mgr_stateType ret=null; 199 SharkTransaction t = null; 200 try { 201 t = SharkUtilities.createTransaction(); 202 ret = process_mgr_state(t); 203 } catch (RootException e) { 205 SharkUtilities.emptyCaches(t); 207 if (e instanceof BaseException) 208 throw (BaseException)e; 209 else 210 throw new BaseException(e); 211 } finally { 212 SharkUtilities.releaseTransaction(t); 213 } 214 return ret; 215 } 216 217 public process_mgr_stateType process_mgr_state (SharkTransaction t) throws BaseException { 218 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 219 if (sm!=null) { 220 try { 221 sm.check_processmgr_process_mgr_state(t, 222 name, 223 userAuth, 224 SharkUtilities.getProcessMgrPkgId(name), 225 SharkUtilities.getProcessMgrVersion(name), 226 SharkUtilities.getProcessMgrProcDefId(name)); 227 } catch (Exception ex) { 228 throw new BaseException(ex); 229 } 230 } 231 232 return WfProcessMgrWrapper.getProcessMgrImpl(t,name).process_mgr_state(t); 233 } 234 235 public void set_process_mgr_state (process_mgr_stateType new_state) throws BaseException, TransitionNotAllowed { 236 SharkTransaction t = null; 237 try { 238 t = SharkUtilities.createTransaction(); 239 set_process_mgr_state(t,new_state); 240 SharkUtilities.commitTransaction(t); 241 } catch (RootException e) { 242 SharkUtilities.rollbackTransaction(t,e); 243 if (e instanceof TransitionNotAllowed) 244 throw (TransitionNotAllowed)e; 245 else if (e instanceof BaseException) 246 throw (BaseException)e; 247 else 248 throw new BaseException(e); 249 } finally { 250 SharkUtilities.releaseTransaction(t); 251 } 252 } 253 254 public void set_process_mgr_state (SharkTransaction t,process_mgr_stateType new_state) throws BaseException, TransitionNotAllowed { 255 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 256 if (sm!=null) { 257 try { 258 sm.check_processmgr_set_process_mgr_state(t, 259 name, 260 userAuth, 261 SharkUtilities.getProcessMgrPkgId(name), 262 SharkUtilities.getProcessMgrVersion(name), 263 SharkUtilities.getProcessMgrProcDefId(name)); 264 } catch (Exception ex) { 265 throw new BaseException(ex); 266 } 267 } 268 269 WfProcessMgrInternal mgrInternal=WfProcessMgrWrapper.getProcessMgrImpl(t,name); 270 mgrInternal.set_process_mgr_state(t,new_state); 271 } 272 273 public String name () throws BaseException { 274 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 275 if (sm==null) { 276 return name; 277 } 278 String ret=null; 279 SharkTransaction t = null; 280 try { 281 t = SharkUtilities.createTransaction(); 282 ret = name(t); 283 } catch (RootException e) { 285 SharkUtilities.emptyCaches(t); 287 if (e instanceof BaseException) 288 throw (BaseException)e; 289 else 290 throw new BaseException(e); 291 } finally { 292 SharkUtilities.releaseTransaction(t); 293 } 294 return ret; 295 } 296 297 public String name (SharkTransaction t) throws BaseException { 298 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 299 if (sm!=null) { 300 try { 301 sm.check_processmgr_name(t, 302 name, 303 userAuth, 304 SharkUtilities.getProcessMgrPkgId(name), 305 SharkUtilities.getProcessMgrVersion(name), 306 SharkUtilities.getProcessMgrProcDefId(name)); 307 } catch (Exception ex) { 308 throw new BaseException(ex); 309 } 310 } 311 312 return name; 313 } 314 315 public String description () throws BaseException { 316 String ret=null; 317 SharkTransaction t = null; 318 try { 319 t = SharkUtilities.createTransaction(); 320 ret = description(t); 321 } catch (RootException e) { 323 SharkUtilities.emptyCaches(t); 325 if (e instanceof BaseException) 326 throw (BaseException)e; 327 else 328 throw new BaseException(e); 329 } finally { 330 SharkUtilities.releaseTransaction(t); 331 } 332 return ret; 333 } 334 335 public String description (SharkTransaction t) throws BaseException { 336 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 337 if (sm!=null) { 338 try { 339 sm.check_processmgr_description(t, 340 name, 341 userAuth, 342 SharkUtilities.getProcessMgrPkgId(name), 343 SharkUtilities.getProcessMgrVersion(name), 344 SharkUtilities.getProcessMgrProcDefId(name)); 345 } catch (Exception ex) { 346 throw new BaseException(ex); 347 } 348 } 349 350 return WfProcessMgrWrapper.getProcessMgrImpl(t,name).description(t); 351 } 352 353 public String category () throws BaseException { 354 String ret=null; 355 SharkTransaction t = null; 356 try { 357 t = SharkUtilities.createTransaction(); 358 ret = category(t); 359 } catch (RootException e) { 361 SharkUtilities.emptyCaches(t); 363 if (e instanceof BaseException) 364 throw (BaseException)e; 365 else 366 throw new BaseException(e); 367 } finally { 368 SharkUtilities.releaseTransaction(t); 369 } 370 return ret; 371 } 372 373 public String category (SharkTransaction t) throws BaseException { 374 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 375 if (sm!=null) { 376 try { 377 sm.check_processmgr_category(t, 378 name, 379 userAuth, 380 SharkUtilities.getProcessMgrPkgId(name), 381 SharkUtilities.getProcessMgrVersion(name), 382 SharkUtilities.getProcessMgrProcDefId(name)); 383 } catch (Exception ex) { 384 throw new BaseException(ex); 385 } 386 } 387 388 return WfProcessMgrWrapper.getProcessMgrImpl(t,name).category(t); 389 } 390 391 public String version () throws BaseException { 392 String ret=null; 393 SharkTransaction t = null; 394 try { 395 t = SharkUtilities.createTransaction(); 396 ret = version(t); 397 } catch (RootException e) { 399 SharkUtilities.emptyCaches(t); 401 if (e instanceof BaseException) 402 throw (BaseException)e; 403 else 404 throw new BaseException(e); 405 } finally { 406 SharkUtilities.releaseTransaction(t); 407 } 408 return ret; 409 } 410 411 public String version (SharkTransaction t) throws BaseException { 412 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 413 if (sm!=null) { 414 try { 415 sm.check_processmgr_version(t, 416 name, 417 userAuth, 418 SharkUtilities.getProcessMgrPkgId(name), 419 SharkUtilities.getProcessMgrVersion(name), 420 SharkUtilities.getProcessMgrProcDefId(name)); 421 } catch (Exception ex) { 422 throw new BaseException(ex); 423 } 424 } 425 426 return WfProcessMgrWrapper.getProcessMgrImpl(t,name).version(t); 427 } 428 429 public Map context_signature () throws BaseException { 430 Map ret=null; 431 SharkTransaction t = null; 432 try { 433 t = SharkUtilities.createTransaction(); 434 ret = context_signature(t); 435 } catch (RootException e) { 437 SharkUtilities.emptyCaches(t); 439 if (e instanceof BaseException) 440 throw (BaseException)e; 441 else 442 throw new BaseException(e); 443 } finally { 444 SharkUtilities.releaseTransaction(t); 445 } 446 return ret; 447 } 448 449 public Map context_signature (SharkTransaction t) throws BaseException { 450 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 451 if (sm!=null) { 452 try { 453 sm.check_processmgr_context_signature(t, 454 name, 455 userAuth, 456 SharkUtilities.getProcessMgrPkgId(name), 457 SharkUtilities.getProcessMgrVersion(name), 458 SharkUtilities.getProcessMgrProcDefId(name)); 459 } catch (Exception ex) { 460 throw new BaseException(ex); 461 } 462 } 463 464 return WfProcessMgrWrapper.getProcessMgrImpl(t,name).context_signature(t); 465 } 466 467 public Map result_signature () throws BaseException { 468 Map ret=null; 469 SharkTransaction t = null; 470 try { 471 t = SharkUtilities.createTransaction(); 472 ret = result_signature(t); 473 } catch (RootException e) { 475 SharkUtilities.emptyCaches(t); 477 if (e instanceof BaseException) 478 throw (BaseException)e; 479 else 480 throw new BaseException(e); 481 } finally { 482 SharkUtilities.releaseTransaction(t); 483 } 484 return ret; 485 } 486 487 public Map result_signature (SharkTransaction t) throws BaseException { 488 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 489 if (sm!=null) { 490 try { 491 sm.check_processmgr_result_signature(t, 492 name, 493 userAuth, 494 SharkUtilities.getProcessMgrPkgId(name), 495 SharkUtilities.getProcessMgrVersion(name), 496 SharkUtilities.getProcessMgrProcDefId(name)); 497 } catch (Exception ex) { 498 throw new BaseException(ex); 499 } 500 } 501 502 return WfProcessMgrWrapper.getProcessMgrImpl(t,name).result_signature(t); 503 } 504 505 508 public WfProcess create_process (WfRequester requester) throws BaseException, 509 NotEnabled, InvalidRequester, RequesterRequired { 510 WfProcess ret=null; 511 SharkTransaction t = null; 512 try { 513 t = SharkUtilities.createTransaction(); 514 ret = create_process(t,requester); 515 SharkUtilities.commitTransaction(t); 516 } catch (RootException e) { 517 SharkUtilities.rollbackTransaction(t,e); 518 if (e instanceof NotEnabled) 519 throw (NotEnabled)e; 520 else if (e instanceof InvalidRequester) 521 throw (InvalidRequester)e; 522 else if (e instanceof RequesterRequired) 523 throw (RequesterRequired)e; 524 else if (e instanceof BaseException) 525 throw (BaseException)e; 526 else 527 throw new BaseException(e); 528 } finally { 529 SharkUtilities.releaseTransaction(t); 530 } 531 return ret; 532 } 533 534 public WfProcess create_process (SharkTransaction t,WfRequester requester) throws BaseException, 535 NotEnabled, InvalidRequester, RequesterRequired { 536 WfProcessMgrInternal mgr=WfProcessMgrWrapper.getProcessMgrImpl(t,name); 537 538 SecurityManager sm=SharkEngineManager.getInstance().getSecurityManager(); 539 if (sm!=null) { 540 try { 541 sm.check_processmgr_create_process(t, 542 name, 543 userAuth, 544 SharkUtilities.getProcessMgrPkgId(name), 545 SharkUtilities.getProcessMgrVersion(name), 546 SharkUtilities.getProcessMgrProcDefId(name)); 547 } catch (Exception ex) { 548 throw new BaseException(ex); 549 } 550 } 551 552 553 if (mgr.category(t).equalsIgnoreCase(XPDLConstants.ACCESS_LEVEL_PRIVATE)) { 555 throw new NotEnabled("The process definition defines only PRIVATE access!"); 556 } 557 558 WfRequesterInternal req=SharkEngineManager 559 .getInstance() 560 .getObjectFactory() 561 .createDefaultRequester(userAuth,requester); 562 563 564 WfProcessInternal procInternal=mgr.create_process(t,req); 565 WfProcess proc=SharkEngineManager 566 .getInstance() 567 .getObjectFactory() 568 .createProcessWrapper(userAuth,procInternal.manager_name(t),procInternal.key(t)); 569 return proc; 570 } 571 572 public String toString () { 573 return "[name="+name+"]"; 574 } 575 576 580 public boolean equals (Object obj) { 581 if (!(obj instanceof WfProcessMgr)) return false; 582 WfProcessMgr mgr=(WfProcessMgr)obj; 583 try { 584 if (obj instanceof WfProcessMgrWrapper) { 585 return ((WfProcessMgrWrapper)obj).name.equals(name); 586 } else { 587 return mgr.name().equals(name); 588 } 589 } catch (Exception ex) { 590 return false; 591 } 592 } 593 594 private static WfProcessMgrInternal getProcessMgrImpl ( 595 SharkTransaction t, 596 String name) throws BaseException { 597 WfProcessMgrInternal mgr=SharkUtilities.getProcessMgr(t,name); 598 if (mgr==null) throw new BaseException("ProcessMgr does not exist"); 599 return mgr; 600 } 601 } 602 603 | Popular Tags |