1 10 11 package org.enhydra.jawe.xml.elements; 12 13 import org.enhydra.jawe.xml.ToNameMutableTreeNode; 14 import org.enhydra.jawe.xml.*; 15 import org.enhydra.jawe.xml.panels.*; 16 17 import javax.swing.*; 18 import java.util.*; 19 import java.awt.*; 20 import javax.swing.tree.*; 21 import javax.swing.*; 22 23 import org.w3c.dom.*; 24 25 28 public class WorkflowProcess extends XMLCollectionElement { 29 private ProcessHeader refProcessHeader=new ProcessHeader(); 30 private RedefinableHeader refRedefinableHeader=new RedefinableHeader(this); private FormalParameters refFormalParameters; 32 private DataFields refDataFields=new DataFields(this); private Participants refParticipants; private Applications refApplications=new Applications(this); private ActivitySets refActivitySets=new ActivitySets(this); private Activities refActivities=new Activities(this); private Transitions refTransitions=new Transitions(this); private ExtendedAttributes refExtendedAttributes=new ExtendedAttributes(this); 40 41 private XMLAttribute attrName=new XMLAttribute("Name"); 42 private XMLAttribute attrAccessLevel=new XMLAttribute("AccessLevel", 43 new String [] { 44 "", 45 "PUBLIC", 46 "PRIVATE" 47 },1); 48 49 50 51 private Package myPackage=null; 52 53 59 private String visuallySortedParticipantIDs=""; 60 61 67 private Set startDescriptions=new HashSet(); 68 74 private Set endDescriptions=new HashSet(); 75 76 77 private ExtendedAttributes clonedEAs; 78 79 80 private transient long nextActivityId=0; 83 private transient long nextTransitionId=0; 84 85 92 public WorkflowProcess (WorkflowProcesses wps,Package p) { 93 super(wps); 94 this.myPackage=p; 95 refParticipants=new Participants(this); refFormalParameters=new FormalParameters(this,myPackage); 100 try { 101 setIDPrefixForCollections(); 102 } catch (Exception ex) {} 103 104 fillStructure(); 105 106 try { 109 RedefinableHeader prh=(RedefinableHeader)p.get("RedefinableHeader"); 110 refRedefinableHeader.set("Author",prh.get("Author").toString()); 111 refRedefinableHeader.set("Version",prh.get("Version").toString()); 112 refRedefinableHeader.set("Codepage",prh.get("Codepage").toString()); 113 refRedefinableHeader.set("Countrykey",prh.get("Countrykey").toString()); 114 refRedefinableHeader.set("PublicationStatus", 115 ((XMLAttribute)prh.get("PublicationStatus")).getChoosen()); 116 Responsibles rwp=(Responsibles)refRedefinableHeader.get("Responsibles"); 117 Responsibles rpkg=(Responsibles)prh.get("Responsibles"); 118 Iterator it=rpkg.toCollection().iterator(); 119 while (it.hasNext()) { 120 Responsible r=(Responsible)it.next(); 121 Responsible rNew=(Responsible)rwp.generateNewElement(); 122 rNew.setValue(r.toValue()); 123 rwp.add(rNew); 124 } 125 } catch (Exception ex) {} 126 127 } 128 129 133 protected void fillStructure () { 134 super.fillStructure(); 135 complexStructure.add(attrName); 136 attributes.add(attrName); 137 complexStructure.add(attrAccessLevel); 138 attributes.add(attrAccessLevel); 139 refProcessHeader.setRequired(true); 140 complexStructure.add(refProcessHeader); 141 complexStructure.add(refRedefinableHeader); 142 complexStructure.add(refFormalParameters); 143 complexStructure.add(refDataFields); 144 complexStructure.add(refParticipants); 145 complexStructure.add(refApplications); 146 complexStructure.add(refActivitySets); 147 complexStructure.add(refActivities); 148 complexStructure.add(refTransitions); 149 complexStructure.add(refExtendedAttributes); 150 } 151 152 157 public Package getPackage () { 158 return myPackage; 159 } 160 161 165 public java.util.List getEntitiesToInsert (Object forObject) { 166 java.util.List lhs=new ArrayList(); 167 boolean isMine=myPackage.isMadeByJaWE(); 168 Collection acts=null; 169 Collection parts=null; 170 Collection trans=null; 171 if (forObject instanceof WorkflowProcess) { 172 acts=refActivities.toCollection(); 173 trans=refTransitions.toCollection(); 174 } else if (forObject instanceof Activity) { 175 Activity act=(Activity)forObject; 176 BlockActivity ba=act.getBlockActivity(); 177 String baID=""; 178 if (ba!=null) { 179 baID=ba.get("BlockId").toValue().toString(); 180 } 181 ActivitySet as=refActivitySets.getActivitySet(baID); 182 if (as!=null) { 183 acts=((Activities)as.get("Activities")).toCollection(); 184 trans=((Transitions)as.get("Transitions")).toCollection(); 185 } 186 } 187 188 try { 189 parts=gatherParticipants(forObject,acts,isMine); 190 lhs.addAll(acts); 191 lhs.addAll(parts); 192 lhs.addAll(trans); 193 } catch (Exception ex) {} 194 195 return lhs; 197 } 198 199 private void displayContent (HashSet hs,Object forObject) { 201 Iterator it=hs.iterator(); 202 System.out.println("Entities inside "+forObject+":"); 203 while (it.hasNext()) { 204 Object nxt=it.next(); 205 if (nxt instanceof Transition) { 206 System.out.println("----------> "+((Transition)nxt).get("Name")); 207 } 208 else { 209 System.out.println("----------> "+nxt+", instance of"+nxt.getClass()); 210 } 211 } 212 } 213 214 221 public Set getStartDescriptions () { 222 return startDescriptions; 223 } 224 225 231 public void setStartDescriptions (Set sd) { 232 startDescriptions=sd; 233 } 234 235 242 public Set getEndDescriptions () { 243 return endDescriptions; 244 } 245 246 252 public void setEndDescriptions (Set eds) { 253 endDescriptions=eds; 254 } 255 256 267 public String getVisuallySortedParticipantIDs () { 268 return visuallySortedParticipantIDs; 269 } 270 271 277 public void setVisuallySortedParticipantIDs (String vsPID) { 278 visuallySortedParticipantIDs=vsPID; 279 } 280 281 288 public String getTooltip () { 289 return XMLUtil.makeTooltip(new XMLElement[] {attrId,attrName,attrAccessLevel, 290 refProcessHeader.get("Created"),refProcessHeader.get("Description"), 291 refProcessHeader.get("Priority"),refProcessHeader.get("Limit"), 292 refProcessHeader.get("ValidFrom"),refProcessHeader.get("ValidTo"), 293 refRedefinableHeader.get("Author"),refRedefinableHeader.get("Version"), 294 refRedefinableHeader.get("Codepage"),refRedefinableHeader.get("Countrykey"), 295 refRedefinableHeader.get("PublicationStatus")}); 296 } 297 298 299 305 public void toXML (Node parent) throws DOMException { 306 ExtendedAttribute ea; 307 Iterator it; 308 309 Set easToRemove=new HashSet(); 311 if (visuallySortedParticipantIDs.length()>0) { 312 ea=new ExtendedAttribute(refExtendedAttributes); 313 ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea); 314 ea.set("Name","ParticipantVisualOrder"); 315 ea.set("Value",visuallySortedParticipantIDs); 316 easToRemove.add(ea); 317 } 318 319 if (endDescriptions.size()>0) { 321 it=endDescriptions.iterator(); 322 while (it.hasNext()) { 323 ea=new ExtendedAttribute(refExtendedAttributes); 324 ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea); 325 ea.set("Name","EndOfWorkflow"); 326 ea.set("Value",(String )it.next()); 327 easToRemove.add(ea); 328 } 329 } 330 if (startDescriptions.size()>0) { 331 it=startDescriptions.iterator(); 332 while (it.hasNext()) { 333 ea=new ExtendedAttribute(refExtendedAttributes); 334 ((ArrayList)refExtendedAttributes.toCollection()).add(0,ea); 335 ea.set("Name","StartOfWorkflow"); 336 ea.set("Value",(String )it.next()); 337 easToRemove.add(ea); 338 } 339 } 340 if (parent.getOwnerDocument()!=null) { 341 super.toXML(parent); 342 } else { 344 Node node = ((Document) parent).createElement(name); 345 super.toXML(node); 346 parent.appendChild(node); 347 } 348 349 refExtendedAttributes.toCollection().removeAll(easToRemove); 351 } 352 353 358 protected void afterImporting () { 359 boolean isMine=myPackage.isMadeByJaWE(); 363 364 Set easToRemove=new HashSet(); 366 367 if (isMine) { 368 Iterator it=refExtendedAttributes.toCollection().iterator(); 369 String nm=""; 370 String val=""; 371 while (it.hasNext()) { 372 ExtendedAttribute ea=(ExtendedAttribute)it.next(); 373 nm=ea.get("Name").toValue().toString(); 374 val=ea.get("Value").toValue().toString(); 375 if (nm.equals("ParticipantVisualOrder") && visuallySortedParticipantIDs.length()==0) { 376 visuallySortedParticipantIDs=val; 377 easToRemove.add(ea); 378 } 379 if (nm.equals("StartOfWorkflow")) { 380 if (XMLUtil.howManyStringsWithinString(val,";")==4) { 381 startDescriptions.add(val); 382 easToRemove.add(ea); 383 } 384 } 385 if (nm.equals("EndOfWorkflow")) { 386 if (XMLUtil.howManyStringsWithinString(val,";")==4) { 387 endDescriptions.add(val); 388 easToRemove.add(ea); 389 } 390 } 391 } 392 } 393 refExtendedAttributes.toCollection().removeAll(easToRemove); 396 397 refRedefinableHeader.afterImporting(); 399 refActivitySets.afterImporting(); 402 refActivities.afterImporting(); 403 refTransitions.afterImporting(); 404 refActivities.fillOutgoingTransitions(); 405 } 406 407 411 private java.util.List gatherParticipants (Object forObject, 412 Collection ownedActivities,boolean isMine) { 413 414 java.util.List gatherInto=new ArrayList(); 415 416 String vsIDs=""; 417 String [] vIDs=null; 418 419 if (isMine) { 420 String delimiterSign=";"; 421 if (forObject instanceof Activity) { 423 Activity block=(Activity)forObject; 424 vsIDs=block.getVisuallySortedParticipantIDs(); 425 } else { 427 vsIDs=getVisuallySortedParticipantIDs(); 428 } 429 vIDs=XMLUtil.tokenize(vsIDs,delimiterSign); 430 } else { 432 if (ownedActivities.size()>0) { 433 Set partIDs=new HashSet(); 434 Iterator it=ownedActivities.iterator(); 435 Activity a; 436 437 String ID; 438 while (it.hasNext()) { 439 Object nextObj=it.next(); 440 if (nextObj instanceof Activity) { 441 a=(Activity)nextObj; 442 Object p=a.get("Performer").toValue(); 443 if (p!=null) { 444 if (p instanceof Participant) { 445 ID=((Participant)p).getID(); 446 } else { 447 ID=p.toString(); 448 } 449 partIDs.add(ID); 450 } 451 } 452 } 453 if (partIDs.size()>0) { 454 vIDs=new String [partIDs.size()]; 455 partIDs.toArray(vIDs); 456 } 457 } 458 } 459 460 if (vIDs!=null && vIDs.length>0) { 462 Participant defaultP=Participant.getFreeTextExpressionParticipant(); 463 for (int i=0; i<vIDs.length; i++) { 464 String pID=vIDs[i]; 465 Participant p=refParticipants.getParticipant(pID); 466 if (p!=null) { 467 gatherInto.add(p); 468 } else { 469 if (!gatherInto.contains(defaultP)) { 470 gatherInto.add(defaultP); 471 } 472 } 473 } 474 } 475 if (gatherInto.size()==0 && ownedActivities.size()>0) { 478 gatherInto.add(Participant.getFreeTextExpressionParticipant()); 479 } 480 481 return gatherInto; 482 } 483 484 493 public String toString() { 494 String disp=attrName.toString(); 495 if (disp.trim().length()==0) { 496 disp=attrId.toString(); 497 } 498 return disp; 499 } 500 501 508 public XMLPanel getPanel (int no) { 509 XMLPanel p; 510 switch (no) { 511 case 1: 512 clonedEAs=(ExtendedAttributes)refExtendedAttributes.clone(); 513 p=new XMLGroupPanel(this, 514 new XMLElement[] { 515 attrId, 516 attrName, 517 attrAccessLevel, 518 clonedEAs 519 },XMLUtil.getLanguageDependentString("GeneralKey")); 520 break; 521 case 2: 522 p=refProcessHeader.getPanel(); 523 break; 524 case 3: 525 p=refRedefinableHeader.getPanel(); 526 break; 527 case 4: 528 p=refParticipants.getPanel(); 529 break; 530 case 5: 531 p=refApplications.getPanel(); 532 break; 533 case 6: 534 p=refDataFields.getPanel(); 535 break; 536 case 7: 537 p=refFormalParameters.getPanel(); 538 break; 539 case 8: 540 p=refActivities.getPanel(); 541 break; 542 case 9: 543 p=refTransitions.getPanel(); 544 break; 545 case 10: 546 p=refActivitySets.getPanel(); 547 break; 548 default: 549 p=new XMLPanel(); 550 } 551 return p; 552 } 553 554 555 565 public XMLPanel getPanel () { 566 XMLPanel[] p=new XMLPanel[10]; 567 for (int i=0; i<10; i++) { 568 p[i]=getPanel(i+1); 569 } 570 XMLTabbedPanel tp=new XMLTabbedPanel(this,p); 571 572 return tp; 573 } 574 575 576 protected void setIDPrefixForCollections () { 577 String colPref=getID()+this.ID_DELIMITER; 578 refApplications.setIDPrefix(colPref+"App"); 579 refActivitySets.setIDPrefix(colPref+"Ase"); 580 refActivities.setIDPrefix(colPref+"Act"); 581 refDataFields.setIDPrefix(colPref+"Dat"); 582 refFormalParameters.setIDPrefix(colPref+"For"); 583 refParticipants.setIDPrefix(colPref+"Par"); 584 refTransitions.setIDPrefix(colPref+"Tra"); 585 } 586 587 588 public void fromXML(Node node) { 589 attrAccessLevel.setValue(""); 590 591 refRedefinableHeader.set("Author",""); 594 refRedefinableHeader.set("Version",""); 595 refRedefinableHeader.set("Codepage",""); 596 refRedefinableHeader.set("Countrykey",""); 597 XMLAttribute ps=(XMLAttribute)refRedefinableHeader.get("PublicationStatus"); 598 try { 599 ps.setValue(ps.getChoices()[0]); 600 } catch (Exception ex) {} 601 Responsibles rsp=(Responsibles)refRedefinableHeader.get("Responsibles"); 602 rsp.clear(); 603 604 processAttributes(node); 605 606 setIDPrefixForCollections(); 607 608 processElements(node); 609 610 ((WorkflowProcesses)myCollection).updateID(getID()); 611 } 612 613 public void readFromXML(Node node) { 614 refRedefinableHeader.set("Author",""); 617 refRedefinableHeader.set("Version",""); 618 refRedefinableHeader.set("Codepage",""); 619 refRedefinableHeader.set("Countrykey",""); 620 XMLAttribute ps=(XMLAttribute)refRedefinableHeader.get("PublicationStatus"); 621 try { 622 ps.setValue(ps.getChoices()[0]); 623 } catch (Exception ex) {} 624 Responsibles rsp=(Responsibles)refRedefinableHeader.get("Responsibles"); 625 rsp.clear(); 626 super.fromXML(node); 627 } 628 629 632 public boolean isIDUniqueAndValid (XMLPanel tabbedPanel) { 633 XMLGroupPanel groupPanel=(XMLGroupPanel)((XMLTabbedPanel)tabbedPanel).getTabbedPanel(0); 634 XMLTextPanel tp=(XMLTextPanel)groupPanel.getPanel(0); 635 String IDToCheck=tp.getText(); 636 XMLComplexElement wp=getCollection().getCollectionElement(IDToCheck); 638 boolean isOK=true; 639 String message=null; 640 String dialogTitle=null; 641 if (wp!=null && wp!=this) { 642 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeUnique"); 643 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotUnique"); 644 isOK=false; 645 } else if (!XMLCollection.isIdValid(IDToCheck)) { 646 message=XMLUtil.getLanguageDependentString("ErrorIDMustBeValid"); 647 dialogTitle=XMLUtil.getLanguageDependentString("DialogIDIsNotValid"); 648 isOK=false; 649 } 650 if (!isOK) { 651 XMLPanel.errorMessage(groupPanel.getDialog(),dialogTitle,"",message); 652 ((JTextField)tp.getComponent(2)).requestFocus(); 653 } 654 return isOK; 655 } 656 657 658 public boolean isValidEnter (XMLPanel p) { 659 refRedefinableHeader.isValidEnter(((XMLTabbedPanel)p).getTabbedPanel(2)); 660 if (clonedEAs!=null) { 661 complexStructure.remove(refExtendedAttributes); 662 refExtendedAttributes=clonedEAs; 663 complexStructure.add(12,refExtendedAttributes); 664 } 665 return true; 666 } 667 668 689 690 public long getNextActivityId () { 691 return (++nextActivityId); 692 } 693 694 public long getCurrentActivityId () { 695 return nextActivityId; 696 } 697 698 public void setCurrentActivityId (long curId) { 699 nextActivityId=curId; 700 } 701 702 public void decrementActivityId () { 703 nextActivityId--; 704 } 705 706 public void resetActivityId () { 707 nextActivityId=0; 708 } 709 710 public Activity getActivity (String id) { 711 Activity ret=refActivities.getActivity(id); 712 if (ret==null) { 713 Iterator ass=refActivitySets.toCollection().iterator(); 714 while (ass.hasNext()) { 715 ActivitySet as=(ActivitySet)ass.next(); 716 ret=((Activities)as.get("Activities")).getActivity(id); 717 if (ret!=null) { 718 break; 719 } 720 } 721 } 722 return ret; 723 } 724 725 public boolean isActivityIdDuplicated (String id) { 726 int cnt=0; 727 cnt+=((refActivities.getActivity(id)==null) ? 0 : 1); 728 Iterator ass=refActivitySets.toCollection().iterator(); 729 while (ass.hasNext()) { 730 ActivitySet as=(ActivitySet)ass.next(); 731 cnt+=((((Activities)as.get("Activities")).getActivity(id)==null) ? 0 : 1); 732 if (cnt>1) { 733 break; 734 } 735 } 736 return (cnt>1); 737 } 738 739 public long getNextTransitionId () { 740 return (++nextTransitionId); 741 } 742 743 public long getCurrentTransitionId () { 744 return nextTransitionId; 745 } 746 747 public void setCurrentTransitionId (long curId) { 748 nextTransitionId=curId; 749 } 750 751 public void decrementTransitionId () { 752 nextTransitionId--; 753 } 754 755 public void resetTransitionId () { 756 nextTransitionId=0; 757 } 758 759 public Transition getTransition (String id) { 760 Transition ret=refTransitions.getTransition(id); 761 if (ret==null) { 762 Iterator ass=refActivitySets.toCollection().iterator(); 763 while (ass.hasNext()) { 764 ActivitySet as=(ActivitySet)ass.next(); 765 ret=((Transitions)as.get("Transitions")).getTransition(id); 766 if (ret!=null) { 767 break; 768 } 769 } 770 } 771 return ret; 772 } 773 774 public boolean isTransitionIdDuplicated (String id) { 775 int cnt=0; 776 cnt+=((refTransitions.getTransition(id)==null) ? 0 : 1); 777 Iterator ass=refActivitySets.toCollection().iterator(); 778 while (ass.hasNext()) { 779 ActivitySet as=(ActivitySet)ass.next(); 780 cnt+=((((Transitions)as.get("Transitions")).getTransition(id)==null) ? 0 : 1); 781 if (cnt>1) { 782 break; 783 } 784 } 785 return (cnt>1); 786 } 787 788 789 } 790 | Popular Tags |