1 19 20 package org.netbeans.modules.xml.wsdl.model.impl; 21 22 import org.netbeans.modules.xml.schema.model.SchemaModel; 23 import org.netbeans.modules.xml.schema.model.SchemaModelFactory; 24 import org.netbeans.modules.xml.wsdl.model.Import; 25 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 26 import org.netbeans.modules.xml.wsdl.model.WSDLModelFactory; 27 import org.netbeans.modules.xml.wsdl.model.spi.WSDLComponentBase; 28 import org.netbeans.modules.xml.wsdl.model.visitor.WSDLVisitor; 29 import org.netbeans.modules.xml.xam.dom.DocumentModel; 30 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 31 import org.netbeans.modules.xml.xam.ModelSource; 32 import org.openide.util.NbBundle; 33 import org.w3c.dom.Element ; 34 35 39 public class ImportImpl extends WSDLComponentBase implements Import { 40 41 42 public ImportImpl(WSDLModel model, Element e) { 43 super(model, e); 44 } 45 46 public ImportImpl(WSDLModel model) { 47 this(model, createNewElement(WSDLQNames.IMPORT.getQName(), model)); 48 } 49 50 public void accept(WSDLVisitor visitor) { 51 visitor.visit(this); 52 } 53 54 public void setNamespace(String namespaceURI) { 55 setAttribute(NAMESPACE_URI_PROPERTY, WSDLAttribute.NAMESPACE_URI, namespaceURI); 56 } 57 58 public void setLocation(String locationURI) { 59 setAttribute(LOCATION_PROPERTY, WSDLAttribute.LOCATION, locationURI); 60 } 61 62 public String getNamespace() { 63 return getAttribute(WSDLAttribute.NAMESPACE_URI); 64 } 65 66 public String getLocation() { 67 return getAttribute(WSDLAttribute.LOCATION); 68 } 69 70 public WSDLModel getImportedWSDLModel() throws CatalogModelException { 71 DocumentModel m = resolveImportedModel(); 72 if (m instanceof WSDLModel) { 73 return (WSDLModel) m; 74 } else { 75 String msg = NbBundle.getMessage(ImportImpl.class, "MSG_CANNOT_LOAD_WSDL", getLocation()); 76 throw new CatalogModelException(msg); 77 } 78 } 79 80 public WSDLModel resolveToWSDLModel() throws CatalogModelException { 81 DocumentModel m = resolveImportedModel(); 82 if (m instanceof WSDLModel) { 83 return (WSDLModel) m; 84 } else { 85 return null; 86 } 87 } 88 89 public SchemaModel resolveToSchemaModel() throws CatalogModelException { 90 DocumentModel m = resolveImportedModel(); 91 if (m instanceof SchemaModel) { 92 return (SchemaModel) m; 93 } else { 94 return null; 95 } 96 } 97 98 public DocumentModel resolveImportedModel() throws CatalogModelException { 99 ModelSource ms = resolveModel(getLocation()); 100 101 String location = getLocation().toLowerCase(); 102 if (location.endsWith(".wsdl")) { return loadAsWSDL(ms); 104 } else if (location.endsWith(".xsd")) { return loadAsSchema(ms); 106 } else { 107 DocumentModel m = loadAsWSDL(ms); 108 if (m == null) { 109 m = loadAsSchema(ms); 110 } 111 return m; 112 } 113 } 114 115 private WSDLModel loadAsWSDL(ModelSource ms) { 116 WSDLModel m = WSDLModelFactory.getDefault().getModel(ms); 117 if (m != null && m.getState() == DocumentModel.State.NOT_WELL_FORMED) { 118 return null; 119 } 120 return m; 121 } 122 123 private SchemaModel loadAsSchema(ModelSource ms) { 124 SchemaModel m = SchemaModelFactory.getDefault().getModel(ms); 125 if (m != null && m.getState() == DocumentModel.State.NOT_WELL_FORMED) { 126 return null; 127 } 128 return m; 129 } 130 } 131 | Popular Tags |