001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.websvc.api.client;
043:
044: import java.io.IOException;
045: import java.util.Iterator;
046: import java.util.List;
047:
048: import org.openide.filesystems.FileObject;
049: import org.openide.util.Lookup;
050:
051: import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl;
052: import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportProvider;
053: import org.netbeans.modules.websvc.client.WebServicesClientSupportAccessor;
054:
055: /** WebServicesClientSupport should be used to manipulate a projects representation
056: * of a web service implementation.
057: * <p>
058: * A client may obtain a WebServicesClientSupport instance using
059: * <code>WebServicesClientSupport.getWebServicesClientSupport(fileObject)</code> static
060: * method, for any FileObject in the project directory structure.
061: *
062: * @author Peter Williams
063: */
064: public final class WebServicesClientSupport {
065:
066: public static final String WSCLIENTUPTODATE_CLASSPATH = "wsclientuptodate.classpath";
067:
068: private WebServicesClientSupportImpl impl;
069: private static final Lookup.Result implementations = Lookup
070: .getDefault().lookup(
071: new Lookup.Template(
072: WebServicesClientSupportProvider.class));
073:
074: static {
075: WebServicesClientSupportAccessor.DEFAULT = new WebServicesClientSupportAccessor() {
076: public WebServicesClientSupport createWebServicesClientSupport(
077: WebServicesClientSupportImpl spiWebServicesClientSupport) {
078: return new WebServicesClientSupport(
079: spiWebServicesClientSupport);
080: }
081:
082: public WebServicesClientSupportImpl getWebServicesClientSupportImpl(
083: WebServicesClientSupport wscs) {
084: return wscs == null ? null : wscs.impl;
085: }
086: };
087: }
088:
089: private WebServicesClientSupport(WebServicesClientSupportImpl impl) {
090: if (impl == null)
091: throw new IllegalArgumentException();
092: this .impl = impl;
093: }
094:
095: /** Find the WebServicesClientSupport for given file or null if the file does
096: * not belong to any module supporting web service clients.
097: */
098: public static WebServicesClientSupport getWebServicesClientSupport(
099: FileObject f) {
100: if (f == null) {
101: throw new NullPointerException(
102: "Passed null to WebServicesClientSupport.getWebServicesClientSupport(FileObject)"); // NOI18N
103: }
104: Iterator it = implementations.allInstances().iterator();
105: while (it.hasNext()) {
106: WebServicesClientSupportProvider impl = (WebServicesClientSupportProvider) it
107: .next();
108: WebServicesClientSupport wscs = impl
109: .findWebServicesClientSupport(f);
110: if (wscs != null) {
111: return wscs;
112: }
113: }
114: return null;
115: }
116:
117: // Delegated methods from WebServicesClientSupportImpl
118:
119: /** Adds a service client to the module represented by this support object.
120: *
121: * 1. Add appropriate entries to project.xml and project.properties to add
122: * this service client to the build. Web/project implementation added
123: * wscompile targets directly to the build-impl.xsl script and adds some
124: * entries to project.xml to drive those fragments.
125: * 2. Regenerate build-impl.xml (For web/project, this happens automatically
126: * when the modified project.xml/project.properties is saved.)
127: * 3. Add J2EE Platform support
128: * 4. Code completion source registration for generated interface files? (So
129: * the user can type "TemperatureService." and have the list of port methods
130: * show up.) This was implemented independent of web services by adding
131: * the build.classes.dir to the SourceForBinaryQuery classpath.
132: * 5. DELETED add service-ref to module deployment descriptor
133: *
134: * @param serviceName name of this service (as specified in wsdl file.)
135: * @param configFile config file for use by wscompile target
136: */
137: public void addServiceClient(String serviceName,
138: String packageName, String sourceUrl,
139: FileObject configFile, ClientStubDescriptor stubDescriptor) {
140: impl.addServiceClient(serviceName, packageName, sourceUrl,
141: configFile, stubDescriptor);
142: }
143:
144: public void addServiceClient(String serviceName,
145: String packageName, String sourceUrl,
146: FileObject configFile, ClientStubDescriptor stubDescriptor,
147: String[] wscompileFeatures) {
148: impl.addServiceClient(serviceName, packageName, sourceUrl,
149: configFile, stubDescriptor, wscompileFeatures);
150: }
151:
152: /** Adds a service-ref to module deployment descriptor.
153: *
154: * @param serviceName name of this service, e.g. service/MyService
155: * @param fqServiceName fully qualified service classname
156: * @param relativeWsdlPath relative path (according to archive root) to wsdl (e.g. WEB-INF/wsdl/weather.wsdl)
157: * @param mappingPath relative path (according to archive root) to mapping file (e.g. WEB-INF/weather-mapping.xml)
158: * @param portSEIInfo array of serviceEndpointInterface names used to fill PortRefArray under ServiceRef element
159: */
160: public void addServiceClientReference(String serviceName,
161: String fqServiceName, String relativeWsdlPath,
162: String mappingPath, String[] portSEIInfo) {
163: impl.addServiceClientReference(serviceName, fqServiceName,
164: relativeWsdlPath, mappingPath, portSEIInfo);
165: }
166:
167: /** Removes a service client from the module represented by this support object.
168: *
169: * 1. Removes everything associated with this service that was added in
170: * addServiceClient, assuming it is not needed by another service client.
171: * 2. Anything specific only to this service should be removed.
172: * 3. Anything specific to web service clients in general should be removed
173: * if there are no other clients, e.g. library support.
174: * 4. Note there are a few items that are shared between web service
175: * implementations and web service clients. These items should only be
176: * removed if there are no services OR clients in the project after this
177: * action is performed.
178: *
179: * @param serviceName name of this service (as specified in wsdl file).
180: */
181: public void removeServiceClient(String serviceName) {
182: impl.removeServiceClient(serviceName);
183: }
184:
185: /** Get the WSDL folder (where WSDL files are to be stored) for this module.
186: *
187: * 1. Return the source folder where wsdl files for the services used by the
188: * client are to be stored. For web project, this is WEB-INF/wsdl
189: * 2. Should this method return a higher level folder type? (if so, what
190: * would that type be? DataFolder?)
191: * 3. Note that this is referring to the source folder, thus allowing freeform
192: * project to let the user set this if they want. For the build directory,
193: * wsdl location is enforced by J2EE 1.4 container to be WEB-INF/wsdl or
194: * META-INF/wsdl.
195: *
196: * @param create set to true if the folder should be created if it does not exist.
197: * @return FileObject representing this folder.
198: * @exception IOException if there is a problem accessing or creating the folder
199: */
200: public FileObject getWsdlFolder(boolean create) throws IOException {
201: return impl.getWsdlFolder(create);
202: }
203:
204: /** Get the WSDL folder (where WSDL files are to be stored) for this module.
205: *
206: * @return FileObject representing this folder or null if the folder does not
207: * exist. The folder will not be created in this case.
208: */
209: public FileObject getWsdlFolder() {
210: FileObject result = null;
211:
212: try {
213: result = impl.getWsdlFolder(false);
214: } catch (IOException ex) {
215: // This won't happen because we're passing false for the create flag.
216: }
217:
218: return result;
219: }
220:
221: /** Retrieves a handle to the general deployment descriptor file (web.xml,
222: * ejbjar.xml) for this module if such file exists.
223: *
224: * 1. Returns the deployment descriptor file, if any, for this module. For
225: * web, this is web.xml. For ejb, this is ejb-jar.xml. If no deployment
226: * descriptor exists, this method should return null. This method is used
227: * by the web service client core code to add a service-ref for the new
228: * client. This only applies to Web and Ejb hosted JSR-109 service clients.
229: *
230: * NOTE: The name of this method will likely change for EA2.
231: *
232: * @return FileObject of the web.xml or ejbjar.xml descriptor file. If the
233: * module in question is not a J2EE module (e.g. J2SE client), this method
234: * should return null.
235: */
236: public FileObject getDeploymentDescriptor() {
237: return impl.getDeploymentDescriptor();
238: }
239:
240: public List/*StubDescriptor*/getStubDescriptors() {
241: return impl.getStubDescriptors();
242: }
243:
244: public List/*WsCompileEditorSupport.ServiceSettings*/getServiceClients() {
245: return impl.getServiceClients();
246: }
247:
248: public String getWsdlSource(String serviceName) {
249: return impl.getWsdlSource(serviceName);
250: }
251:
252: public void setWsdlSource(String serviceName, String wsdlSource) {
253: impl.setWsdlSource(serviceName, wsdlSource);
254: }
255:
256: public void setProxyJVMOptions(String proxyHost, String proxyPort) {
257: impl.setProxyJVMOptions(proxyHost, proxyPort);
258: }
259:
260: public String getServiceRefName(String serviceName) {
261: return impl.getServiceRefName(serviceName);
262: }
263:
264: /* !PW FIXME What to put here? (commented code came from WebModule API)
265: *
266: public boolean equals (Object obj) {
267: if (!WebModule.class.isAssignableFrom(obj.getClass()))
268: return false;
269: WebModule wm = (WebModule) obj;
270: return getDocumentBase().equals(wm.getDocumentBase())
271: && getJ2eePlatformVersion().equals (wm.getJ2eePlatformVersion())
272: && getContextPath().equals(wm.getContextPath());
273: }
274:
275: public int hashCode () {
276: return getDocumentBase ().getPath ().length () + getContextPath ().length ();
277: }
278: */
279: }
|