KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > api > client > WebServicesClientSupport


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.api.client;
21
22 import java.io.IOException JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.openide.filesystems.FileObject;
27 import org.openide.util.Lookup;
28
29 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl;
30 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportProvider;
31 import org.netbeans.modules.websvc.client.WebServicesClientSupportAccessor;
32
33 /** WebServicesClientSupport should be used to manipulate a projects representation
34  * of a web service implementation.
35  * <p>
36  * A client may obtain a WebServicesClientSupport instance using
37  * <code>WebServicesClientSupport.getWebServicesClientSupport(fileObject)</code> static
38  * method, for any FileObject in the project directory structure.
39  *
40  * @author Peter Williams
41  */

42 public final class WebServicesClientSupport {
43     
44     public static final String JavaDoc WSCLIENTUPTODATE_CLASSPATH = "wsclientuptodate.classpath";
45
46     private WebServicesClientSupportImpl impl;
47     private static final Lookup.Result implementations =
48         Lookup.getDefault().lookup(new Lookup.Template(WebServicesClientSupportProvider.class));
49
50     static {
51         WebServicesClientSupportAccessor.DEFAULT = new WebServicesClientSupportAccessor() {
52             public WebServicesClientSupport createWebServicesClientSupport(WebServicesClientSupportImpl spiWebServicesClientSupport) {
53                 return new WebServicesClientSupport(spiWebServicesClientSupport);
54             }
55
56             public WebServicesClientSupportImpl getWebServicesClientSupportImpl(WebServicesClientSupport wscs) {
57                 return wscs == null ? null : wscs.impl;
58             }
59         };
60     }
61
62     private WebServicesClientSupport(WebServicesClientSupportImpl impl) {
63         if (impl == null)
64             throw new IllegalArgumentException JavaDoc ();
65         this.impl = impl;
66     }
67
68     /** Find the WebServicesClientSupport for given file or null if the file does
69      * not belong to any module supporting web service clients.
70      */

71     public static WebServicesClientSupport getWebServicesClientSupport (FileObject f) {
72         if (f == null) {
73             throw new NullPointerException JavaDoc("Passed null to WebServicesClientSupport.getWebServicesClientSupport(FileObject)"); // NOI18N
74
}
75         Iterator JavaDoc it = implementations.allInstances().iterator();
76         while (it.hasNext()) {
77             WebServicesClientSupportProvider impl = (WebServicesClientSupportProvider)it.next();
78             WebServicesClientSupport wscs = impl.findWebServicesClientSupport (f);
79             if (wscs != null) {
80                 return wscs;
81             }
82         }
83         return null;
84     }
85
86     // Delegated methods from WebServicesClientSupportImpl
87

88     /** Adds a service client to the module represented by this support object.
89      *
90      * 1. Add appropriate entries to project.xml and project.properties to add
91      * this service client to the build. Web/project implementation added
92      * wscompile targets directly to the build-impl.xsl script and adds some
93      * entries to project.xml to drive those fragments.
94      * 2. Regenerate build-impl.xml (For web/project, this happens automatically
95      * when the modified project.xml/project.properties is saved.)
96      * 3. Add J2EE Platform support
97      * 4. Code completion source registration for generated interface files? (So
98      * the user can type "TemperatureService." and have the list of port methods
99      * show up.) This was implemented independent of web services by adding
100      * the build.classes.dir to the SourceForBinaryQuery classpath.
101      * 5. DELETED add service-ref to module deployment descriptor
102      *
103      * @param serviceName name of this service (as specified in wsdl file.)
104      * @param configFile config file for use by wscompile target
105      */

106     public void addServiceClient(String JavaDoc serviceName, String JavaDoc packageName, String JavaDoc sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor) {
107         impl.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor);
108     }
109
110     public void addServiceClient(String JavaDoc serviceName, String JavaDoc packageName, String JavaDoc sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor, String JavaDoc[] wscompileFeatures) {
111         impl.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor, wscompileFeatures);
112     }
113     
114     /** Adds a service-ref to module deployment descriptor.
115      *
116      * @param serviceName name of this service, e.g. service/MyService
117      * @param fqServiceName fully qualified service classname
118      * @param relativeWsdlPath relative path (according to archive root) to wsdl (e.g. WEB-INF/wsdl/weather.wsdl)
119      * @param mappingPath relative path (according to archive root) to mapping file (e.g. WEB-INF/weather-mapping.xml)
120      * @param portSEIInfo array of serviceEndpointInterface names used to fill PortRefArray under ServiceRef element
121      */

