KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > extensibility > model > impl > WSDLExtensibilityElementImpl


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * Created on May 25, 2005
22  *
23  * To change the template for this generated file go to
24  * Window - Preferences - Java - Code Generation - Code and Comments
25  */

26 package org.netbeans.modules.xml.wsdl.ui.extensibility.model.impl;
27
28 import java.util.ArrayList JavaDoc;
29 import java.util.Collection JavaDoc;
30 import java.util.HashMap JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34
35 import javax.xml.namespace.QName JavaDoc;
36
37 import org.netbeans.modules.xml.schema.model.GlobalElement;
38 import org.netbeans.modules.xml.schema.model.Schema;
39 import org.netbeans.modules.xml.wsdl.ui.common.Constants;
40 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElement;
41 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementInfo;
42 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.WSDLExtensibilityElementInfoContainer;
43 import org.netbeans.modules.xml.wsdl.ui.extensibility.model.XMLSchemaFileInfo;
44 import org.openide.loaders.DataFolder;
45 import org.openide.loaders.DataObject;
46
47
48
49 /**
50  * @author radval
51  *
52  * elements need to be unique withing this WSDLExtensibilityElement.
53  * (i.e two element name can be same as long as they are in different targetNamespace)
54  *
55  */

56 public class WSDLExtensibilityElementImpl implements WSDLExtensibilityElement {
57     
58     
59     private DataFolder mDataFolder;
60     
61     private Map JavaDoc elementInfoMap = new HashMap JavaDoc();
62     
63     private Map JavaDoc providersMap = new HashMap JavaDoc();
64     
65     private WSDLExtensibilityElementsImpl mRootElement;
66     
67     public WSDLExtensibilityElementImpl(DataFolder dataObject, WSDLExtensibilityElementsImpl element) {
68         this.mDataFolder = dataObject;
69         this.mRootElement = element;
70     }
71     
72     public WSDLExtensibilityElementInfo getWSDLExtensibilityElementInfos(QName JavaDoc elementQName) {
73         List JavaDoc allInfos = getAllWSDLExtensibilityElementInfos();
74         Iterator JavaDoc it = allInfos.iterator();
75         String JavaDoc ns = elementQName.getNamespaceURI();
76         String JavaDoc localPart = elementQName.getLocalPart();
77         while(it.hasNext()) {
78             WSDLExtensibilityElementInfo eInfo = (WSDLExtensibilityElementInfo) it.next();
79             Schema schema = eInfo.getSchema();
80             if(schema != null) {
81                 if(ns != null) {
82                     if(ns.equals(schema.getTargetNamespace())
83                             && localPart.equals(eInfo.getElementName())) {
84                         if(findGlobalElement(elementQName, schema) != null) {
85                             return eInfo;
86                         }
87                     }
88                 }
89             }
90         }
91         
92         return null;
93     }
94     
95     public List JavaDoc getAllWSDLExtensibilityElementInfos() {
96         ArrayList JavaDoc elementsInfo = new ArrayList JavaDoc();
97         elementsInfo.addAll(getWSDLExtensibilityElementInfos());
98         
99         List JavaDoc containers = getAllWSDLExtensibilityElementInfoContainers();
100         Iterator JavaDoc it = containers.iterator();
101         while(it.hasNext()) {
102             WSDLExtensibilityElementInfoContainer container = (WSDLExtensibilityElementInfoContainer) it.next();
103             elementsInfo.addAll(container.getAllWSDLExtensibilityElementInfo());
104         }
105         
106         return elementsInfo;
107     }
108     
109     public List JavaDoc getWSDLExtensibilityElementInfos() {
110         ArrayList JavaDoc elementInfos = new ArrayList JavaDoc();
111         ArrayList JavaDoc allDataObjectNames = new ArrayList JavaDoc();
112         
113         DataObject[] children = this.mDataFolder.getChildren();
114         for(int i = 0; i < children.length; i++ ) {
115             DataObject dObj = children[i];
116             if(!(dObj instanceof DataFolder)) {
117                 WSDLExtensibilityElementInfo elementInfo =
118                     (WSDLExtensibilityElementInfo) elementInfoMap.get(dObj.getName());
119                 
120                 if(elementInfo == null) {
121                     elementInfo = createNewElementInfo(dObj);
122                     elementInfoMap.put(dObj.getName(), elementInfo);
123                 }
124                 
125                 elementInfos.add(elementInfo);
126                 allDataObjectNames.add(dObj.getName());
127             }
128         }
129         
130         
131         //TODO:update elementInfoMap map. this is to ensure if some
132
//modules are disabled then we remove the elementInfos provided
133
//by that module
134

135         
136         return elementInfos;
137     }
138     
139     public List JavaDoc getAllWSDLExtensibilityElementInfoContainers() {
140         ArrayList JavaDoc providers = new ArrayList JavaDoc();
141         DataObject[] children = this.mDataFolder.getChildren();
142         for(int i = 0; i < children.length; i++ ) {
143             DataObject dObj = children[i];
144             if(dObj instanceof DataFolder) {
145                 WSDLExtensibilityElementInfoContainer provider =
146                     (WSDLExtensibilityElementInfoContainer) providersMap.get(dObj.getName());
147                 
148                 if(provider == null) {
149                     provider = createNewProvider((DataFolder) dObj);
150                     providersMap.put(dObj.getName(), provider);
151                 }
152                 providers.add(provider);
153             }
154         }
155         
156         //update provider map. this is to ensure if some
157
//modules are disabled then we remove the provider provided
158
//by that module
159

160         return providers;
161     }
162     
163     public String JavaDoc getName() {
164         return mDataFolder.getName();
165     }
166     
167     public boolean isExtensibilityElementsAvailable() {
168         boolean available = false;
169         
170         if(this.getAllWSDLExtensibilityElementInfos().size() != 0) {
171             available = true;
172         }
173         return available;
174     }
175     
176     private WSDLExtensibilityElementInfoContainer createNewProvider(DataFolder dataObject) {
177         WSDLExtensibilityElementInfoContainer provider =
178             new WSDLExtensibilityElementInfoContainerImpl(dataObject, this.mRootElement);
179         
180         return provider;
181     }
182     
183     
184     private WSDLExtensibilityElementInfo createNewElementInfo(DataObject dataObject) {
185         
186         Object JavaDoc val = dataObject.getPrimaryFile().getAttribute(Constants.XSD_FILE_NAME);
187         XMLSchemaFileInfo xmlSchemaInfo = null;
188         if(val instanceof String JavaDoc) {
189             xmlSchemaInfo = this.mRootElement.getXMLSchemaFileInfoMatchingFileName((String JavaDoc) val);
190         }
191         
192         
193         WSDLExtensibilityElementInfo elementInfo =
194             new WSDLExtensibilityElementInfoImpl(dataObject, xmlSchemaInfo);
195         
196         return elementInfo;
197     }
198         
199         
200     private GlobalElement findGlobalElement(QName JavaDoc elementQName, Schema schema) {
201         Collection JavaDoc<GlobalElement> elements = schema.getElements();
202         Iterator JavaDoc<GlobalElement> iter = elements.iterator();
203         while (iter.hasNext()) {
204             GlobalElement elem = iter.next();
205             if (elem.getName().equals(elementQName.getLocalPart())) {
206                 return elem;
207             }
208         }
209         
210         return null;
211     }
212
213     public Collection JavaDoc<WSDLExtensibilityElementInfo> getWSDLExtensibilityElementInfos(String JavaDoc namespace) {
214         List JavaDoc<WSDLExtensibilityElementInfo> allInfos = getAllWSDLExtensibilityElementInfos();
215         List JavaDoc<WSDLExtensibilityElementInfo> result = new ArrayList JavaDoc<WSDLExtensibilityElementInfo>();
216         for (WSDLExtensibilityElementInfo eInfo : allInfos) {
217             Schema schema = eInfo.getSchema();
218             if(schema != null) {
219                 if(namespace != null) {
220                     if(namespace.equals(schema.getTargetNamespace())) {
221                         result.add(eInfo);
222                     }
223                 }
224             }
225         }
226         
227         return result;
228     }
229 }
230
Popular Tags