1 19 20 package org.netbeans.modules.xml.wsdl.model.spi; 21 22 import java.util.List ; 23 import org.netbeans.modules.xml.wsdl.model.impl.*; 24 import org.netbeans.modules.xml.xam.Component; 25 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 26 import javax.xml.namespace.QName ; 27 import org.netbeans.modules.xml.schema.model.ReferenceableSchemaComponent; 28 import org.netbeans.modules.xml.wsdl.model.Documentation; 29 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement; 30 import org.netbeans.modules.xml.wsdl.model.ReferenceableWSDLComponent; 31 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 32 import org.netbeans.modules.xml.wsdl.model.WSDLModel; 33 import org.netbeans.modules.xml.wsdl.model.extensions.xsd.impl.SchemaReferenceImpl; 34 import org.netbeans.modules.xml.xam.dom.Attribute; 35 import org.netbeans.modules.xml.xam.dom.DocumentComponent; 36 import org.netbeans.modules.xml.xam.dom.NamedComponentReference; 37 import org.w3c.dom.Element ; 38 import org.w3c.dom.NodeList ; 39 40 44 public abstract class WSDLComponentBase extends AbstractDocumentComponent<WSDLComponent> implements WSDLComponent { 45 46 47 public WSDLComponentBase(WSDLModel model, org.w3c.dom.Element e) { 48 super((WSDLModelImpl) model, e); 49 } 50 51 public WSDLModel getModel() { 52 return (WSDLModel) super.getModel(); 53 } 54 55 protected void populateChildren(List <WSDLComponent> children) { 56 NodeList nl = getPeer().getChildNodes(); 57 if (nl != null){ 58 for (int i = 0; i < nl.getLength(); i++) { 59 org.w3c.dom.Node n = nl.item(i); 60 if (n instanceof Element) { 61 WSDLModel wmodel = getModel(); 62 WSDLComponentBase comp = (WSDLComponentBase) wmodel.getFactory().create((Element)n,this); 63 if (comp != null) { 64 children.add(comp); 65 } 66 } 67 } 68 } 69 } 70 71 protected static org.w3c.dom.Element createNewElement(QName qName, WSDLModel model){ 72 return model.getDocument().createElementNS(qName.getNamespaceURI(), qName.getLocalPart()); 73 } 74 75 protected static org.w3c.dom.Element createPrefixedElement(QName qName, WSDLModel model){ 76 String qualified = qName.getPrefix() == null ? qName.getLocalPart() : 77 qName.getPrefix() + ":" + qName.getLocalPart(); 78 return model.getDocument().createElementNS(qName.getNamespaceURI(), qualified); 79 } 80 81 public void setDocumentation(Documentation doc) { 82 setChildBefore(Documentation.class, DOCUMENTATION_PROPERTY, doc, TypeCollection.ALL.types()); 83 } 84 85 public Documentation getDocumentation() { 86 return getChild(Documentation.class); 87 } 88 89 protected Object getAttributeValueOf(Attribute attr, String stringValue) { 90 return stringValue; 91 } 92 93 protected <T extends ReferenceableWSDLComponent> NamedComponentReference<T> resolveGlobalReference( 94 Class <T> c, Attribute attrName) { 95 String v = getAttribute(attrName); 96 return v == null ? null : new GlobalReferenceImpl<T>(c, this, v); 97 } 98 99 public WSDLModel getWSDLModel() { 100 return getModel(); 101 } 102 103 public <T extends ReferenceableWSDLComponent> NamedComponentReference<T> createReferenceTo(T target, Class <T> type) { 104 return new GlobalReferenceImpl<T>(target, type, this); 105 } 106 107 protected <T extends ReferenceableSchemaComponent> 108 NamedComponentReference<T> resolveSchemaReference(Class <T> c, Attribute attrName) { 109 String v = getAttribute(attrName); 110 return v == null ? null : new SchemaReferenceImpl<T>(c, this, v); 111 } 112 113 public <T extends ReferenceableSchemaComponent> 114 NamedComponentReference<T> createSchemaReference(T target, Class <T> type) { 115 return new SchemaReferenceImpl<T>( target, type, this); 116 } 117 118 public String toString(QName qname) { 119 return getPrefixedName(qname.getNamespaceURI(), qname.getLocalPart()); 120 } 121 122 public void removeExtensibilityElement(ExtensibilityElement ee) { 123 removeChild(EXTENSIBILITY_ELEMENT_PROPERTY, ee); 124 } 125 126 public void addExtensibilityElement(ExtensibilityElement ee) { 127 appendChild(EXTENSIBILITY_ELEMENT_PROPERTY, ee); 128 } 129 130 public List <ExtensibilityElement> getExtensibilityElements() { 131 return getChildren(ExtensibilityElement.class); 132 } 133 134 public <T extends ExtensibilityElement> List <T> getExtensibilityElements(Class <T> type) { 135 return getChildren(type); 136 } 137 138 public boolean canPaste(Component child) { 139 if (child instanceof DocumentComponent) { 140 return new ChildComponentUpdateVisitor().canAdd(this, (DocumentComponent) child); 141 } else { 142 return false; 143 } 144 } 145 } 146 | Popular Tags |