122     public void addServiceClientReference(String JavaDoc serviceName, String JavaDoc fqServiceName, String JavaDoc relativeWsdlPath, String JavaDoc mappingPath, String JavaDoc[] portSEIInfo) {
123         impl.addServiceClientReference(serviceName, fqServiceName, relativeWsdlPath, mappingPath, portSEIInfo);
124     }
125     
126     /** Removes a service client from the module represented by this support object.
127      *
128      * 1. Removes everything associated with this service that was added in
129      * addServiceClient, assuming it is not needed by another service client.
130      * 2. Anything specific only to this service should be removed.
131      * 3. Anything specific to web service clients in general should be removed
132      * if there are no other clients, e.g. library support.
133      * 4. Note there are a few items that are shared between web service
134      * implementations and web service clients. These items should only be
135      * removed if there are no services OR clients in the project after this
136      * action is performed.
137      *
138      * @param serviceName name of this service (as specified in wsdl file).
139      */

140     public void removeServiceClient(String JavaDoc serviceName) {
141         impl.removeServiceClient(serviceName);
142     }
143
144     /** Get the WSDL folder (where WSDL files are to be stored) for this module.
145      *
146      * 1. Return the source folder where wsdl files for the services used by the
147      * client are to be stored. For web project, this is WEB-INF/wsdl
148      * 2. Should this method return a higher level folder type? (if so, what
149      * would that type be? DataFolder?)
150      * 3. Note that this is referring to the source folder, thus allowing freeform
151      * project to let the user set this if they want. For the build directory,
152      * wsdl location is enforced by J2EE 1.4 container to be WEB-INF/wsdl or
153      * META-INF/wsdl.
154      *
155      * @param create set to true if the folder should be created if it does not exist.
156      * @return FileObject representing this folder.
157      * @exception IOException if there is a problem accessing or creating the folder
158      */

159     public FileObject getWsdlFolder(boolean create) throws IOException JavaDoc {
160         return impl.getWsdlFolder(create);
161     }
162
163     /** Get the WSDL folder (where WSDL files are to be stored) for this module.
164      *
165      * @return FileObject representing this folder or null if the folder does not
166      * exist. The folder will not be created in this case.
167      */

168     public FileObject getWsdlFolder() {
169         FileObject result = null;
170
171         try {
172             result = impl.getWsdlFolder(false);
173         } catch(IOException JavaDoc ex) {
174             // This won't happen because we're passing false for the create flag.
175
}
176
177         return result;
178     }
179
180     /** Retrieves a handle to the general deployment descriptor file (web.xml,
181      * ejbjar.xml) for this module if such file exists.
182      *
183      * 1. Returns the deployment descriptor file, if any, for this module. For
184      * web, this is web.xml. For ejb, this is ejb-jar.xml. If no deployment
185      * descriptor exists, this method should return null. This method is used
186      * by the web service client core code to add a service-ref for the new
187      * client. This only applies to Web and Ejb hosted JSR-109 service clients.
188      *
189      * NOTE: The name of this method will likely change for EA2.
190      *
191      * @return FileObject of the web.xml or ejbjar.xml descriptor file. If the
192      * module in question is not a J2EE module (e.g. J2SE client), this method
193      * should return null.
194      */

195     public FileObject getDeploymentDescriptor() {
196         return impl.getDeploymentDescriptor();
197     }
198
199     public List JavaDoc/*StubDescriptor*/ getStubDescriptors() {
200         return impl.getStubDescriptors();
201     }
202
203     public List JavaDoc/*WsCompileEditorSupport.ServiceSettings*/ getServiceClients() {
204         return impl.getServiceClients();
205     }
206
207     public String JavaDoc getWsdlSource(String JavaDoc serviceName) {
208         return impl.getWsdlSource(serviceName);
209     }
210
211     public void setWsdlSource(String JavaDoc serviceName, String JavaDoc wsdlSource) {
212         impl.setWsdlSource(serviceName, wsdlSource);
213     }
214     
215     public void setProxyJVMOptions(String JavaDoc proxyHost, String JavaDoc proxyPort) {
216         impl.setProxyJVMOptions(proxyHost, proxyPort);
217     }
218     
219     public String JavaDoc getServiceRefName(String JavaDoc serviceName){
220         return impl.getServiceRefName(serviceName);
221     }
222
223 /* !PW FIXME What to put here? (commented code came from WebModule API)
224  *
225     public boolean equals (Object obj) {
226         if (!WebModule.class.isAssignableFrom(obj.getClass()))
227             return false;
228         WebModule wm = (WebModule) obj;
229         return getDocumentBase().equals(wm.getDocumentBase())
230             && getJ2eePlatformVersion().equals (wm.getJ2eePlatformVersion())
231             && getContextPath().equals(wm.getContextPath());
232     }
233
234     public int hashCode () {
235         return getDocumentBase ().getPath ().length () + getContextPath ().length ();
236     }
237  */

238 }
Popular Tags