1 19 package org.netbeans.modules.xml.wsdl.refactoring.xsd; 20 21 import java.util.ArrayList ; 22 import java.util.Collection ; 23 import java.util.List ; 24 import org.netbeans.modules.xml.refactoring.FindUsageResult; 25 import org.netbeans.modules.xml.refactoring.RefactoringManager; 26 import org.netbeans.modules.xml.refactoring.UsageGroup; 27 import org.netbeans.modules.xml.refactoring.UsageSet; 28 import org.netbeans.modules.xml.refactoring.spi.RefactoringEngine; 29 import org.netbeans.modules.xml.schema.model.GlobalElement; 30 import org.netbeans.modules.xml.schema.model.GlobalType; 31 import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent; 32 import org.netbeans.modules.xml.schema.model.Schema; 33 import org.netbeans.modules.xml.wsdl.model.Definitions; 34 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; 35 import org.netbeans.modules.xml.wsdl.model.Part; 36 import org.netbeans.modules.xml.wsdl.model.Types; 37 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 38 import org.netbeans.modules.xml.wsdl.model.visitor.ChildVisitor; 39 import org.netbeans.modules.xml.wsdl.model.visitor.WSDLVisitor; 40 import org.netbeans.modules.xml.xam.Component; 41 import org.netbeans.modules.xml.xam.NamedReferenceable; 42 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 43 import org.openide.ErrorManager; 44 45 49 public class FindSchemaUsageVisitor extends ChildVisitor implements WSDLVisitor { 50 private ReferenceableSchemaComponent referenced; 51 private UsageGroup usage; 52 private List <UsageGroup> usages; 53 54 55 public FindSchemaUsageVisitor() { 56 } 57 58 public List <UsageGroup> findUsages(ReferenceableSchemaComponent referenced, 59 Definitions wsdl, RefactoringEngine engine) { 60 this.referenced = referenced; 61 usage = new UsageGroup(engine, wsdl.getModel(), referenced); 62 usages = new ArrayList <UsageGroup>(); 63 wsdl.accept(this); 64 if (!usage.isEmpty()) { 65 usages.add(usage); 66 } 67 return usages; 68 } 69 70 public void visit(Types types) { 71 Collection <Schema> schemas = types.getSchemas(); 72 if (schemas == null || schemas.size() == 0) 73 return; 74 for (Schema schema : schemas) { 75 collectUsage(schema); 76 } 77 super.visit(types); 78 } 79 80 public void visit(Part part) { 81 try { 82 if (referenced instanceof GlobalElement && part.getElement() != null && 83 part.getElement().references((GlobalElement)referenced) || 84 referenced instanceof GlobalType && part.getType() != null && 85 part.getType().references((GlobalType)referenced)) 86 { 87 usage.addItem(part); 88 } 89 } catch(Exception e) { 90 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 91 usage.addError(part, e.getMessage()); 92 } 93 super.visit(part); 94 } 95 96 101 102 private void collectUsage(Component searchRoot) { 103 FindUsageResult result = RefactoringManager.getInstance().findUsages(referenced, searchRoot); 104 try { 105 UsageSet usageSet = result.get(); 106 for (UsageGroup u : usageSet.getUsages()) { 107 if (! u.isEmpty()) { 108 usages.add(u); 109 } 110 } 111 } catch(Exception e) { 112 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 113 usage.addError(searchRoot, e.getMessage()); 114 } 115 } 116 } 117 | Popular Tags |