1 19 20 package org.netbeans.modules.xml.wsdl.model.impl; 21 22 import org.netbeans.modules.xml.wsdl.model.Definitions; 23 import org.netbeans.modules.xml.wsdl.model.Import; 24 import org.netbeans.modules.xml.wsdl.model.ReferenceableWSDLComponent; 25 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 26 import org.netbeans.modules.xml.wsdl.model.spi.WSDLComponentBase; 27 import org.netbeans.modules.xml.wsdl.model.visitor.FindReferencedVisitor; 28 import org.netbeans.modules.xml.xam.dom.AbstractNamedComponentReference; 29 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 30 import org.netbeans.modules.xml.xam.locator.CatalogModelException; 31 32 37 public class GlobalReferenceImpl<T extends ReferenceableWSDLComponent> 38 extends AbstractNamedComponentReference<T> implements NamedComponentReference<T> { 39 40 41 public GlobalReferenceImpl( 43 T referenced, 44 Class <T> type, 45 WSDLComponentBase parent) { 46 super(referenced, type, parent); 47 } 48 49 public GlobalReferenceImpl( 51 Class <T> type, 52 WSDLComponentBase parent, 53 String refString){ 54 super(type, parent, refString); 55 } 56 57 protected Definitions getDefinitions() { 58 WSDLComponentBase wparent = WSDLComponentBase.class.cast(getParent()); 59 return wparent.getModel().getDefinitions(); 60 } 61 62 public T get() { 63 WSDLComponentBase wparent = WSDLComponentBase.class.cast(getParent()); 64 if (super.getReferenced() == null) { 65 String localName = getLocalName(); 66 String namespace = getEffectiveNamespace(); 67 WSDLModel model = wparent.getWSDLModel(); 68 T target = null; 69 if (namespace != null && namespace.equals(model.getDefinitions().getTargetNamespace())) { 70 target = new FindReferencedVisitor<T>(model.getDefinitions()).find(localName, getType()); 71 } 72 if (target == null) { 73 for (Import i : wparent.getWSDLModel().getDefinitions().getImports()) { 74 if (! i.getNamespace().equals(namespace)) { 75 continue; 76 } 77 try { 78 model = i.getImportedWSDLModel(); 79 } catch(CatalogModelException ex) { 80 continue; 81 } 82 target = new FindReferencedVisitor<T>(model.getDefinitions()).find(localName, getType()); 83 if (target != null) { 84 break; 85 } 86 } 87 } 88 setReferenced(target); 89 } 90 return getReferenced(); 91 } 92 93 public WSDLComponentBase getParent() { 94 return (WSDLComponentBase) super.getParent(); 95 } 96 97 public String getEffectiveNamespace() { 98 if (refString == null) { 99 assert getReferenced() != null; 100 return getReferenced().getModel().getDefinitions().getTargetNamespace(); 101 } else { 102 return getParent().lookupNamespaceURI(getPrefix()); 103 } 104 } 105 } 106 | Popular Tags |