KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > api > property > PropertyUtil


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  * PropertyUtil.java
22  *
23  * Created on April 17, 2006, 12:58 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.wsdl.ui.api.property;
30
31 import java.util.ArrayList JavaDoc;
32 import java.util.Collection JavaDoc;
33 import java.util.List JavaDoc;
34
35 import javax.xml.namespace.QName JavaDoc;
36
37 import org.netbeans.modules.xml.wsdl.model.Binding;
38 import org.netbeans.modules.xml.wsdl.model.Definitions;
39 import org.netbeans.modules.xml.wsdl.model.Message;
40 import org.netbeans.modules.xml.wsdl.model.PortType;
41 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
42 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
43
44 /**
45  *
46  * @author radval
47  */

48 public class PropertyUtil {
49     private static final String JavaDoc COLON = ":";// NOI18N
50
/** Creates a new instance of PropertyUtil */
51     public PropertyUtil() {
52     }
53
54     public static String JavaDoc[] getAllPortTypes(WSDLModel model, boolean includeBlankItem) {
55         ArrayList JavaDoc<String JavaDoc> portTypesList = new ArrayList JavaDoc<String JavaDoc>();
56         if (includeBlankItem) {
57             portTypesList.add("");
58         }
59
60         //ifist get all PortTypes in current wsdl document
61
portTypesList.addAll(getAllAvailablePortTypes(model, model));
62
63         //then get all port type in all explicitly imported documents
64
for (WSDLModel imported : Utility.getImportedDocuments(model)) {
65             portTypesList.addAll(getAllAvailablePortTypes(model, imported));
66         }
67
68         return portTypesList.toArray(new String JavaDoc[portTypesList.size()]);
69     }
70
71
72     private static List JavaDoc<String JavaDoc> getAllAvailablePortTypes(WSDLModel source, WSDLModel document) {
73         ArrayList JavaDoc<String JavaDoc> portTypesList = new ArrayList JavaDoc<String JavaDoc>();
74
75         Definitions definition = document.getDefinitions();
76         
77         for (PortType portType : definition.getPortTypes()) {
78             String JavaDoc name = portType.getName();
79             String JavaDoc targetNamespace = document.getDefinitions().getTargetNamespace();
80             String JavaDoc prefix = Utility.getNamespacePrefix(targetNamespace, source);
81             if(name != null) {
82                 if(prefix != null) {
83                     String JavaDoc portTypeQNameStr = prefix + COLON + name;
84                     portTypesList.add(portTypeQNameStr);
85                 } else {
86                     portTypesList.add(name);
87                 }
88             }
89         }
90         
91         return portTypesList;
92     }
93
94     public static String JavaDoc[] getAllMessages(WSDLModel model) {
95         ArrayList JavaDoc<String JavaDoc> messageList = new ArrayList JavaDoc<String JavaDoc>();
96         //messageList.add("");
97

98         //first get all messages in current wsdl document
99
messageList.addAll(getAllAvailableMessages(model, model));
100
101         //then get all messages in all imported wsdl documents
102
Collection JavaDoc<WSDLModel> allWsdls = Utility.getImportedDocuments(model);
103         if (allWsdls != null) {
104             for (WSDLModel doc : allWsdls) {
105                 messageList.addAll(getAllAvailableMessages(model, doc));
106
107             }
108         }
109         return messageList.toArray(new String JavaDoc[messageList.size()]);
110     }
111
112     private static List JavaDoc<String JavaDoc> getAllAvailableMessages(WSDLModel source, WSDLModel document) {
113         ArrayList JavaDoc<String JavaDoc> messageList = new ArrayList JavaDoc<String JavaDoc>();
114
115         Definitions definition = document.getDefinitions();
116         for (Message msg : definition.getMessages()) {
117             String JavaDoc name = msg.getName();
118             String JavaDoc targetNamespace = definition.getTargetNamespace();
119             String JavaDoc prefix = Utility.getNamespacePrefix(targetNamespace, source);
120             if(name != null) {
121                 if(prefix != null) {
122                     String JavaDoc messageQNameStr = prefix + COLON + name;
123                     messageList.add(messageQNameStr);
124                 } else {
125                     messageList.add(name);
126                 }
127             }
128             
129         }
130
131         return messageList;
132     }
133
134
135     public static String JavaDoc[] getAllBindings(WSDLModel model) {
136         ArrayList JavaDoc<String JavaDoc> bindingList = new ArrayList JavaDoc<String JavaDoc>();
137         bindingList.add("");
138
139         //first get all binding in current wsdl document
140
bindingList.addAll(getAllBindings(model, model));
141
142         //then get all biniding in all explicitly imported documents
143
for (WSDLModel doc : Utility.getImportedDocuments(model)) {
144             bindingList.addAll(getAllBindings(model, doc));
145         }
146
147         return bindingList.toArray(new String JavaDoc[bindingList.size()]);
148     }
149
150     private static List JavaDoc<String JavaDoc> getAllBindings(WSDLModel source, WSDLModel document) {
151         ArrayList JavaDoc<String JavaDoc> bindingList = new ArrayList JavaDoc<String JavaDoc>();
152
153         Definitions definition = document.getDefinitions();
154
155         for (Binding binding : definition.getBindings()) {
156             String JavaDoc name = binding.getName();
157             String JavaDoc targetNamespace = definition.getTargetNamespace();
158             String JavaDoc prefix = Utility.getNamespacePrefix(targetNamespace, source);
159             if(name != null) {
160                 if(prefix != null) {
161                     String JavaDoc messageQNameStr = prefix + COLON + name;
162                     bindingList.add(messageQNameStr);
163                 } else {
164                     bindingList.add(name);
165                 }
166             }
167
168         }
169
170         return bindingList;
171     }
172
173     public static Message getMessage(MessageProvider prov, WSDLModel model) {
174         Message msg = prov.getWSDLMessage();
175         if (msg != null) {
176             return msg;
177         }
178         
179         String JavaDoc messageName = prov.getMessage();
180         if (messageName == null) {
181             return null;
182         }
183         String JavaDoc[] qnameParts = messageName.split(COLON);
184         String JavaDoc prefix = "";
185         String JavaDoc localPart = messageName;
186         if (qnameParts.length > 1) {
187             prefix = qnameParts[0];
188             localPart = qnameParts[1];
189         }
190         String JavaDoc ns = Utility.getNamespaceURI(prefix, model);
191         if (ns != null) {
192             return model.findComponentByName(new QName JavaDoc(ns, localPart), Message.class);
193         }
194         return model.findComponentByName(localPart, Message.class);
195     }
196 }
197
Popular Tags