Main { {{ static ClassGraph cg ; public static void main(String args[]) throws Exception { Schema s = Schema.parse(System.in); cg = new ClassGraph(true, false); ClassGraph cg2 = new ClassGraph(cg, "from Schema bypassing -> *,tail,* to *"); cg2.traverse(s,"from Schema to TypeDef", new Visitor() { void before(TypeDef host){ System.out.println(" TypeDef found "); } }); TraversalGraph tg1 = new TraversalGraph( "from Schema to Attribute", cg2); System.out.println(" TraversalGraph from Schema to Attribute "); System.out.println(tg1); System.out.println("========"); tg1 = new TraversalGraph( "from Attribute to AttrValue", cg2); System.out.println(" TraversalGraph from Attribute to AttrValue "); // question to Doug: why is SchemaItem in the traversal graph? // there is no edge to it. System.out.println(tg1); System.out.println("========"); tg1 = new TraversalGraph( "from Schema to ComplexType", cg2); System.out.println(" TraversalGraph from Schema to ComplexType "); System.out.println(tg1); System.out.println("========"); tg1 = new TraversalGraph( "from Schema to Element", cg2); System.out.println(" TraversalGraph from Schema to Element "); System.out.println(tg1); System.out.println("========"); tg1 = new TraversalGraph( "from Schema to TypeDef", cg2); System.out.println(" TraversalGraph from Schema to TypeDef "); System.out.println(tg1); System.out.println("========"); System.out.println(" Eliminate attributes from elements "); cg2.traverse(s,"from Schema to Element", new Visitor() { void before(Element host){ System.out.println(" Element found "); host.set_attrs(new AttrValue_List()); } }); System.out.println("========"); System.out.println(" Eliminate name space refs from complex types "); cg2.traverse(s,"from Schema to ComplexType", new Visitor() { void before(ComplexType host){ System.out.println(" ComplexType found "); host.set_prefixS(null); } }); s.printSchema(); s.displaySchema(); HashSet r = s.getDefThings(cg2); System.out.println("done"); } }} } Schema { void printSchema() bypassing -> *,tail,* to * (PrintVisitor); void displaySchema() bypassing -> *,tail,* to * (DisplayVisitor); {{ HashSet getDefThings(ClassGraph cg){ String definedThings = "from Schema to ComplexType"; Visitor v = new Visitor(){ HashSet r = new HashSet(); void before(ComplexType host){ String n = host.get_attrs().search_name(); if (!(n == null)) r.add(n); } public Object getReturnValue(){return r;} }; cg.traverse(this,definedThings,v); return (HashSet) v.getReturnValue(); } }} } AttrValue_List { {{ String search_name(){ Enumeration en = this.elements(); String s = new String("name"); String result; while (en.hasMoreElements()) { AttrValue n = (AttrValue) en.nextElement(); if (s.equals(n.get_attrName().toString())) { result = n.get_attrValue(); System.out.println("Type " + result + " found"); return result; } } System.out.println("NOTHING FOUND"); return null; } }} }