1 19 20 package org.netbeans.modules.xml.schema.model.visitor; 21 22 import java.util.Collection ; 23 import org.netbeans.modules.xml.schema.model.Constraint; 24 import org.netbeans.modules.xml.schema.model.GlobalElement; 25 import org.netbeans.modules.xml.schema.model.LocalElement; 26 import org.netbeans.modules.xml.schema.model.SchemaComponent; 27 28 35 public class FindReferredConstraintVisitor extends DeepSchemaVisitor{ 36 37 private Constraint constraint; 38 private String name; 39 private boolean found; 40 41 44 public FindReferredConstraintVisitor() { 45 } 46 47 53 public Constraint findReferredConstraint(SchemaComponent parent, String name){ 54 this.name = name; 55 found = false; 56 parent.accept(this); 57 return constraint; 58 } 59 60 public void visit(LocalElement le) { 61 if(findConstraint(le.getConstraints())){ 62 return; 63 } 64 super.visit(le); 65 } 66 67 public void visit(GlobalElement ge) { 68 if(findConstraint(ge.getConstraints())){ 69 return; 70 } 71 super.visit(ge); 72 } 73 74 protected void visitChildren(SchemaComponent sc) { 75 for (SchemaComponent child: sc.getChildren()) { 76 child.accept(this); 77 if(found) return; 78 } 79 } 80 81 private boolean findConstraint(Collection <Constraint> constraints){ 82 for(Constraint c : constraints){ 83 if(c.getName().equals(name)){ 84 constraint = c; 85 found = true; 86 return true; 87 } 88 } 89 return false; 90 } 91 } 92 | Popular Tags |