1 19 20 package org.netbeans.modules.xml.wsdl.model.extensions.xsd.impl; 21 22 import javax.xml.XMLConstants ; 23 import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent; 24 import org.netbeans.modules.xml.schema.model.Schema; 25 import org.netbeans.modules.xml.schema.model.SchemaModel; 26 import org.netbeans.modules.xml.schema.model.SchemaModelFactory; 27 import org.netbeans.modules.xml.wsdl.model.Import; 28 import org.netbeans.modules.xml.wsdl.model.Types; 29 import org.netbeans.modules.xml.wsdl.model.impl.ImportImpl; 30 import org.netbeans.modules.xml.wsdl.model.spi.WSDLComponentBase; 31 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 32 import org.netbeans.modules.xml.xam.dom.AbstractNamedComponentReference; 33 import org.netbeans.modules.xml.xam.dom.DocumentModel; 34 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 35 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 36 37 41 public class SchemaReferenceImpl<T extends ReferenceableSchemaComponent> 42 extends AbstractNamedComponentReference<T> implements NamedComponentReference<T> { 43 44 45 public SchemaReferenceImpl( 46 T referenced, 47 Class <T> type, 48 AbstractDocumentComponent parent) { 49 super(referenced, type, parent); 50 } 51 52 public SchemaReferenceImpl(Class <T> type, AbstractDocumentComponent parent, String refString){ 54 super(type, parent, refString); 55 } 56 57 public T get() { 58 if (getReferenced() == null) { 59 String localName = getLocalName(); 60 String namespace = getEffectiveNamespace(); 61 T target = null; 62 63 if (XMLConstants.W3C_XML_SCHEMA_NS_URI.equals(namespace)) { 64 SchemaModel primitiveModel = SchemaModelFactory.getDefault().getPrimitiveTypesModel(); 65 target = primitiveModel.resolve(namespace, localName, getType()); 66 } else { 67 Types types = getParent().getModel().getDefinitions().getTypes(); 68 if (types != null) { 69 for (Schema s : types.getSchemas()) { 70 target = s.getModel().resolve(namespace, localName, getType()); 71 if (target != null) { 72 break; 73 } 74 } 75 } 76 if (target == null) { 77 for (Import i : getParent().getModel().getDefinitions().getImports()) { 78 DocumentModel m = null; 79 try { 80 m = ((ImportImpl)i).resolveImportedModel(); 81 } catch(CatalogModelException ex) { 82 } 84 if (m instanceof SchemaModel) { 85 target = ((SchemaModel)m).resolve(namespace, localName, getType()); 86 } 87 if (target != null) { 88 break; 89 } 90 } 91 } 92 } 93 94 if (target != null) { 95 setReferenced(target); 96 } 97 } 98 return getReferenced(); 99 } 100 101 public WSDLComponentBase getParent() { 102 return (WSDLComponentBase) super.getParent(); 103 } 104 105 public String getEffectiveNamespace() { 106 if (refString == null) { 107 assert getReferenced() != null; 108 return getReferenced().getModel().getSchema().getTargetNamespace(); 109 } else { 110 if (getPrefix() == null) { 111 return null; 112 } else { 113 return getParent().lookupNamespaceURI(getPrefix()); 114 } 115 } 116 } 117 } 118 | Popular Tags |