KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > WebService


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.deployment;
24
25 import java.util.Iterator JavaDoc;
26 import java.util.StringTokenizer JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30
31 import java.io.*;
32 import java.net.*;
33
34
35 /**
36  * Information about a single webservice-description in webservices.xml
37  *
38  * @author Kenneth Saks
39  * @author Jerome Dochez
40  */

41
42 public class WebService extends Descriptor {
43
44     private String JavaDoc wsdlFileUri;
45
46     /**
47      * Derived, non-peristent location of wsdl file.
48      * Only used at deployment/runtime.
49      */

50     private URL wsdlFileUrl;
51
52     private String JavaDoc mappingFileUri;
53
54     /**
55      * Derived, non-peristent location of mapping file.
56      * Only used at deployment/runtime.
57      */

58     private File mappingFile;
59
60     private HashMap JavaDoc<String JavaDoc, WebServiceEndpoint> endpoints;
61
62     // The set of web services to which this service belongs.
63
private WebServicesDescriptor webServicesDesc;
64
65     //
66
// Runtime info
67
//
68

69     // Optional file URL to which final wsdl should be published.
70
// This represents a directory on the file system from which deployment
71
// is initiated. URL schemes other than file: are legal but ignored.
72
private URL publishUrl;
73     
74     /**
75      * Default constructor.
76      */

77     public WebService() {
78         this("");
79     }
80
81     /**
82      * copy constructor.
83      */

84     public WebService(WebService other) {
85         super(other);
86     wsdlFileUri = other.wsdlFileUri; // String
87
wsdlFileUrl = other.wsdlFileUrl;
88     mappingFileUri = other.mappingFileUri; // String
89
mappingFile = other.mappingFile;
90         publishUrl = other.publishUrl;
91     webServicesDesc = other.webServicesDesc; // copy as-is
92
if (other.endpoints != null) {
93         endpoints = new HashMap JavaDoc<String JavaDoc, WebServiceEndpoint>();
94         for (WebServiceEndpoint wsep : other.endpoints.values()) {
95             wsep.setWebService(this);
96             endpoints.put(wsep.getEndpointName(), wsep);
97         }
98     } else {
99         endpoints = null;
100     }
101     }
102
103     public WebService(String JavaDoc name) {
104         setName(name);
105         endpoints = new HashMap JavaDoc();
106     }
107     
108     public void setWebServicesDescriptor(WebServicesDescriptor webServices) {
109         webServicesDesc = webServices;
110     }
111
112     public WebServicesDescriptor getWebServicesDescriptor() {
113         return webServicesDesc;
114     }
115
116     public BundleDescriptor getBundleDescriptor() {
117         return webServicesDesc.getBundleDescriptor();
118     }
119
120     public boolean hasWsdlFile() {
121         return (wsdlFileUri != null);
122     }
123
124     public void setWsdlFileUri(String JavaDoc uri) {
125         wsdlFileUri = uri;
126         super.changed();
127     }
128
129     public String JavaDoc getWsdlFileUri() {
130         if (wsdlFileUri==null && wsdlFileUrl!=null) {
131             // no wsdl file was provided but we generated one, we can
132
// return this path.
133
return getBundleDescriptor().getWsdlDir() + "/"
134                     + (new File(wsdlFileUrl.getFile())).getName();
135         }
136         return wsdlFileUri;
137     }
138
139     public URL getWsdlFileUrl() {
140         return wsdlFileUrl;
141     }
142
143     public void setWsdlFileUrl(URL url) {
144         wsdlFileUrl = url;
145         super.changed();
146     }
147     
148     public String JavaDoc getGeneratedWsdlFilePath() {
149         if (hasWsdlFile()) {
150             String JavaDoc xmlDir = getBundleDescriptor().getApplication().getGeneratedXMLDirectory();
151             if(!getBundleDescriptor().getModuleDescriptor().isStandalone()) {
152                 String JavaDoc uri = getBundleDescriptor().getModuleDescriptor().getArchiveUri();
153                 xmlDir = xmlDir + File.separator + uri.replaceAll("\\.", "_");
154             }
155             if(xmlDir == null) {
156                 return null;
157             }
158             return xmlDir + File.separator + wsdlFileUri;
159         } else {
160             return getWsdlFileUrl().getPath();
161         }
162     }
163     
164     public boolean hasMappingFile() {
165         return (mappingFileUri != null);
166     }
167
168     public void setMappingFileUri(String JavaDoc uri) {
169         mappingFileUri = uri;
170         super.changed();
171     }
172
173     public String JavaDoc getMappingFileUri() {
174         return mappingFileUri;
175     }
176
177     public File getMappingFile() {
178         return mappingFile;
179     }
180
181     public void setMappingFile(File file) {
182         mappingFile = file;
183         super.changed();
184     }
185
186     public void addEndpoint(WebServiceEndpoint endpoint) {
187         endpoint.setWebService(this);
188         endpoints.put(endpoint.getEndpointName(), endpoint);
189         super.changed();
190     }
191
192     public void removeEndpointByName(String JavaDoc endpointName) {
193         WebServiceEndpoint endpoint = (WebServiceEndpoint)
194             endpoints.remove(endpointName);
195         endpoint.setWebService(null);
196         super.changed();
197     }
198
199     public void removeEndpoint(WebServiceEndpoint endpoint) {
200         removeEndpointByName(endpoint.getEndpointName());
201         super.changed();
202     }
203
204     public Collection JavaDoc<WebServiceEndpoint> getEndpoints() {
205         HashMap JavaDoc shallowCopy = new HashMap JavaDoc(endpoints);
206         return shallowCopy.values();
207     }
208
209     public boolean hasClientPublishUrl() {
210         return (publishUrl != null);
211     }
212
213     public void setClientPublishUrl(URL url) {
214         publishUrl = url;
215         super.changed();
216     }
217
218     public URL getClientPublishUrl() {
219         return publishUrl;
220     }
221
222     public boolean hasUrlPublishing() {
223         return (!hasFilePublishing());
224     }
225
226     public boolean hasFilePublishing() {
227         return (hasClientPublishUrl() &&
228                 publishUrl.getProtocol().equals("file"));
229     }
230
231     /**
232      * Select one of this webservice's endpoints to use for converting
233      * relative imports.
234      */

235     public WebServiceEndpoint pickEndpointForRelativeImports() {
236         WebServiceEndpoint pick = null;
237
238         // First secure endpoint takes precedence.
239
for(WebServiceEndpoint wse : endpoints.values()) {
240             if( wse.isSecure() ) {
241                 pick = wse;
242                 break;
243             }
244             pick = wse;
245         }
246         return pick;
247     }
248
249     /**
250      * Returns a formatted String of the attributes of this object.
251      */

252     public void print(StringBuffer JavaDoc toStringBuffer) {
253     super.print(toStringBuffer);
254         toStringBuffer.append( "\n wsdl file : ").append( wsdlFileUri);
255         toStringBuffer.append( "\n mapping file ").append(mappingFileUri);
256         toStringBuffer.append( "\n publish url ").append(publishUrl);
257         toStringBuffer.append( "\n final wsdl ").append(wsdlFileUrl);
258         toStringBuffer.append( "\n endpoints ").append(endpoints);
259     }
260     
261 }
262
Popular Tags