1 19 20 package org.netbeans.modules.xml.axi.visitor; 21 22 import java.util.ArrayList ; 23 import java.util.List ; 24 import org.netbeans.modules.xml.axi.AXIComponent; 25 import org.netbeans.modules.xml.axi.AXIDocument; 26 import org.netbeans.modules.xml.axi.AXIModel; 27 import org.netbeans.modules.xml.axi.Element; 28 import org.netbeans.modules.xml.axi.impl.SchemaGeneratorUtil; 29 import org.netbeans.modules.xml.schema.model.SchemaModel; 30 31 36 public class AXINonCyclicVisitor extends DeepAXITreeVisitor { 37 38 List <AXIComponent> path = null; 39 40 private AXIModel am; 41 42 private SchemaModel sm; 43 44 47 public AXINonCyclicVisitor(AXIModel am) { 48 this.am = am; 49 this.sm = am.getSchemaModel(); 50 path = new ArrayList <AXIComponent>(); 51 } 52 53 public void expand(AXIDocument root) { 54 path.clear(); 55 if(root != null) { 56 for(AXIComponent c : root.getChildren()) { c.accept(this); 58 } 59 } 60 } 61 62 public void expand(List <Element> elements) { 65 path.clear(); 66 for(Element e : elements) { e.accept(this); 68 } 69 } 70 71 public void visit(Element e) { 72 if(!canVisit(e)) return; 74 visitChildren(e); 75 } 76 77 public boolean canVisit(Element e) { 78 Element orig = getOriginalElement(e); 79 if(!SchemaGeneratorUtil.fromSameSchemaModel(orig, sm) || 80 path.size() > 0 && path.contains(orig)) return false; 82 return true; 83 } 84 85 public void visitChildren(Element e) { 86 Element orig = getOriginalElement(e); 87 path.add(orig); 88 try { 89 super.visit(e); } finally { 91 path.remove(path.size()-1); 92 } 93 } 94 95 private Element getOriginalElement(final Element e) { 96 Element orig = e; 97 if(orig.isReference()) { 98 orig = SchemaGeneratorUtil.findOriginalElement(e); 99 } 100 return orig; 101 } 102 } 103 | Popular Tags |