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;} void print_temp() (@ PrintWriter w = new PrintWriter(System.out, true); this.printClass(new DisplayVisitor(w)); w.flush(); @) void compare(Schcmp 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.println("\n"); ClassNameVisitor cNVA = new ClassNameVisitor(classlistB,false,true); // System.out.println("\nThe classes unique to SchemaA:\n "); 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 SchemaB:\n "); // b.toClassnames(cNVB); // if(cNVB.get_same()) // System.out.println("\tNONE"); @) void attrcompare(Schcmp 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 SchemaA:\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 SchemaB: \n"); // b.toAttrnames(aNVB); // if(aNVB.get_same()) // System.out.println("\tNONE"); @) void syntaxcompare(Schcmp 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 attributes unique to SchemaA:\n "); this.toSyntaxnames(sNVA); if(sNVA.get_same()) System.out.println("\tNo Differences"); // AttrNameVisitor aNVB = new AttrNameVisitor(attrlistA,false,true); // // System.out.println("\nThe attributes unique to SchemaB: \n"); // b.toAttrnames(aNVB); // if(aNVB.get_same()) // System.out.println("\tNONE"); @) } ClistVisitor{ init (@ clist=new ClassDef_List(null); @) before ClassDef (@ if(clist.isEmpty()) clist.push(host); else clist.addElement(host); //System.out.println("The classname is "+ host.get_classname().get_s_classname()); @) } ClassNameVisitor{ init (@ inlist=false; same=true; @) before Classname (@ java.util.Enumeration cl=classlist.elements(); while(cl.hasMoreElements()){ ClassDef classdef= (ClassDef) cl.nextElement(); //System.out.println("ClassDef List B: "+ classdef.get_classname().get_s_classname()); //System.out.println("Host :"+ host.get_s_classname()); if(classdef.get_classname().get_s_classname().equals(host.get_s_classname())){ inlist=true; } } if(!inlist){ System.out.println("\t"+host.get_s_classname()); 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); //System.out.println("The attrname is "+ host.get_attrname().get_s_attrname()); @) } AttrNameVisitor{ init (@ inlist=false; same=true; @) before Attrname (@ java.util.Enumeration al=attrlist.elements(); while(al.hasMoreElements()) { AttrDef attrdef= (AttrDef) al.nextElement(); //System.out.println("AttrDef List B: "+ attrdef.get_attrname().get_s_attrname()); //System.out.println("Host :"+ host.get_s_attrname()); if(attrdef.get_attrname().get_s_attrname().equals(host.get_s_attrname())) { inlist=true; } } if(!inlist) { System.out.println("\t"+host.get_s_attrname()); 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); //System.out.println("The attrname is "+ host.get_attrname().get_s_attrname()); @) } SyntaxNameVisitor{ init (@ inlist=false; same=true; @) before Syntaxname (@ java.util.Enumeration sl=Syntaxlist.elements(); while(sl.hasMoreElements()) { SyntaxDef Syntaxdef= (SyntaxDef) sl.nextElement(); //System.out.println("AttrDef List B: "+ attrdef.get_attrname().get_s_attrname()); //System.out.println("Host :"+ host.get_s_attrname()); if(Syntaxdef.get_Syntaxname().get_s_Syntaxname().equals(host.get_s_Syntaxname())) { inlist=true; } } if(!inlist) { System.out.println("\t"+host.get_s_Syntaxname()); same=false; } @) after SyntaxDef (@ inlist=false; @) } //(@ //void static PrintHelp() //{ // System.err.println("##############################################################################"); // System.err.println(" SCHCMP General Usage Help 1.0"); // System.err.println("##############################################################################"); // System.err.println(" Purpose: Compares the schema of two servers. "); // System.err.println(" "); // System.err.println(" Syntax: SCHCMP [/C | /A | /S] "); // System.err.println("##############################################################################"); // System.err.println(" Description: "); // System.err.println(" Displays the schema of or compares with and "); // System.err.println(" displays their differences. and may be a server name,"); // System.err.println(" a schema reference file(.ref), or a server list file(.lst). "); // System.err.println(" "); // System.err.println(" Options: "); // System.err.println(" NO options List or compare class, attribute and syntax definitions "); // System.err.println(" /C List or compare class definitions only. "); // System.err.println(" /A List or compare attribute definitions. "); // System.err.println(" /S List or compare syntax definitions. "); // System.err.println("##############################################################################"); // System.err.println(" Examples: "); // System.err.println(" SCHCMP serverA /C /A "); // System.err.println(" SCHCMP serverA serverB /S "); // System.err.println(" SCHCMP 411.ref serverB "); // System.err.println(" SCHCMP serverB servers.lst "); // System.err.println("##############################################################################"; //} // @) Main { (@ public static void main(String[] argv) throws Exception { try { // Check arg list //if (argv.length != 2 ) schcmp.PrintHelp(); // 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.print_temp(); //schemaB.print_temp(); System.out.print("\nThe classes unique to "+argv[0]+":"); schemaA.compare(schemaB); System.out.print("\nThe classes unique to "+argv[1]+":"); schemaB.compare(schemaA); System.out.print("\nThe attributes unique to "+argv[0]+":"); schemaA.attrcompare(schemaB); System.out.print("\nThe attributes unique to "+argv[1]+":"); schemaB.attrcompare(schemaA); System.out.print("\nThe Syntax unique to "+argv[0]+":"); schemaA.syntaxcompare(schemaB); System.out.print("\nThe Syntax unique to "+argv[1]+":"); schemaB.syntaxcompare(schemaA); } 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); } } @) }