1 9 10 package org.netbeans.modules.xml.wsdl.validator.visitor.schema; 11 12 import java.util.ArrayList ; 13 import java.util.Collection ; 14 import java.util.Iterator ; 15 import java.util.List ; 16 import org.netbeans.modules.xml.schema.model.Import; 17 import org.netbeans.modules.xml.schema.model.Schema; 18 import org.netbeans.modules.xml.schema.model.SchemaComponent; 19 import org.netbeans.modules.xml.schema.model.SchemaModel; 20 import org.netbeans.modules.xml.schema.model.visitor.DefaultSchemaVisitor; 21 import org.netbeans.modules.xml.wsdl.model.Definitions; 22 import org.netbeans.modules.xml.wsdl.model.Types; 23 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 24 import org.netbeans.modules.xml.wsdl.model.extensions.xsd.WSDLSchema; 25 import org.netbeans.modules.xml.xam.Component; 26 import org.netbeans.modules.xml.xam.Model; 27 import org.netbeans.modules.xml.xam.spi.Validation; 28 import org.netbeans.modules.xml.xam.spi.Validation.ValidationType; 29 import org.netbeans.modules.xml.xam.spi.Validator; 30 import org.netbeans.modules.xml.xam.spi.Validator.ResultItem; 31 import org.openide.util.NbBundle; 32 33 37 public class SchemaSemanticsVisitor extends DefaultSchemaVisitor { 38 39 40 public static final String VAL_MISSING_IMPORTED_DOCUMENT = "VAL_MISSING_IMPORTED_DOCUMENT"; 41 public static final String FIX_MISSING_IMPORTED_DOCUMENT = "FIX_MISSING_IMPORTED_DOCUMENT"; 42 43 44 45 public List <ResultItem> mResultItems = new ArrayList <ResultItem>(); 46 private WSDLModel mParentModel; 47 private Validator mValidator; 48 private Validation mValidation; 49 private List <Model> mValidatedModels; 50 51 52 public SchemaSemanticsVisitor(WSDLModel parentModel, 53 Validator validator, 54 Validation validation, 55 List <Model> validatedModels) { 56 mParentModel = parentModel; 57 mValidation = validation; 58 mValidatedModels = validatedModels; 59 } 60 61 public List <ResultItem> getResultItems() { 62 return mResultItems; 63 } 64 65 public void visit(Schema s) { 66 if(s != null) { 67 visitChildren(s); 68 } 69 } 70 71 public void visit(Import im) { 72 73 Collection <Schema> schemas = im.getModel().findSchemas(im.getNamespace()); 75 76 if(schemas == null || schemas.isEmpty()) { 77 WSDLSchema schema = findInlineSchema(im.getNamespace()); 79 if(schema == null) { 80 logValidation 81 (Validator.ResultType.ERROR, im, 82 NbBundle.getMessage(SchemaSemanticsVisitor.class, 83 VAL_MISSING_IMPORTED_DOCUMENT, 84 im.getNamespace(), 85 im.getSchemaLocation()), 86 NbBundle.getMessage(SchemaSemanticsVisitor.class, FIX_MISSING_IMPORTED_DOCUMENT) 87 ); 88 } 89 90 } 91 92 } 96 97 private void visitChildren(SchemaComponent w) { 98 Collection coll = w.getChildren(); 99 if (coll != null) { 100 Iterator iter = coll.iterator(); 101 while (iter.hasNext()) { 102 SchemaComponent component = (SchemaComponent) iter.next(); 103 component.accept(this); 104 } 105 } 106 } 107 108 private void logValidation(Validator.ResultType type, 109 Component component, 110 String desc, 111 String correction) { 112 String message = desc; 113 if (correction != null) { 114 message = desc + " : " + correction; 115 } 116 ResultItem item = new Validator.ResultItem(mValidator, type, component, message); 117 mResultItems.add(item); 118 119 } 120 121 private WSDLSchema findInlineSchema(String namespace) { 122 if(namespace == null) { 123 return null; 124 } 125 126 WSDLSchema matchingSchema = null; 127 128 Definitions def = mParentModel.getDefinitions(); 129 if(def != null) { 130 Types types = def.getTypes(); 131 if(types != null) { 132 Collection <WSDLSchema> schemas = types.getExtensibilityElements(WSDLSchema.class); 133 if(schemas != null) { 134 Iterator <WSDLSchema> sIt = schemas.iterator(); 135 while(sIt.hasNext()) { 136 WSDLSchema wSchema = sIt.next(); 137 SchemaModel sModel = wSchema.getSchemaModel(); 138 if(sModel != null && sModel.getSchema() != null) { 139 String targetNamespace = sModel.getSchema().getTargetNamespace(); 140 if(namespace.equals(targetNamespace)) { 141 matchingSchema = wSchema; 142 break; 143 } 144 } 145 } 146 } 147 } 148 } 149 150 return matchingSchema; 151 } 152 } 153 | Popular Tags |