Schcmp{ traversal printClass(DisplayVisitor dV) { to *; } traversal toClassDef(ClistVisitor cV) { to ClassDef; } traversal toClassnames(ClassNameVisitor cV) { to Classname; } traversal toAttrDef(AlistVisitor aV) { to AttrDef; } traversal toAttrnames(AttrNameVisitor aV) { to Attrname; } traversal toSyntaxDef(SlistVisitor sV) { to SyntaxDef; } traversal toSyntaxnames(SyntaxNameVisitor sV) { to Syntaxname; } traversal toall(IsDiffVisitor) { to *;} void print_temp() (@ PrintWriter w = new PrintWriter(System.out, true); this.printClass(new DisplayVisitor(w)); w.flush(); @) void compare(Schcmp b,String A,String B) (@ ClistVisitor cVA = new ClistVisitor(); ClistVisitor cVB = new ClistVisitor(); this.toClassDef(cVA); b.toClassDef(cVB); ClassDef_List classlistA = cVA.get_clist(); ClassDef_List classlistB = cVB.get_clist(); System.out.print("\nThe class definitions: "); System.out.println("\n"); ClassNameVisitor cNVA = new ClassNameVisitor(classlistB,false,true); System.out.println("\nThe classes unique to "+A+":"); this.toClassnames(cNVA); if(cNVA.get_same()) System.out.println("\tNo Differences"); ClassNameVisitor cNVB = new ClassNameVisitor(classlistA,false,true); System.out.println("\nThe classes unique to "+B+":"); b.toClassnames(cNVB); if(cNVB.get_same()) System.out.println("\tNo Differences"); //Compare list of Attributes System.out.print("\nThe attributes definitions: "); this.attrcompare(b,A,B); //Compare list of Syntax System.out.print("\nThe Syntax definitions: "); this.syntaxcompare(b,A,B); //Class Definition Differences IsDiffVisitor idvA=new IsDiffVisitor(classlistB,false,false,false,new ClassDef_List(null)); IsDiffVisitor idvB=new IsDiffVisitor(classlistA,false,false,false,new ClassDef_List(null)); System.out.println("\nDefinition Differences for "+A); this.toall(idvA); if(idvA.get_clistdflag()){ } else System.out.println("\tNo Differences"); System.out.println("\nDefinition Differences for "+B); b.toall(idvB); if(idvB.get_clistdflag()){ } else System.out.println("\tNo Differences"); @) void attrcompare(Schcmp b,String A,String B) (@ AlistVisitor aVA = new AlistVisitor(); AlistVisitor aVB = new AlistVisitor(); this.toAttrDef(aVA); b.toAttrDef(aVB); AttrDef_List attrlistA = aVA.get_alist(); AttrDef_List attrlistB = aVB.get_alist(); System.out.println("\n"); AttrNameVisitor aNVA = new AttrNameVisitor(attrlistB,false,true); System.out.println("\nThe attributes unique to "+A+" : \n"); this.toAttrnames(aNVA); if(aNVA.get_same()) System.out.println("\tNo Differences"); AttrNameVisitor aNVB = new AttrNameVisitor(attrlistA,false,true); System.out.println("\nThe attributes unique to "+B+" : \n"); b.toAttrnames(aNVB); if(aNVB.get_same()) System.out.println("\tNo Differences"); @) void syntaxcompare(Schcmp b,String A,String B) (@ SlistVisitor sVA = new SlistVisitor(); SlistVisitor sVB = new SlistVisitor(); this.toSyntaxDef(sVA); b.toSyntaxDef(sVB); SyntaxDef_List SyntaxlistA = sVA.get_slist(); SyntaxDef_List SyntaxlistB = sVB.get_slist(); System.out.println("\n"); SyntaxNameVisitor sNVA = new SyntaxNameVisitor(SyntaxlistB,false,true); System.out.println("\nThe syntax unique to "+A+" : \n"); this.toSyntaxnames(sNVA); if(sNVA.get_same()) System.out.println("\tNo Differences"); SyntaxNameVisitor sNVB = new SyntaxNameVisitor(SyntaxlistA,false,true); System.out.println("\nThe syntax unique to "+B+" : \n"); b.toSyntaxnames(sNVB); if(sNVB.get_same()) System.out.println("\tNo Differences"); @) } ClistVisitor{ init (@ clist=new ClassDef_List(null); @) before ClassDef (@ if(clist.isEmpty()) clist.push(host); else clist.addElement(host); @) } ClassNameVisitor{ init (@ inlist=false; same=true; @) before Classname (@ java.util.Enumeration cl=classlist.elements(); while(cl.hasMoreElements()){ ClassDef classdef= (ClassDef) cl.nextElement(); if(classdef.get_classname().get_s().equals(host.get_s())){ inlist=true; } } if(!inlist){ System.out.println("\t"+host.get_s()); same=false; } @) after ClassDef (@ inlist=false; @) } AlistVisitor { init (@ alist=new AttrDef_List(null); @) before AttrDef (@ if(alist.isEmpty()) alist.push(host); else alist.addElement(host); @) } AttrNameVisitor{ init (@ inlist=false; same=true; @) before Attrname (@ java.util.Enumeration al=attrlist.elements(); while(al.hasMoreElements()) { AttrDef attrdef= (AttrDef) al.nextElement(); if(attrdef.get_attrname().get_s().equals(host.get_s())) { inlist=true; } } if(!inlist) { System.out.println("\t"+host.get_s()); same=false; } @) after AttrDef (@ inlist=false; @) } SlistVisitor { init (@ slist=new SyntaxDef_List(null); @) before SyntaxDef (@ if(slist.isEmpty()) slist.push(host); else slist.addElement(host); @) } SyntaxNameVisitor{ init (@ inlist=false; same=true; @) before Syntaxname (@ java.util.Enumeration sl=Syntaxlist.elements(); while(sl.hasMoreElements()){ SyntaxDef Syntaxdef= (SyntaxDef) sl.nextElement(); if(Syntaxdef.get_Syntaxname().get_s().equals(host.get_s())){ inlist=true; } } if(!inlist){ System.out.println("\t"+host.get_s()); same=false; } @) after SyntaxDef (@ inlist=false; @) } IsDiffVisitor{ init(@ clistdflag = false; dflag = false; inlist = false; ClassDef_List newClist=new ClassDef_List(null); //store diff list @) (@ protected boolean printObjectname = false; protected boolean printClassname = false; protected ClassDef cCD=new ClassDef(); //comparison ClassDef @) before ClassDef (@ java.util.Enumeration en=classlist.elements(); while(en.hasMoreElements()&&(!inlist)){ ClassDef classdef= (ClassDef) en.nextElement(); if(classdef.get_classname().get_s().equals(host.get_classname().get_s())){ inlist=true; cCD=classdef; } } @) before Flags (@ if(inlist){ java.util.Enumeration en=cCD.get_flist().elements(); while(en.hasMoreElements()){ Flags flag= (Flags) en.nextElement(); if(flag.get_s().equals(host.get_s())){ dflag=true; } } if(!dflag){ if(!printClassname){ System.out.println(cCD.get_classname().get_s()); printClassname=true; } if(!printObjectname){ System.out.println(" Flags"); printObjectname=true; } System.out.println(" "+host.get_s()); } } @) after Flags (@ dflag=false; @) after Flags_List(@ printObjectname=false; @) before SuperClasses (@ if(inlist){ java.util.Enumeration en=cCD.get_sclass().elements(); while(en.hasMoreElements()){ SuperClasses superclass= (SuperClasses) en.nextElement(); if(superclass.get_s().equals(host.get_s())){ dflag=true; } } if(!dflag){ if(!printClassname){ System.out.println(cCD.get_classname().get_s()); printClassname=true; } if(!printObjectname){ System.out.println(" SuperClasses"); printObjectname=true; } System.out.println(" "+host.get_s()); } } @) after SuperClasses(@ dflag=false; @) after SuperClasses_List(@ printObjectname=false; @) before Containment (@ if(inlist){ java.util.Enumeration en=cCD.get_clist().elements(); while(en.hasMoreElements()){ Containment c= (Containment) en.nextElement(); if(c.get_s().equals(host.get_s())){ dflag=true; } } if(!dflag){ if(!printClassname){ System.out.println(cCD.get_classname().get_s()); printClassname=true; } if(!printObjectname){ System.out.println(" Containment"); printObjectname=true; } System.out.println(" "+host.get_s()); } } @) after Containment (@ dflag=false; @) after Containment_List (@ printObjectname=false; @) before NamedBy (@ if(inlist){ java.util.Enumeration en=cCD.get_nlist().elements(); while(en.hasMoreElements()){ NamedBy n= (NamedBy) en.nextElement(); if(n.get_s().equals(host.get_s())){ dflag=true; } } if(!dflag){ if(!printClassname){ System.out.println(cCD.get_classname().get_s()); printClassname=true; } if(!printObjectname){ System.out.println(" NamedBy"); printObjectname=true; } System.out.println(" "+host.get_s()); } } @) after NamedBy (@ dflag=false; @) after NamedBy_List (@ printObjectname=false; @) before Mandatory (@ if(inlist){ java.util.Enumeration en=cCD.get_mlist().elements(); while(en.hasMoreElements()){ Mandatory m= (Mandatory) en.nextElement(); if(m.get_s().equals(host.get_s())){ dflag=true; } } if(!dflag){ if(!printClassname){ System.out.println(cCD.get_classname().get_s()); printClassname=true; } if(!printObjectname){ System.out.println(" Mandatory Attributes"); printObjectname=true; } System.out.println(" "+host.get_s()); } } @) after Mandatory (@ dflag=false; @) after Mandatory_List (@ printObjectname=false; @) before Opt (@ if(inlist){ java.util.Enumeration en=cCD.get_olist().elements(); while(en.hasMoreElements()){ Opt o= (Opt) en.nextElement(); if(o.get_s().equals(host.get_s())){ dflag=true; } } if(!dflag){ if(!printClassname){ System.out.println(cCD.get_classname().get_s()); printClassname=true; } if(!printObjectname){ System.out.println(" Optional Attributes"); printObjectname=true; } System.out.println(" "+host.get_s()); } } @) after Opt (@ dflag=false; @) after Opt_List (@ printObjectname=false; @) after ClassDef (@ if(printClassname) clistdflag=true; inlist=false; dflag=false; printObjectname=false; printClassname=false; @) } Main { (@ public static void main(String[] argv) throws Exception { try { // Check input files File schema1 = new File(argv[0]); if (!schema1.exists()) { System.err.println("Could not find "+argv[0]); throw new FileNotFoundException(); } File schema2 = new File(argv[1]); if (!schema2.exists()) { System.err.println("Could not find "+argv[1]); throw new FileNotFoundException(); } Schcmp schemaA = Schcmp.parse(new FileInputStream(schema1)); Schcmp schemaB = Schcmp.parse(new FileInputStream(schema2)); //printout the Schema of both A and B schemaA.compare(schemaB,argv[0],argv[1]); } catch (ParseError e) { System.err.println("Failed to parse file."); e.printStackTrace(); System.exit(1); } catch (FileNotFoundException e) { System.err.println("\nPlease check and see if the file name exists. "); System.exit(1); } } @) }