KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > model > WebServiceData


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.websvc.registry.model;
21
22 ///import org.netbeans.modules.websvc.registry.model.WebServiceListModel;
23
///import org.netbeans.modules.websvc.registry.jaxrpc.Wsdl2Java;
24
////import org.netbeans.modules.websvc.registry.util.Util;
25

26 import com.sun.xml.rpc.processor.model.Port;
27 import com.sun.xml.rpc.processor.model.Operation;
28 /////////import com.sun.xml.rpc.processor.model.java.JavaMethod;
29

30 import java.net.MalformedURLException JavaDoc;
31 import java.net.URL JavaDoc;
32
33 import java.io.File JavaDoc;
34
35 import java.util.ArrayList JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.Arrays JavaDoc;
38 import java.util.List JavaDoc;
39 import java.util.Set JavaDoc;
40 import java.util.HashSet JavaDoc;
41 import java.util.HashMap JavaDoc;
42
43
44 /**
45  * A webservice model. Holds the URL & methods information etc
46  * When the WSDL is parsed for each port a WebServiceData is created and added to the
47  * WebService Node Model.
48  * @author octav, Winston Prakash, David Botterill
49  */

50 public class WebServiceData {
51     
52     /** Unique Web service id*/
53     private String JavaDoc websvcId;
54     /** Web service name */
55     private String JavaDoc name;
56     /** Web Service port number */
57     private int webServicePort;
58     /** Web service URL */
59     private String JavaDoc wsdlUrl;
60     /** proxy name */
61     private String JavaDoc proxy;
62     
63     private String JavaDoc groupId;
64     
65     private String JavaDoc displayName;
66     
67     private String JavaDoc proxyJarFileName;
68     
69     private String JavaDoc packageName;
70     
71     private String JavaDoc webServiceAddress;
72     
73     /**
74      * Array list of com.sun.xml.rpc.processor.model.Port objects
75      */

76     private ArrayList JavaDoc ports = new ArrayList JavaDoc();
77     
78     public final static String JavaDoc PORT_PROPERTY_NAME="WSPORTNAME";
79     /** Default constructor */
80     public WebServiceData() {
81         this(WebServiceListModel.getInstance().getUniqueWebServiceId());
82     }
83     
84     public WebServiceData(String JavaDoc id) {
85         setId(id);
86     }
87     
88     public void setId(String JavaDoc id){
89         websvcId = id;
90     }
91     
92     public String JavaDoc getId(){
93         return websvcId;
94     }
95     
96     
97     public String JavaDoc getName() {
98         return name;
99     }
100     
101     public String JavaDoc getDisplayName() {
102         if(displayName == null) displayName = name;
103         return displayName;
104     }
105     
106     public void setDisplayName(String JavaDoc dispName) {
107         displayName = dispName;
108     }
109     
110     
111     public String JavaDoc getGroupId(){
112         return groupId;
113     }
114     
115     public void setGroupId(String JavaDoc id){
116         groupId = id;
117     }
118     public void setPackageName(String JavaDoc inPackageName){
119         packageName = inPackageName;
120     }
121     
122     public void setWebServiceAddress(String JavaDoc inAddress){
123         webServiceAddress = inAddress;
124     }
125     
126     /**
127      * InSync needs this, however this is a read only property
128      * @param Web Service name
129      */

130     public void setName(String JavaDoc name) {
131         this.name = name;
132     }
133     
134     /** This method will return the methods for the service.
135      * @return an array list of com.sun.xml.rpc.processor.model.Operation objects.
136      */

137     public ArrayList JavaDoc getMethods() {
138         
139         /**
140          * Go through the ports and get the operations, for each
141          * operation, return the JavaMethod.
142          */

143         ArrayList JavaDoc returnMethods = new ArrayList JavaDoc();
144         Iterator JavaDoc portIterator = ports.iterator();
145         Port currentPort = null;
146         while(portIterator.hasNext()) {
147             currentPort = (Port)portIterator.next();
148             if(null == currentPort || null == currentPort.getOperations()) {
149                 continue;
150             }
151             Iterator JavaDoc operationIterator = currentPort.getOperations();
152             Operation currentOperation = null;
153             while(operationIterator.hasNext()) {
154                 currentOperation = (Operation)operationIterator.next();
155                 if(null == currentOperation) {
156                     continue;
157                 }
158                 returnMethods.add(currentOperation);
159             }
160         }
161         return returnMethods;
162     }
163     
164     
165     
166     public int getWebServicePort() {
167         return webServicePort;
168     }
169     
170     public void setWebServicePort(int portNumber) {
171         webServicePort = portNumber;
172     }
173     
174     public String JavaDoc getURL() {
175         return wsdlUrl;
176     }
177     
178     public void setURL(String JavaDoc url) {
179         wsdlUrl = url;
180     }
181     
182     public String JavaDoc getProxy() {
183         return proxy;
184     }
185     
186     public void setProxy(String JavaDoc proxy) {
187         this.proxy = proxy;
188     }
189     
190     public void setProxyJarFileName(String JavaDoc jarName){
191         
192         proxyJarFileName = jarName;
193     }
194     
195     public String JavaDoc getProxyJarFileName(){
196         /**
197          * Since this data could have been persisted and moved, we need to
198          * make sure the file name of this jar file is still valid. If it is not found,
199          * try getting it from the current user directory. There are really only two places
200          * that are valid for the location to be in, the netbeans user directory or a temp directory
201          * when the user is testing the web service before they've added it to server navigator.
202          * - David Botterill 4/23/2004
203          */

204         if(null == proxyJarFileName) return null;
205        
206         File JavaDoc proxyFile = new File JavaDoc(proxyJarFileName);
207         if(!proxyFile.exists()) {
208             /**
209              * First, strip off any bogus path information for both windows and unix style paths that might exist.
210              */

211             String JavaDoc fileOnlyName = proxyJarFileName;
212             if(proxyJarFileName.indexOf("/") != -1) {
213                 fileOnlyName = proxyJarFileName.substring(proxyJarFileName.lastIndexOf("/")+1);
214             }
215             
216             if(proxyJarFileName.indexOf("\\") != -1) {
217                 fileOnlyName = proxyJarFileName.substring(proxyJarFileName.lastIndexOf("\\")+1);
218             }
219             
220             String JavaDoc newName = System.getProperty("netbeans.user") + File.separator + "websvc" + File.separator + fileOnlyName;
221             proxyFile = new File JavaDoc(newName);
222             if(!proxyFile.exists()) {
223                 return null;
224             } else {
225                 proxyJarFileName = newName;
226                 /**
227                  * make sure to set the new name.
228                  */

229                 this.setProxyJarFileName(proxyJarFileName);
230             }
231         }
232         
233         return proxyJarFileName;
234     }
235     
236     public String JavaDoc getWSDescription() {
237         return "Web Service Information-\n" +
238         "Name: " + name + "\n" +
239         "Port number: " + webServicePort + "\n" +
240         "URL: " + wsdlUrl + "\n" +
241         "Address: " + webServiceAddress + "\n"
242         ;
243     }
244     public String JavaDoc getPackageName(){
245         if(null == packageName) {
246             packageName = "webservice";///Wsdl2Java.DEFAULT_TARGET_PACKAGE;
247
}
248         return packageName;
249     }
250     public String JavaDoc getWebServiceAddress(){
251         return webServiceAddress;
252     }
253     
254     public Port [] getPorts() {
255         return (Port []) ports.toArray(new Port [0]);
256     }
257     
258     public void addPort(Port inPort) {
259         ports.add(inPort);
260     }
261     
262     public void setPorts(Port [] inPorts) {
263         ports = new ArrayList JavaDoc(Arrays.asList(inPorts));
264     }
265     
266     
267     /**
268      * Override equals to specialize checking equality of WebServiceData. Web services
269      * for Creator will be equal if the display name is equal regardless of case.
270      */

271     public boolean equals(Object JavaDoc inWSData) {
272         /**
273          * If the object passed isn't of the same type, they aren't equal.
274          */

275         if(!(inWSData instanceof WebServiceData)) {
276             return false;
277         }
278         
279         WebServiceData comparingWSdata = (WebServiceData)inWSData;
280         String JavaDoc thisDisplayName = this.getDisplayName();
281         String JavaDoc comparingDisplayName = comparingWSdata.getDisplayName();
282         
283         /**
284          * the Display Name should never be null but we still need to check the condition.
285          */

286         if(null == comparingDisplayName && null != thisDisplayName) {
287             return false;
288         }
289         if(null == thisDisplayName && null != comparingDisplayName) {
290             return false;
291         }
292         
293         /**
294          * This should never happen but they logically are equal based on our
295          * definition of object equality.
296          */

297         if(null == thisDisplayName && null == comparingDisplayName) {
298             return true;
299         }
300         
301         
302         if(thisDisplayName.equalsIgnoreCase(comparingDisplayName)) {
303             return true;
304         } else {
305             return false;
306         }
307         
308     }
309     
310     /**
311      * Not only debug, also used to present the W/S node description in the
312      * Server Navigator
313      * @return W/S Info stuff: name, port, URL
314      */

315     public String JavaDoc toString() {
316         // return "Web Service Information - \n\tName: " + name + "\n\t Port number " + webServicePort + "\n\t URL " + wsdlUrl;
317
return "<html><b>Web Service Information</b>" + "" +
318         "<br><b>Name:</b> " + name +
319         "<br><b>Port number:</b> " + webServicePort +
320         "<br><b>URL:</b> " + wsdlUrl +
321         "<br><b>Address:</b> " + webServiceAddress +
322         "</html>"
323         ;
324     }
325     
326     
327     
328 }
Popular Tags