1 19 20 package org.netbeans.modules.xml.schema.model.visitor; 21 22 import java.util.Collection ; 23 24 import org.netbeans.modules.xml.schema.model.*; 25 import org.netbeans.modules.xml.xam.NamedReferenceable; 26 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 27 28 32 public class FindUsageVisitor extends DeepSchemaVisitor { 33 34 37 private NamedReferenceable<SchemaComponent> globalSchemaComponent = null; 38 39 42 private PreviewImpl preview = null; 43 44 47 public Preview findUsages(Collection <Schema> roots, NamedReferenceable<SchemaComponent> component ) { 48 preview = new PreviewImpl(); 49 globalSchemaComponent = component; 50 return findUsages(roots); 51 } 52 53 56 private Preview findUsages(Collection <Schema> roots) { 57 for(Schema schema : roots) { 58 schema.accept(this); 59 } 60 61 return preview; 62 } 63 64 public void visit(Union u) { 65 if (u.getMemberTypes() != null) { 66 for (NamedComponentReference<GlobalSimpleType> t : u.getMemberTypes()) { 67 checkReference(t, u); 68 } 69 } 70 super.visit(u); 71 } 72 73 77 public void visit(SimpleTypeRestriction str) { 78 checkReference(str.getBase(), str); 79 super.visit(str); 80 } 81 82 87 public void visit(LocalElement element) { 88 checkReference((NamedComponentReference<GlobalType>)element.getType(), element); 89 super.visit(element); 90 } 91 92 97 public void visit(ElementReference element) { 98 checkReference(element.getRef(), element); 99 super.visit(element); 100 } 101 102 107 public void visit(GlobalElement element) { 108 checkReference(element.getType(), element); 109 checkReference(element.getSubstitutionGroup(), element); 110 super.visit(element); 111 } 112 113 118 public void visit(LocalAttribute attribute) { 119 checkReference(attribute.getType(), attribute); 120 super.visit(attribute); 121 } 122 123 128 public void visit(AttributeReference attribute) { 129 checkReference(attribute.getRef(), attribute); 130 super.visit(attribute); 131 } 132 133 137 public void visit(AttributeGroupReference agr) { 138 checkReference(agr.getGroup(), agr); 139 super.visit(agr); 140 } 141 142 146 public void visit(ComplexContentRestriction ccr) { 147 checkReference(ccr.getBase(), ccr); 148 super.visit(ccr); 149 } 150 151 155 public void visit(SimpleExtension extension) { 156 checkReference(extension.getBase(), extension); 157 super.visit(extension); 158 } 159 160 164 public void visit(ComplexExtension extension) { 165 checkReference(extension.getBase(), extension); 166 super.visit(extension); 167 } 168 169 173 public void visit(GroupReference gr) { 174 checkReference(gr.getRef(), gr); 175 super.visit(gr); 176 } 177 178 182 public void visit(List list) { 183 checkReference(list.getType(), list); 184 super.visit(list); 185 } 186 187 private <T extends NamedReferenceable<SchemaComponent>> void checkReference( 188 NamedComponentReference<T> ref, SchemaComponent component) { 189 if (ref == null || ! ref.getType().isAssignableFrom(globalSchemaComponent.getClass())) return; 190 if (ref.references(ref.getType().cast(globalSchemaComponent))) { 191 preview.addToUsage(component); 192 } 193 } 194 } 195 | Popular Tags |