1 19 package org.netbeans.modules.xml.axi.visitor; 20 21 import java.util.Stack ; 22 import org.netbeans.modules.xml.axi.AXIComponent; 23 import org.netbeans.modules.xml.axi.AXIComponent.ComponentType; 24 import org.netbeans.modules.xml.axi.AXIDocument; 25 import org.netbeans.modules.xml.axi.AnyAttribute; 26 import org.netbeans.modules.xml.axi.AnyElement; 27 import org.netbeans.modules.xml.axi.Attribute; 28 import org.netbeans.modules.xml.axi.Compositor; 29 import org.netbeans.modules.xml.axi.Element; 30 import org.netbeans.modules.xml.axi.ContentModel; 31 import org.netbeans.modules.xml.axi.impl.ElementRef; 32 33 37 public class DeepAXITreeVisitor extends DefaultVisitor { 38 39 Stack <AXIComponent> pathToRoot = new Stack <AXIComponent>(); 40 41 44 public DeepAXITreeVisitor() { 45 super(); 46 } 47 48 public void visit(AXIDocument root) { 49 visitChildren(root); 50 } 51 52 public void visit(Element element) { 53 visitChildren(element); 54 } 55 56 public void visit(AnyElement element) { 57 visitChildren(element); 58 } 59 60 public void visit(Attribute attribute) { 61 visitChildren(attribute); 62 } 63 64 public void visit(AnyAttribute attribute) { 65 visitChildren(attribute); 66 } 67 68 public void visit(Compositor compositor) { 69 visitChildren(compositor); 70 } 71 72 public void visit(ContentModel element) { 73 visitChildren(element); 74 } 75 76 protected void visitChildren(AXIComponent component) { 77 if( !canVisit(component) ) 78 return; 79 80 pathToRoot.push(component.getOriginal()); 81 for(AXIComponent child: component.getChildren()) { 82 child.accept(this); 83 } 84 pathToRoot.pop(); 85 } 86 87 private boolean canVisit(AXIComponent component) { 88 if(pathToRoot.contains(component)) 89 return false; 90 91 if(component.getComponentType() == ComponentType.PROXY) 92 return canVisit(component.getOriginal()); 93 94 if(component.getComponentType() == ComponentType.REFERENCE && 95 component instanceof ElementRef) { 96 ElementRef ref = (ElementRef)component; 97 Element e = ref.getReferent(); 98 if(pathToRoot.contains(e)) 99 return false; 100 } 101 102 return true; 103 } 104 105 } 106 | Popular Tags |