KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > model > spi > WSDLComponentBase


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.wsdl.model.spi;
21
22 import java.util.List JavaDoc;
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 JavaDoc;
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 JavaDoc;
38 import org.w3c.dom.NodeList JavaDoc;
39
40 /**
41  * @author rico
42  * @author Nam Nguyen
43  */

44 public abstract class WSDLComponentBase extends AbstractDocumentComponent<WSDLComponent> implements WSDLComponent {
45
46     /** Creates a new instance of WSDLComponentImpl */
47     public WSDLComponentBase(WSDLModel model, org.w3c.dom.Element JavaDoc e) {
48         super((WSDLModelImpl) model, e);
49     }
50     
51     public WSDLModel getModel() {
52         return (WSDLModel) super.getModel();
53     }
54     
55     protected void populateChildren(List JavaDoc<WSDLComponent> children) {
56         NodeList JavaDoc nl = getPeer().getChildNodes();
57         if (nl != null){
58             for (int i = 0; i < nl.getLength(); i++) {
59                 org.w3c.dom.Node JavaDoc 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 JavaDoc createNewElement(QName JavaDoc qName, WSDLModel model){
72         return model.getDocument().createElementNS(qName.getNamespaceURI(), qName.getLocalPart());
73     }
74     
75     protected static org.w3c.dom.Element JavaDoc createPrefixedElement(QName JavaDoc qName, WSDLModel model){
76         String JavaDoc 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 JavaDoc getAttributeValueOf(Attribute attr, String JavaDoc stringValue) {
90         return stringValue;
91     }
92     
93     protected <T extends ReferenceableWSDLComponent> NamedComponentReference<T> resolveGlobalReference(
94             Class JavaDoc<T> c, Attribute attrName) {
95         String JavaDoc 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 JavaDoc<T> type) {
104         return new GlobalReferenceImpl<T>(target, type, this);
105     }
106     
107     protected <T extends ReferenceableSchemaComponent>
108             NamedComponentReference<T> resolveSchemaReference(Class JavaDoc<T> c, Attribute attrName) {
109         String JavaDoc 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 JavaDoc<T> type) {
115         return new SchemaReferenceImpl<T>( target, type, this);
116     }
117     
118     public String JavaDoc toString(QName JavaDoc 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 JavaDoc<ExtensibilityElement> getExtensibilityElements() {
131         return getChildren(ExtensibilityElement.class);
132     }
133     
134     public <T extends ExtensibilityElement> List JavaDoc<T> getExtensibilityElements(Class JavaDoc<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