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.jaxws.client;
043:
044: import java.io.IOException;
045: import java.net.URL;
046: import java.util.Iterator;
047: import java.util.List;
048: import org.netbeans.modules.websvc.jaxws.client.JAXWSClientSupportAccessor;
049: import org.netbeans.modules.websvc.spi.jaxws.client.JAXWSClientSupportImpl;
050:
051: import org.openide.filesystems.FileObject;
052: import org.openide.util.Lookup;
053: import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportProvider;
054: import org.openide.nodes.Node;
055:
056: /** JAXWSClientSupport should be used to manipulate representations
057: * of JAX-WS service references (WS Clients) in a project.
058: * <p>
059: * A client may obtain a JAXWSClientSupport instance using
060: * <code>JAXWSClientSupport.getJAXWSClientSupport(fileObject)</code> static
061: * method, for any FileObject in the project directory structure.
062: *
063: * @author Peter Williams
064: */
065: public final class JAXWSClientSupport {
066:
067: private JAXWSClientSupportImpl impl;
068: private static final Lookup.Result implementations = Lookup
069: .getDefault().lookup(
070: new Lookup.Template(
071: WebServicesClientSupportProvider.class));
072:
073: static {
074: JAXWSClientSupportAccessor.DEFAULT = new JAXWSClientSupportAccessor() {
075: public JAXWSClientSupport createJAXWSClientSupport(
076: JAXWSClientSupportImpl spiWebServicesClientSupport) {
077: return new JAXWSClientSupport(
078: spiWebServicesClientSupport);
079: }
080:
081: public JAXWSClientSupportImpl getJAXWSClientSupportImpl(
082: JAXWSClientSupport wscs) {
083: return wscs == null ? null : wscs.impl;
084: }
085: };
086: }
087:
088: private JAXWSClientSupport(JAXWSClientSupportImpl impl) {
089: if (impl == null)
090: throw new IllegalArgumentException();
091: this .impl = impl;
092: }
093:
094: /** Find the JAXWSClientSupport for given file or null if the file does
095: * not belong to any module supporting JAX-WS service clients.
096: */
097: public static JAXWSClientSupport getJaxWsClientSupport(FileObject f) {
098: if (f == null) {
099: throw new NullPointerException(
100: "Passed null to JAXWSClientSupport.getJAXWSClientSupport(FileObject)"); // NOI18N
101: }
102: Iterator it = implementations.allInstances().iterator();
103: while (it.hasNext()) {
104: WebServicesClientSupportProvider impl = (WebServicesClientSupportProvider) it
105: .next();
106: JAXWSClientSupport wscs = impl.findJAXWSClientSupport(f);
107: if (wscs != null) {
108: return wscs;
109: }
110: }
111: return null;
112: }
113:
114: // Delegated methods from JAXWSClientSupportImpl
115:
116: /** Add JAX-WS Client to project.
117: * <ul>
118: * <li> add client element to jax-ws.xml (Netbeans specific configuration file)
119: * <li> download the wsdl file(s) and all related XML artifacts to the project
120: * <li> generate JAX-WS artifacts for web service specified by wsdlUrl.
121: * <li> this can be achieved by creating specific target in build-impl.xml, that calls wsimport task.
122: * </ul>
123: * @param clientName proposed name for the client (the web service reference node display name)
124: * @param wsdlURL URL for web service WSDL file
125: * @param isJsr109 flag indicating the need to add JAX-WS libraries to project:
126: * if (isJsr109==false) JAX-WS libraries should be added to the project classpath
127: * @return unique name for WS Client in the project(can be different than requested clientName)
128: */
129: public String addServiceClient(String serviceName, String wsdlUrl,
130: String packageName, boolean isJsr109) {
131: return impl.addServiceClient(serviceName, wsdlUrl, packageName,
132: isJsr109);
133: }
134:
135: /** Remove JAX-WS Client from project.
136: * <ul>
137: * <li> remove client element from jax-ws.xml (Netbeans specific configuration file)
138: * <li> remove all WSDL/XML artifacts related to this client
139: * <li> remove all JAX-WS java artifacts generated for this client
140: * </ul>
141: * @param clientName client name (the web service reference node display name)
142: */
143: public void removeServiceClient(String serviceName) {
144: impl.removeServiceClient(serviceName);
145: }
146:
147: /** Get WSDL folder for the project (folder containing wsdl files)
148: * The folder is used to save remote or local wsdl files to be available within the jar/war files.
149: * it is usually META-INF/wsdl folder (or WEB-INF/wsdl for web application)
150: * @param createFolder if (createFolder==true) the folder will be created (if not created before)
151: * @return the file object (folder) where wsdl files are located in project
152: */
153: public FileObject getWsdlFolder(boolean create) throws IOException {
154: return impl.getWsdlFolder(create);
155: }
156:
157: /** Get folder for local WSDL and XML artifacts for given client
158: * This is the location where wsdl/xml files are downloaded to the project.
159: * JAX-WS java artifacts will be generated from these local files instead of remote.
160: * @param clientName client name (the web service reference node display name)
161: * @param createFolder if (createFolder==true) the folder will be created (if not created before)
162: * @return the file object (folder) where wsdl files are located in project
163: */
164: public FileObject getLocalWsdlFolderForClient(String clientName,
165: boolean createFolder) {
166: return impl.getLocalWsdlFolderForClient(clientName,
167: createFolder);
168: }
169:
170: /** Get folder for local jaxb binding (xml) files for given client
171: * This is the location where external jaxb binding files are downloaded to the project.
172: * JAX-WS java artifacts will be generated using these local binding files instead of remote.
173: * @param clientName client name (the web service reference node display name)
174: * @param createFolder if (createFolder==true) the folder will be created (if not created before)
175: * @return the file object (folder) where jaxb binding files are located in project
176: */
177: public FileObject getBindingsFolderForClient(String clientName,
178: boolean createFolder) {
179: return impl
180: .getBindingsFolderForClient(clientName, createFolder);
181: }
182:
183: /** gets the URL of catalog.xml file
184: * (the catalog is used by wsimport to locate local wsdl/xml resources)
185: * @return URL url of the car
186: */
187: public URL getCatalog() {
188: return impl.getCatalog();
189: }
190:
191: /** Get list of all JAX-WS Clients in project
192: * @param clientName client name (the web service reference node display name)
193: */
194: public List/*Client*/getServiceClients() {
195: return impl.getServiceClients();
196: }
197:
198: /** intended to be used to obtain service-ref name for given web service reference
199: * (currently not used in projects)
200: */
201: public String getServiceRefName(Node clientNode) {
202: return impl.getServiceRefName(clientNode);
203: }
204: }
|