1 10 11 package org.enhydra.jawe.xml; 12 13 import org.enhydra.jawe.xml.elements.*; 14 15 import java.util.*; 16 import java.io.*; 17 import java.net.URL ; 18 import javax.swing.*; 19 import java.awt.*; 20 import javax.swing.tree.*; 21 22 import javax.xml.transform.*; 23 import javax.xml.transform.dom.*; 24 import javax.xml.transform.stream.*; 25 import org.w3c.dom.*; 26 27 import javax.xml.parsers.DocumentBuilderFactory ; 28 import javax.xml.parsers.DocumentBuilder ; 29 import org.apache.xml.serialize.XMLSerializer; 30 import org.apache.xml.serialize.OutputFormat; 31 import org.apache.xerces.parsers.DOMParser; 32 import org.xml.sax.*; 33 34 import org.enhydra.jawe.xml.elements.Package; 35 36 43 public class XMLUtil { 44 45 46 private static final String EMPTY_STRING =""; 47 48 private static final String HTML_OPEN ="<html>"; 49 50 private static final String HTML_CLOSE ="</html>"; 51 52 private static final String STRONG_OPEN ="<strong>"; 53 54 private static final String STRONG_CLOSE ="</strong>"; 55 56 private static final String LINE_BREAK ="<br>"; 57 58 private static final String COLON_SPACE =": "; 59 60 private static Window myWindow; 61 62 private static ResourceBundle defaultResources; 63 private static ResourceBundle choosenResources; 64 private static Properties properties; 65 66 private static XMLUtil.XMLFilter allFilter = new XMLUtil.XMLFilter(null); 68 private static XMLUtil.XMLFilter xmlFilter = new XMLUtil.XMLFilter("xml"); 69 private static XMLUtil.XMLFilter xpdlFilter = new XMLUtil.XMLFilter("xpdl"); 70 private static XMLUtil.XMLFilter jpgFilter = new XMLUtil.XMLFilter("jpg"); 71 private static XMLUtil.XMLFilter svgFilter = new XMLUtil.XMLFilter("svg"); 72 private static XMLUtil.XMLFilter txtFilter = new XMLUtil.XMLFilter("txt"); 73 74 private static javax.swing.filechooser.FileFilter [] lastChoosenFilter= 75 new javax.swing.filechooser.FileFilter [5]; 76 static { 77 lastChoosenFilter[0]=xpdlFilter; 78 lastChoosenFilter[1]=jpgFilter; 79 lastChoosenFilter[2]=svgFilter; 80 lastChoosenFilter[3]=txtFilter; 81 lastChoosenFilter[4]=allFilter; 82 } 83 84 private static JFileChooser chooser; 85 86 static { 87 String userDir=System.getProperty("user.dir"); 88 chooser=new JFileChooser(userDir); 89 } 90 91 public static final int INFORMATION_MESSAGE = JOptionPane.INFORMATION_MESSAGE; 92 public static final int ERROR_MESSAGE = JOptionPane.ERROR_MESSAGE; 93 94 98 private static final class XMLFilter extends javax.swing.filechooser.FileFilter { 99 private String myExtension=null; 100 101 XMLFilter (String extension) { 102 this.myExtension=extension; 103 } 104 105 public String getExtension () { 106 return myExtension; 107 } 108 109 public boolean accept (File f) { 110 if(f != null) { 111 if(f.isDirectory()) { 112 return true; 113 } 114 if (myExtension!=null) { 115 String extension = null; 116 String fName = f.getName(); 117 int i = fName.lastIndexOf('.'); 118 if(i>0 && i<fName.length()-1) { 119 extension=fName.substring(i+1).toLowerCase(); 120 } 121 122 if(extension != null && extension.equalsIgnoreCase(myExtension)) { 123 return true; 124 } 125 } else { 126 return true; 127 } 128 } 129 return false; 130 } 131 132 public String getDescription () { 133 if (myExtension!=null) { 134 return XMLUtil.getLanguageDependentString(myExtension.toUpperCase()+"Description"); 135 } else { 136 return XMLUtil.getLanguageDependentString("ALLDescription"); 137 } 138 } 139 } 140 142 public static void setApplicationWindow (Window w) { 143 myWindow=w; 144 } 145 146 public static void setDefaultResources (ResourceBundle defaultR) { 147 defaultResources=defaultR; 148 } 149 150 public static void setChoosenResources (ResourceBundle choosenR) { 151 choosenResources=choosenR; 152 } 153 154 public static void setProperties (Properties props) { 155 properties=props; 156 } 157 158 159 public static void message(String message,int type) { 160 JOptionPane.showMessageDialog(myWindow,message, 161 XMLUtil.getLanguageDependentString("Title"),type); 162 } 163 164 174 public static String dialog(Component parent,String message, 175 int mode,int filteringMode,String initialName) { 176 chooser.updateUI(); 177 chooser.setDialogTitle(message); 178 int setFilterIndex = 0; 179 switch (filteringMode) { 180 case 0: 181 chooser.setAcceptAllFileFilterUsed(false); 182 chooser.setFileFilter(allFilter); 183 chooser.setFileFilter(xmlFilter); 184 chooser.setFileFilter(xpdlFilter); 185 chooser.removeChoosableFileFilter(jpgFilter); 186 chooser.removeChoosableFileFilter(svgFilter); 187 chooser.removeChoosableFileFilter(txtFilter); 188 setFilterIndex = 0; 189 break; 190 case 1: 191 chooser.setAcceptAllFileFilterUsed(false); 192 chooser.setFileFilter(allFilter); 193 chooser.setFileFilter(jpgFilter); 194 chooser.removeChoosableFileFilter(xmlFilter); 195 chooser.removeChoosableFileFilter(xpdlFilter); 196 chooser.removeChoosableFileFilter(svgFilter); 197 chooser.removeChoosableFileFilter(txtFilter); 198 setFilterIndex = 1; 199 break; 200 case 2: 201 chooser.setAcceptAllFileFilterUsed(false); 202 chooser.setFileFilter(allFilter); 203 chooser.setFileFilter(svgFilter); 204 chooser.removeChoosableFileFilter(xmlFilter); 205 chooser.removeChoosableFileFilter(xpdlFilter); 206 chooser.removeChoosableFileFilter(jpgFilter); 207 chooser.removeChoosableFileFilter(txtFilter); 208 setFilterIndex = 2; 209 break; 210 case 3: 211 chooser.setAcceptAllFileFilterUsed(false); 212 chooser.setFileFilter(allFilter); 213 chooser.setFileFilter(txtFilter); 214 chooser.removeChoosableFileFilter(xmlFilter); 215 chooser.removeChoosableFileFilter(xpdlFilter); 216 chooser.removeChoosableFileFilter(jpgFilter); 217 chooser.removeChoosableFileFilter(svgFilter); 218 setFilterIndex = 3; 219 break; 220 default: 221 chooser.setAcceptAllFileFilterUsed(false); 222 chooser.setFileFilter(allFilter); 223 chooser.removeChoosableFileFilter(xmlFilter); 224 chooser.removeChoosableFileFilter(xpdlFilter); 225 chooser.removeChoosableFileFilter(jpgFilter); 226 chooser.removeChoosableFileFilter(svgFilter); 227 chooser.removeChoosableFileFilter(txtFilter); 228 setFilterIndex = 4; 229 break; 230 } 231 try { 232 chooser.setFileFilter(lastChoosenFilter[setFilterIndex]); 233 } catch (Exception ex) {} 234 235 if (initialName!=null && initialName.length()>0) { 236 chooser.setSelectedFile(new File(initialName)); 237 } 238 239 int returnVal=-1; 240 String fileName=null; 241 242 while (true) { 243 if (mode==0) { 244 returnVal = chooser.showOpenDialog(parent); 245 } 246 else { 247 returnVal = chooser.showSaveDialog(parent); 248 } 249 250 if(returnVal == JFileChooser.APPROVE_OPTION) { 251 File f=chooser.getSelectedFile(); 252 fileName=f.getAbsolutePath(); 253 String extension=((XMLUtil.XMLFilter)chooser.getFileFilter()).getExtension(); 257 int dotIndex=f.getName().lastIndexOf("."); 258 259 String oldFilename=fileName; 260 if (mode==1) { 261 if ((filteringMode>=0 && filteringMode<=2) && extension!=null && 262 dotIndex==-1) { 263 fileName+="."+extension; 264 } 265 if (new File(fileName).exists()) { 267 int r=JOptionPane.showConfirmDialog(myWindow, 268 XMLUtil.getLanguageDependentString("WarningFileAlreadyExistsDoYouWantToReplaceIt"), 269 XMLUtil.getLanguageDependentString("Title"),JOptionPane.YES_NO_OPTION); 270 if (r==JOptionPane.NO_OPTION) { 271 fileName=oldFilename; 272 continue; 273 } 274 } 275 276 } else { 280 if (mode==0 && !f.exists()) { 281 if ((filteringMode>=0 && filteringMode<=2) && dotIndex==-1) { 282 fileName+="."+extension; 283 if (!new File(fileName).exists()) { 284 fileName=null; 285 } 286 } else { 287 fileName=null; 288 } 289 } 290 if (fileName==null) { 291 XMLUtil.message( 292 XMLUtil.getLanguageDependentString("WarningFileDoesNotExistPleaseSelectExistingFileToOpen"), 293 JOptionPane.WARNING_MESSAGE); 294 fileName=oldFilename; 295 continue; 296 } 297 } 298 } 299 break; 300 } 301 302 try { 303 lastChoosenFilter[setFilterIndex]=chooser.getFileFilter(); 304 } catch (Exception ex) {} 305 306 return fileName; 307 } 308 309 319 public static String getLanguageDependentString(String nm) { 320 String str; 321 try { 322 str=choosenResources.getString(nm); 323 } catch (MissingResourceException mre) { 324 try { 325 str=defaultResources.getString(nm); 326 } catch (MissingResourceException mre1) { 327 str = null; 328 } catch (NullPointerException npe) { 329 str=null; 330 } 331 } catch (NullPointerException npe) { 332 334 ResourceBundle orig=ResourceBundle. 335 getBundle("org.enhydra.jawe.resources.JaWE"); 336 try { 337 str=orig.getString(nm); 338 } catch (Exception ex) { 339 str=null; 340 } 341 } 342 return str; 343 } 344 345 351 public static URL getResource(String key) { 352 try { 353 String name=properties.getProperty(key); 354 if (name != null) { 355 URL url = XMLUtil.class.getClassLoader().getResource(name); 356 return url; 357 } 358 } catch (Exception ex) {} 359 return null; 360 } 361 362 368 public static String [] tokenize(String input,String boundary) { 369 if (input==null) input=""; 370 Vector v = new Vector(); 371 StringTokenizer t = new StringTokenizer(input,boundary); 372 String cmd[]; 373 374 while (t.hasMoreTokens()) 375 v.addElement(t.nextToken()); 376 cmd = new String [v.size()]; 377 for (int i = 0; i < cmd.length; i++) 378 cmd[i] = (String )v.elementAt(i); 379 380 return cmd; 381 } 382 383 386 public static int howManyStringsWithinString (String toSearch,String toFind) { 387 try { 388 int startAt=0; 389 int howMany=0; 390 391 int fnd; 392 while ((fnd=toSearch.indexOf(toFind,startAt))!=-1) { 393 howMany++; 394 startAt=(fnd+toFind.length()); 395 } 396 return howMany; 397 } catch (Exception ex) { 398 return -1; 399 } 400 } 401 402 406 public static String makeTooltip(XMLElement[] elements){ 407 if (elements==null) return ""; 408 String s = HTML_OPEN; 409 for (int i=0; i<elements.length; i++) { 410 s+=makeAnotherHtmlLine(elements[i]); 411 } 412 s=s.substring(0, s.length() - LINE_BREAK.length()); 413 s+=HTML_CLOSE; 414 return s; 415 } 416 417 418 private static String makeAnotherHtmlLine(XMLElement el) { 419 int MAX_LENGTH=100; 420 int MAX_LINES_PER_TEXT=15; 421 String textToAppend=""; 422 textToAppend += STRONG_OPEN; 423 textToAppend += el.toLabel()+COLON_SPACE; 424 textToAppend += STRONG_CLOSE; 425 String val=el.toString(); 426 val=val.replaceAll("<","<"); 427 val=val.replaceAll(">",">"); 428 int vl=val.length(); 429 if (vl>MAX_LENGTH) { 430 String newVal=""; 431 int hm=vl/MAX_LENGTH; 432 for (int i=0; i<=hm; i++) { 433 int startI=i*MAX_LENGTH; 434 int endI=(i+1)*MAX_LENGTH; 435 if (endI>vl) { 436 endI=vl; 437 } 438 newVal=newVal+val.substring(startI,endI); 439 if (i==MAX_LINES_PER_TEXT) { 440 newVal=newVal+" ..."; 441 break; 442 } 443 if (i<hm) { 444 newVal+=LINE_BREAK; 445 newVal+=XMLUtil.makeEmptyHTMLText((el.toLabel()+COLON_SPACE).length()); 446 } 447 } 448 val=newVal; 449 } 450 textToAppend += val; 451 textToAppend += LINE_BREAK; 452 453 return textToAppend; 454 } 455 456 public static String getCanonicalPath (String path, boolean canBeDirectory) { 457 File f=new File(path); 458 if (!f.isAbsolute()) { 459 f=new File(System.getProperty("user.dir")+File.separator+path); 460 } 461 if (!f.exists() || (f.isDirectory() && !canBeDirectory)) { 462 System.err.println("The file "+f.getAbsolutePath()+" does not exist"); 463 return null; 464 } else { 465 return getCanonicalPath(f); 466 } 467 } 468 469 private static String getCanonicalPath (File f) { 470 try { 471 return f.getCanonicalPath(); 472 } catch (Exception ex) { 473 return f.getAbsolutePath(); 474 } 475 } 476 477 485 public static void parseElements (Node node,Collection complexStructure) { 486 String nameSpacePrefix=node.getPrefix(); 487 if (nameSpacePrefix!=null) { 488 nameSpacePrefix+=":"; 489 } else { 490 nameSpacePrefix=""; 491 } 492 Iterator it=complexStructure.iterator(); 494 while (it.hasNext()) { 495 XMLElement el=(XMLElement)it.next(); 496 if (!(el instanceof XMLAttribute) && !(el instanceof XMLComplexChoice) 497 && node!=null) { 498 Node child = getChildByName(node,nameSpacePrefix+el.name); 501 if (child!=null) { 502 el.fromXML(child); 503 } 504 } 505 else { 506 if (el instanceof XMLComplexChoice) { 507 Object [] ch=((XMLComplexChoice)el).getChoices(); 508 if (ch != null && node!=null) { 509 for (int i=0; i<ch.length; i++) { 510 XMLElement chc=(XMLElement)ch[i]; 511 Node child = getChildByName(node,nameSpacePrefix+chc.name); 513 if (child!=null) { 514 ((XMLComplexChoice)el).fromXML(chc.name,child); 515 } 516 } 517 } 518 } 519 } 520 } 521 } 522 523 public static Node getChildByName(Node parent,String childName) { 524 NodeList children = parent.getChildNodes(); 525 for (int i = 0; i < children.getLength(); ++i) { 526 Node child = (Node) children.item(i); 527 if (child.getNodeName().equals(childName)) { 528 return child; 529 } 530 } 531 return null; 532 } 533 534 public static String getID (Node node) { 535 try { 536 NamedNodeMap nnm=node.getAttributes(); 537 Node attrib=nnm.getNamedItem("Id"); 538 Object ID; 539 if (attrib.hasChildNodes()) { 540 ID=attrib.getChildNodes().item(0).getNodeValue(); 541 } else { 542 ID=attrib.getNodeValue(); 543 } 544 return ID.toString(); 545 } catch (Exception ex) { 546 return ""; 547 } 548 } 549 550 public static String getContent (Node node,boolean omitXMLDeclaration) { 551 try { 552 ByteArrayOutputStream baos=new ByteArrayOutputStream(); 553 554 TransformerFactory tFactory = 556 TransformerFactory.newInstance(); 557 Transformer transformer = tFactory.newTransformer(); 558 transformer.setOutputProperty("indent","yes"); 559 transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount","4"); 560 transformer.setOutputProperty("encoding","UTF-8"); 561 if (omitXMLDeclaration) { 562 transformer.setOutputProperty("omit-xml-declaration","yes"); 563 } 564 565 DOMSource source = new DOMSource(node); 566 StreamResult result = new StreamResult(baos); 567 transformer.transform(source,result); 568 569 String cont=baos.toString("UTF8"); 570 571 baos.close(); 572 return cont; 573 } catch (Exception ex) { 574 return ""; 575 } 576 } 577 578 public static String getChildNodesContent (Node node) { 579 String txt=""; 580 if (node!=null) { 581 if (node.hasChildNodes()) { 582 txt=XMLUtil.getContent(node,true); 583 try { 584 Node fc=node.getFirstChild(); 585 String fcnc=XMLUtil.getContent(fc,true); 586 String closedTag="</"+node.getNodeName()+">"; 587 if (fcnc.trim().length()>0) { 588 fcnc=fcnc.trim(); 589 } 590 591 int i1,i2; 592 i1=txt.indexOf(fcnc); 593 i2=txt.lastIndexOf(closedTag); 594 txt=txt.substring(i1,i2).trim(); 595 } catch (Exception ex) { 596 NodeList nl=node.getChildNodes(); 597 txt=""; 598 try { 599 for (int i=0; i<nl.getLength(); i++) { 600 Node sn=nl.item(i); 601 if (sn instanceof Element) { 602 txt+=XMLUtil.getContent(sn,true); 603 } else { 604 String nv=sn.getNodeValue(); 605 if (i>0) { 607 txt+=nv.substring(1); 608 } else if (i==0 && nv.trim().length()==0) { 609 continue; 610 } else { 611 txt+=nv; 612 } 613 } 614 } 615 } catch (Exception ex2){} 616 } 617 } 618 } 619 return txt; 620 } 621 622 630 public static boolean isANDTypeSplitOrJoin (Activity act,int sOrJ) { 631 String splitOrJoin="Split"; 632 if (sOrJ!=0) { 633 splitOrJoin="Join"; 634 } 635 String sjType = "XOR"; Collection transitionRestrictions = 639 ((TransitionRestrictions)act.get("TransitionRestrictions")).toCollection(); 640 Iterator iter = transitionRestrictions.iterator(); 641 while(iter.hasNext()){ 642 TransitionRestriction restriction=(TransitionRestriction)iter.next(); 643 XMLComplexElement sj=(XMLComplexElement)restriction.get(splitOrJoin); 644 if(sj==null){ 645 continue; 647 } 648 sjType = sj.get("Type").toValue().toString(); 649 } 650 651 if (sjType.equals("AND")) { 652 return true; 653 } else { 654 return false; 655 } 656 } 657 658 665 public static Set getSplitOrJoinActivities (Collection acts,int sOrJ) { 666 Set sOrJactivities=new HashSet(); 667 if (acts==null) return sOrJactivities; 668 Transitions ts=null; 669 Iterator it=acts.iterator(); 670 while (it.hasNext()) { 671 Activity act=(Activity)it.next(); 672 if (ts==null) { 673 ts=(Transitions)act.getCollection().getOwner().get("Transitions"); 674 } 675 Iterator iter; 676 if (sOrJ==0) { 677 iter=ts.getTransitions(act.getID(),-1).iterator(); 678 } else { 679 iter=ts.getTransitions(act.getID(),1).iterator(); 680 } 681 int noOfTrans=0; 682 while (iter.hasNext()) { 683 Transition t = (Transition)iter.next(); 684 if (t!=null && t.getFrom()!=null && t.getTo()!=null) { 685 noOfTrans++; 686 } 687 } 688 if (noOfTrans>1) { 689 sOrJactivities.add(act); 690 } 691 } 692 693 return sOrJactivities; 694 } 695 696 703 public static Set getBlockActivities(XMLComplexElement wpOrAs,boolean recursivly) { 704 Collection allActs=((Activities)wpOrAs.get("Activities")).toCollection(); 705 Set bas=new HashSet(); 706 Iterator it=allActs.iterator(); 707 Activity act; 708 while (it.hasNext()) { 709 act=(Activity)it.next(); 710 BlockActivity ba=act.getBlockActivity(); 711 if (ba!=null) { 712 bas.add(act); 713 if (!recursivly) continue; 714 ActivitySets ass=(ActivitySets)act.getOwnerProcess().get("ActivitySets"); 715 String asId=ba.get("BlockId").toString(); 716 ActivitySet as=ass.getActivitySet(asId); 717 if (as!=null) { 718 bas.addAll(getBlockActivities(as,true)); 719 } 720 } 721 } 722 return bas; 723 } 724 725 726 732 public static int getConformanceClassNo (String conformanceClass) { 733 if (conformanceClass.equals("NON_BLOCKED")) { 734 return 0; 735 } else if (conformanceClass.equals("LOOP_BLOCKED")) { 736 return 1; 737 } else if (conformanceClass.equals("FULL_BLOCKED")) { 738 return 2; 739 } else { 740 return -1; 741 } 742 } 743 744 747 public static String fileToString (String fileName) { 748 if (fileName != null) { 749 byte[] utf8Bytes; 751 String sFile = new String (); 752 try { 754 FileInputStream fis=new FileInputStream(fileName); 755 int noOfBytes=fis.available(); 756 if (noOfBytes>0) { 757 utf8Bytes=new byte[noOfBytes]; 758 fis.read(utf8Bytes); 759 sFile=new String (utf8Bytes,"UTF8"); 760 } 761 } 762 catch (Exception ex) { 763 return null; 764 } 765 return sFile; 766 } 767 return null; 768 } 769 771 772 public static String getCurrentDateAndTime () { 773 String dateSeparator="-"; 774 String timeSeparator=":"; 775 Calendar cal=new GregorianCalendar(); 776 String dateTime=""; 777 dateTime=dateTime+String.valueOf(cal.get(Calendar.YEAR))+dateSeparator; 778 int mnth=cal.get(Calendar.MONTH)+1; 779 if (mnth<10) { 780 dateTime=dateTime+"0"; 781 } 782 dateTime=dateTime+String.valueOf(mnth)+dateSeparator; 783 int dayOfMnth=cal.get(Calendar.DAY_OF_MONTH); 784 if (dayOfMnth<10) { 785 dateTime=dateTime+"0"; 786 } 787 dateTime=dateTime+String.valueOf(dayOfMnth)+" "; 788 int hr=cal.get(Calendar.HOUR_OF_DAY); 789 int ampm=cal.get(Calendar.AM_PM); 790 if (ampm==Calendar.PM && hr<12) { 791 hr+=12; 792 } 793 if (hr<10) { 794 dateTime=dateTime+"0"; 795 } 796 dateTime=dateTime+String.valueOf(hr)+timeSeparator; 797 int min=cal.get(Calendar.MINUTE); 798 if (min<10) { 799 dateTime=dateTime+"0"; 800 } 801 dateTime=dateTime+String.valueOf(min)+timeSeparator; 802 int sec=cal.get(Calendar.SECOND); 803 if (sec<10) { 804 dateTime=dateTime+"0"; 805 } 806 dateTime=dateTime+String.valueOf(sec); 807 808 return dateTime; 809 } 810 811 817 public static int checkParameterMatching (FormalParameters fps,ActualParameters aps) { 818 if (fps==null || aps==null || fps.size()!=aps.size()) { 819 return 1; 820 } 821 822 for (int i=0; i<fps.size(); i++) { 823 FormalParameter fp=(FormalParameter)fps.get(i); 824 ActualParameter ap=(ActualParameter)aps.get(i); 825 826 String fpMode=fp.get("Mode").toValue().toString(); 827 828 if (fpMode.equals("IN")) continue; 831 832 DataType fpdt=(DataType)fp.get("DataType"); 834 XMLComplexChoice fpdtt=(XMLComplexChoice)fpdt.get("Type"); 835 XMLElement fpType=(XMLElement)fpdtt.getChoosen(); 836 837 Object apWRD=ap.toValue(); 839 XMLElement apType=null; 840 if ((apWRD instanceof DataField) || (apWRD instanceof FormalParameter)) { 841 DataType apdt=(DataType)((XMLCollectionElement)apWRD).get("DataType"); 842 XMLComplexChoice apdtt=(XMLComplexChoice)apdt.get("Type"); 843 apType=(XMLElement)apdtt.getChoosen(); 844 } 845 846 if (apType==null) { 849 return 2; 850 } 851 852 if (fpType.getClass().equals(apType.getClass())) { 853 if (fpType instanceof BasicType) { 855 XMLAttribute fpAT=(XMLAttribute)((BasicType)fpType).get("Type"); 856 XMLAttribute apAT=(XMLAttribute)((BasicType)apType).get("Type"); 857 if (!fpAT.toValue().toString().equals(apAT.toValue().toString())) { 858 return 2; 859 } 860 } 861 if (fpType instanceof EnumerationType) { 863 if (((EnumerationType)fpType).size()!=((EnumerationType)apType).size()) { 865 return 2; 866 } 867 for (int j=0; j<((EnumerationType)fpType).size(); j++) { 869 if (!((EnumerationType)fpType).get(j).toString(). 870 equals(((EnumerationType)apType).get(j).toString())) { 871 return 2; 872 } 873 } 874 } 875 if (fpType instanceof DeclaredType) { 877 if (!((DeclaredType)fpType).get("Id").toString(). 878 equals(((DeclaredType)apType).get("Id").toString())) { 879 return 2; 880 } 881 } 882 883 } else { 884 return 2; 885 } 886 } 887 return 0; 888 } 889 890 public static String replaceBackslashesWithSlashes (String repBS) { 891 if (repBS!=null) { 892 int ind=-1; 893 while ((ind=repBS.indexOf("\\"))!=-1) { 894 repBS=repBS.substring(0,ind)+"/"+repBS.substring(ind+1); 895 } 896 } 897 return repBS; 898 } 899 900 906 public static void expandAll(JTree tree, boolean expand) { 907 TreeNode root = (TreeNode)tree.getModel().getRoot(); 908 909 expandAll(tree, new TreePath(root), expand); 911 } 912 913 919 public static void expandAll(JTree tree, TreePath parent, boolean expand) { 920 try { 921 TreeNode node = ( TreeNode ) parent.getLastPathComponent(); 923 if ( node.getChildCount() >= 0 ) { 924 for ( Enumeration e = node.children(); e.hasMoreElements(); ) { 925 TreeNode n = ( TreeNode ) e.nextElement(); 926 TreePath path = parent.pathByAddingChild( n ); 927 expandAll( tree, path, expand ); 928 } 929 } 930 if ( expand ) { 932 tree.expandPath( parent ); 933 } 934 else { 935 tree.collapsePath( parent ); 936 } 937 }catch(Exception e) { 938 } 940 } 941 942 948 public static void initExpand(JTree tree, TreePath parent) { 949 try { 950 TreeNode node = ( TreeNode ) parent.getLastPathComponent(); 952 ArrayList expandedChilds = new ArrayList(); 953 if ( node.getChildCount() >= 0 ) { 954 for ( Enumeration e = node.children(); e.hasMoreElements(); ) { 955 TreeNode n = ( TreeNode ) e.nextElement(); 956 if( !((XMLElement)((DefaultMutableTreeNode)n).getUserObject()).isCollapsed()) 957 expandedChilds.add(n); 958 } 959 for(int i = 0; i < expandedChilds.size(); i++ ) { 960 TreePath path = parent.pathByAddingChild( (TreeNode)expandedChilds.get(i) ); 961 initExpand( tree, path ); 962 } 963 964 } 965 tree.expandPath( parent ); 966 }catch(Exception e) { 967 } 969 } 970 971 public static Set getStartingActivities (XMLCollectionElement procOrASDef) { 972 Activities acts=((Activities)procOrASDef.get("Activities")); 973 Set starts=new HashSet(); 974 Iterator it=acts.toCollection().iterator(); 975 Transitions ts=(Transitions)procOrASDef.get("Transitions"); 976 while (it.hasNext()) { 977 Activity act=(Activity)it.next(); 978 Set trs=act.getIncomingTransitions(); 979 if (trs.size()==0) { 981 starts.add(act); 982 } else if (trs.size()==1) { 984 Transition t=(Transition)trs.toArray()[0]; 985 if (t.getFrom()!=null && t.getFrom().equals(t.getTo())) { 986 starts.add(act); 987 } 988 } 989 } 990 return starts; 991 } 992 993 public static Set getEndingActivities (XMLCollectionElement procOrASDef) { 994 Activities acts=((Activities)procOrASDef.get("Activities")); 995 Set ends=new HashSet(); 996 Iterator it=acts.toCollection().iterator(); 997 Transitions ts=(Transitions)procOrASDef.get("Transitions"); 998 while (it.hasNext()) { 999 Activity act=(Activity)it.next(); 1000 Set trs=act.getNonExceptionalOutgoingTransitions(); 1001 if (trs.size()==0) { 1003 ends.add(act); 1004 } else if (trs.size()==1) { 1006 Transition t=(Transition)trs.toArray()[0]; 1007 if (t.getFrom()!=null && t.getFrom().equals(t.getTo())) { 1008 ends.add(act); 1009 } 1010 } 1011 } 1012 1013 return ends; 1014 } 1015 1016 public static Set getAllExtendedAttributeNames (XMLComplexElement cel) { 1017 Set extAttribNames=new HashSet(); 1018 XMLInterface xmlInterface=null; 1019 1020 if (cel instanceof Activity) { 1021 xmlInterface=((Activity)cel).getOwnerProcess().getPackage().getXMLInterface(); 1022 } else if (cel instanceof Application) { 1023 xmlInterface=((Application)cel).getPackage().getXMLInterface(); 1024 } else if (cel instanceof DataField) { 1025 xmlInterface=((DataField)cel).getPackage().getXMLInterface(); 1026 } else if (cel instanceof ExternalPackage) { 1027 xmlInterface=((ExternalPackage)cel).getMyPackage().getXMLInterface(); 1028 } else if (cel instanceof Package ) { 1029 xmlInterface=((Package )cel).getXMLInterface(); 1030 } else if (cel instanceof Participant) { 1031 xmlInterface=((Participant)cel).getPackage().getXMLInterface(); 1032 } else if (cel instanceof Tool) { 1033 xmlInterface=((Tool)cel).getPackage().getXMLInterface(); 1034 } else if (cel instanceof Transition) { 1035 xmlInterface=((Transition)cel).getPackage().getXMLInterface(); 1036 } else if (cel instanceof TypeDeclaration) { 1037 xmlInterface=((TypeDeclaration)cel).getPackage().getXMLInterface(); 1038 } else if (cel instanceof WorkflowProcess) { 1039 xmlInterface=((WorkflowProcess)cel).getPackage().getXMLInterface(); 1040 } 1041 1042 if (xmlInterface!=null) { 1043 Iterator it=xmlInterface.getAllPackages().iterator(); 1044 while (it.hasNext()) { 1045 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames((Package )it.next(),cel)); 1046 } 1047 } 1048 return extAttribNames; 1049 } 1050 1051 private static Set getAllExtendedAttributeNames (Package pkg,XMLComplexElement cel) { 1052 Set extAttribNames=new HashSet(); 1053 if (cel instanceof Activity) { 1054 Iterator it=((WorkflowProcesses)pkg.get("WorkflowProcesses")).toCollection().iterator(); 1055 while (it.hasNext()) { 1056 WorkflowProcess wp=(WorkflowProcess)it.next(); 1057 Activities acts=(Activities)wp.get("Activities"); 1058 Iterator acti=acts.toCollection().iterator(); 1059 while (acti.hasNext()) { 1060 Activity act=(Activity)acti.next(); 1061 Collection extAttribs=((ExtendedAttributes)act.get("ExtendedAttributes")).toCollection(); 1062 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1063 } 1064 Iterator asets=((ActivitySets)wp.get("ActivitySets")).toCollection().iterator(); 1065 while (asets.hasNext()) { 1066 ActivitySet as=(ActivitySet)asets.next(); 1067 acts=(Activities)as.get("Activities"); 1068 acti=acts.toCollection().iterator(); 1069 while (acti.hasNext()) { 1070 Activity act=(Activity)acti.next(); 1071 Collection extAttribs=((ExtendedAttributes)act.get("ExtendedAttributes")).toCollection(); 1072 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1073 } 1074 } 1075 } 1076 } else if (cel instanceof Application) { 1077 Applications aps=(Applications)pkg.get("Applications"); 1078 Iterator api=aps.toCollection().iterator(); 1079 while (api.hasNext()) { 1080 Application ap=(Application)api.next(); 1081 Collection extAttribs=((ExtendedAttributes)ap.get("ExtendedAttributes")).toCollection(); 1082 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1083 } 1084 Iterator it=((WorkflowProcesses)pkg.get("WorkflowProcesses")).toCollection().iterator(); 1085 while (it.hasNext()) { 1086 WorkflowProcess wp=(WorkflowProcess)it.next(); 1087 aps=(Applications)wp.get("Applications"); 1088 api=aps.toCollection().iterator(); 1089 while (api.hasNext()) { 1090 Application ap=(Application)api.next(); 1091 Collection extAttribs=((ExtendedAttributes)ap.get("ExtendedAttributes")).toCollection(); 1092 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1093 } 1094 } 1095 } else if (cel instanceof DataField) { 1096 DataFields dfs=(DataFields)pkg.get("DataFields"); 1097 Iterator dfi=dfs.toCollection().iterator(); 1098 while (dfi.hasNext()) { 1099 DataField df=(DataField)dfi.next(); 1100 Collection extAttribs=((ExtendedAttributes)df.get("ExtendedAttributes")).toCollection(); 1101 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1102 } 1103 Iterator it=((WorkflowProcesses)pkg.get("WorkflowProcesses")).toCollection().iterator(); 1104 while (it.hasNext()) { 1105 WorkflowProcess wp=(WorkflowProcess)it.next(); 1106 dfs=(DataFields)wp.get("DataFields"); 1107 dfi=dfs.toCollection().iterator(); 1108 while (dfi.hasNext()) { 1109 DataField df=(DataField)dfi.next(); 1110 Collection extAttribs=((ExtendedAttributes)df.get("ExtendedAttributes")).toCollection(); 1111 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1112 } 1113 } 1114 } else if (cel instanceof ExternalPackage) { 1115 ExternalPackages eps=(ExternalPackages)pkg.get("ExternalPackages"); 1116 Iterator it=eps.toCollection().iterator(); 1117 while (it.hasNext()) { 1118 ExternalPackage ep=(ExternalPackage)it.next(); 1119 Collection extAttribs=((ExtendedAttributes)ep.get("ExtendedAttributes")).toCollection(); 1120 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1121 } 1122 } else if (cel instanceof Package ) { 1123 Collection extAttribs=((ExtendedAttributes)pkg.get("ExtendedAttributes")).toCollection(); 1124 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1125 } else if (cel instanceof Participant) { 1126 Participants ps=(Participants)pkg.get("Participants"); 1127 Iterator psi=ps.toCollection().iterator(); 1128 while (psi.hasNext()) { 1129 Participant p=(Participant)psi.next(); 1130 Collection extAttribs=((ExtendedAttributes)p.get("ExtendedAttributes")).toCollection(); 1131 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1132 } 1133 Iterator it=((WorkflowProcesses)pkg.get("WorkflowProcesses")).toCollection().iterator(); 1134 while (it.hasNext()) { 1135 WorkflowProcess wp=(WorkflowProcess)it.next(); 1136 ps=(Participants)wp.get("Participants"); 1137 psi=ps.toCollection().iterator(); 1138 while (psi.hasNext()) { 1139 Participant p=(Participant)psi.next(); 1140 Collection extAttribs=((ExtendedAttributes)p.get("ExtendedAttributes")).toCollection(); 1141 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1142 } 1143 } 1144 } else if (cel instanceof Tool) { 1145 Iterator it=((WorkflowProcesses)pkg.get("WorkflowProcesses")).toCollection().iterator(); 1146 while (it.hasNext()) { 1147 WorkflowProcess wp=(WorkflowProcess)it.next(); 1148 Activities acts=(Activities)wp.get("Activities"); 1149 Iterator acti=acts.toCollection().iterator(); 1150 while (acti.hasNext()) { 1151 Activity act=(Activity)acti.next(); 1152 Tools ts=act.getTools(); 1153 if (ts!=null) { 1154 Iterator ti=ts.toCollection().iterator(); 1155 while (ti.hasNext()) { 1156 Tool t=(Tool)ti.next(); 1157 Collection extAttribs=((ExtendedAttributes)t.get("ExtendedAttributes")).toCollection(); 1158 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1159 } 1160 } 1161 } 1162 Iterator asets=((ActivitySets)wp.get("ActivitySets")).toCollection().iterator(); 1163 while (asets.hasNext()) { 1164 ActivitySet as=(ActivitySet)asets.next(); 1165 acts=(Activities)as.get("Activities"); 1166 acti=acts.toCollection().iterator(); 1167 while (acti.hasNext()) { 1168 Activity act=(Activity)acti.next(); 1169 Tools ts=act.getTools(); 1170 if (ts!=null) { 1171 Iterator ti=ts.toCollection().iterator(); 1172 while (ti.hasNext()) { 1173 Tool t=(Tool)ti.next(); 1174 Collection extAttribs=((ExtendedAttributes)t.get("ExtendedAttributes")).toCollection(); 1175 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1176 } 1177 } 1178 } 1179 } 1180 } 1181 } else if (cel instanceof Transition) { 1182 Iterator it=((WorkflowProcesses)pkg.get("WorkflowProcesses")).toCollection().iterator(); 1183 while (it.hasNext()) { 1184 WorkflowProcess wp=(WorkflowProcess)it.next(); 1185 Transitions ts=(Transitions)wp.get("Transitions"); 1186 Iterator tsi=ts.toCollection().iterator(); 1187 while (tsi.hasNext()) { 1188 Transition t=(Transition)tsi.next(); 1189 Collection extAttribs=((ExtendedAttributes)t.get("ExtendedAttributes")).toCollection(); 1190 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1191 } 1192 Iterator asets=((ActivitySets)wp.get("ActivitySets")).toCollection().iterator(); 1193 while (asets.hasNext()) { 1194 ActivitySet as=(ActivitySet)asets.next(); 1195 ts=(Transitions)as.get("Transitions"); 1196 tsi=ts.toCollection().iterator(); 1197 while (tsi.hasNext()) { 1198 Transition t=(Transition)tsi.next(); 1199 Collection extAttribs=((ExtendedAttributes)t.get("ExtendedAttributes")).toCollection(); 1200 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1201 } 1202 } 1203 } 1204 } else if (cel instanceof TypeDeclaration) { 1205 Iterator tds=((TypeDeclarations)pkg.get("TypeDeclarations")).toCollection().iterator(); 1206 while (tds.hasNext()) { 1207 TypeDeclaration td=(TypeDeclaration)tds.next(); 1208 Collection extAttribs=((ExtendedAttributes)td.get("ExtendedAttributes")).toCollection(); 1209 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1210 } 1211 } else if (cel instanceof WorkflowProcess) { 1212 Iterator it=((WorkflowProcesses)pkg.get("WorkflowProcesses")).toCollection().iterator(); 1213 while (it.hasNext()) { 1214 WorkflowProcess wp=(WorkflowProcess)it.next(); 1215 Collection extAttribs=((ExtendedAttributes)wp.get("ExtendedAttributes")).toCollection(); 1216 extAttribNames.addAll(XMLUtil.getAllExtendedAttributeNames(extAttribs)); 1217 } 1218 } 1219 return extAttribNames; 1220 } 1221 1222 private static Set getAllExtendedAttributeNames (Collection extAttribs) { 1223 Set eaNames=new HashSet(); 1224 Iterator it=extAttribs.iterator(); 1225 while (it.hasNext()) { 1226 ExtendedAttribute ea=(ExtendedAttribute)it.next(); 1227 eaNames.add(ea.get("Name").toString()); 1228 } 1229 return eaNames; 1230 } 1231 1232 public static String makeEmptyHTMLText (int length) { 1233 if (length<0) return null; 1234 String es=""; 1235 for (int i=0; i<length; i++) { 1236 es+=" "; 1237 } 1238 return es; 1239 } 1240 1241 1288} 1289 1290 | Popular Tags |