KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.xml.wsdl.model.spi;
20
21 import java.io.IOException JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25 import javax.xml.namespace.QName JavaDoc;
26 import org.netbeans.modules.xml.wsdl.model.ExtensibilityElement;
27 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
28 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
29 import org.netbeans.modules.xml.wsdl.model.visitor.WSDLVisitor;
30 import org.netbeans.modules.xml.xam.Component;
31 import org.netbeans.modules.xml.xam.dom.Attribute;
32 import org.w3c.dom.Element JavaDoc;
33
34 /**
35  *
36  * @author Nam Nguyen
37  */

38 public class GenericExtensibilityElement extends WSDLComponentBase implements ExtensibilityElement.ParentSelector {
39     
40     /** Creates a new instance of GenericExtensibilityElement */
41     public GenericExtensibilityElement(WSDLModel model, Element e) {
42         super(model, e);
43     }
44     
45     public GenericExtensibilityElement(WSDLModel model, QName JavaDoc qname){
46         this(model, createNewElement(qname, model));
47     }
48     
49     public void accept(WSDLVisitor visitor) {
50         visitor.visit(this);
51     }
52
53     public static class StringAttribute implements Attribute {
54         private String JavaDoc name;
55         public StringAttribute(String JavaDoc name) { this.name = name; }
56         public Class JavaDoc getType() { return String JavaDoc.class; }
57         public String JavaDoc getName() { return name; }
58         public Class JavaDoc getMemberType() { return null; }
59     }
60     
61     public String JavaDoc getAttribute(String JavaDoc attribute) {
62         return getAttribute(new StringAttribute(attribute));
63     }
64     public void setAttribute(String JavaDoc attribute, String JavaDoc value) {
65         setAttribute(attribute, new StringAttribute(attribute), value);
66     }
67     
68     public String JavaDoc getContentFragment() {
69         return super.getXmlFragment();
70     }
71     
72     public void setContentFragment(String JavaDoc text) throws IOException JavaDoc {
73         super.setXmlFragment(CONTENT_FRAGMENT_PROPERTY, text);
74     }
75
76     public void addAnyElement(ExtensibilityElement anyElement, int index) {
77         List JavaDoc<WSDLComponent> all = getChildren();
78         if (index > all.size() || index < 0) {
79             throw new ArrayIndexOutOfBoundsException JavaDoc(index);
80         }
81         insertAtIndex(EXTENSIBILITY_ELEMENT_PROPERTY, anyElement, index);
82     }
83
84     public void removeAnyElement(ExtensibilityElement any) {
85         super.removeExtensibilityElement(any);
86     }
87
88     public List JavaDoc<ExtensibilityElement> getAnyElements() {
89         List JavaDoc<ExtensibilityElement> result = new ArrayList JavaDoc<ExtensibilityElement>();
90         List JavaDoc<ExtensibilityElement> allEEs = super.getExtensibilityElements();
91         for (ExtensibilityElement ee : allEEs) {
92             if (! ee.getModel().getQNames().contains(ee.getQName())) {
93                 result.add(ee);
94             }
95         }
96         return Collections.unmodifiableList(result);
97     }
98
99     /**
100      * Generic extensibility by default can be added to any WSDL component.
101      */

102     public boolean canBeAddedTo(Component target) {
103         if (target instanceof WSDLComponent) {
104             return true;
105         }
106         return false;
107     }
108 }
109
Popular Tags