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.jaxws.api;
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.j2ee.dd.api.webservices.WebservicesMetadata;
049: import org.netbeans.modules.j2ee.metadata.model.api.MetadataModel;
050: import org.netbeans.modules.websvc.jaxws.JAXWSSupportAccessor;
051: import org.netbeans.modules.websvc.jaxws.spi.JAXWSSupportImpl;
052: import org.netbeans.modules.websvc.jaxws.spi.JAXWSSupportProvider;
053: import org.netbeans.spi.project.support.ant.AntProjectHelper;
054: import org.openide.filesystems.FileObject;
055: import org.openide.util.Lookup;
056:
057: /** JAXWSSupport should be used to manipulate projects representations
058: * of JAX-WS services.
059: * <p>
060: * A client may obtain a JAXWSSupport instance using
061: * <code>JAXWSSupport.getJAXWSSupport(fileObject)</code> static
062: * method, for any FileObject in the project directory structure.
063: *
064: * @author Peter Williams, Milan Kuchtiak
065: */
066: public final class JAXWSSupport {
067:
068: private JAXWSSupportImpl impl;
069: private static final Lookup.Result<JAXWSSupportProvider> implementations = Lookup
070: .getDefault().lookup(
071: new Lookup.Template<JAXWSSupportProvider>(
072: JAXWSSupportProvider.class));
073:
074: static {
075: JAXWSSupportAccessor.DEFAULT = new JAXWSSupportAccessor() {
076: public JAXWSSupport createJAXWSSupport(
077: JAXWSSupportImpl spiWebServicesSupport) {
078: return new JAXWSSupport(spiWebServicesSupport);
079: }
080:
081: public JAXWSSupportImpl getJAXWSSupportImpl(JAXWSSupport wss) {
082: return wss == null ? null : wss.impl;
083: }
084: };
085: }
086:
087: private JAXWSSupport(JAXWSSupportImpl impl) {
088: if (impl == null)
089: throw new IllegalArgumentException();
090: this .impl = impl;
091: }
092:
093: /** Find the JAXWSSupport for given file or null if the file does not belong
094: * to any module support web services.
095: */
096: public static JAXWSSupport getJAXWSSupport(FileObject f) {
097: if (f == null) {
098: throw new NullPointerException(
099: "Passed null to JAXWSSupport.getJAXWSSupport(FileObject)"); // NOI18N
100: }
101: Iterator it = implementations.allInstances().iterator();
102: while (it.hasNext()) {
103: JAXWSSupportProvider supportProvider = (JAXWSSupportProvider) it
104: .next();
105: JAXWSSupport wss = supportProvider.findJAXWSSupport(f);
106: if (wss != null) {
107: return wss;
108: }
109: }
110: return null;
111: }
112:
113: // Delegated methods from WebServicesSupportImpl
114:
115: /**
116: * Add web service to jax-ws.xml intended for web services from java
117: * @param serviceName service display name (name of the node ws will be presented in Netbeans), e.g. "SearchService"
118: * @param serviceImpl package name of the implementation class, e.g. "org.netbeans.SerchServiceImpl"
119: * @param isJsr109 Indicates if the web service is being created in a project that supports a JSR 109 container
120: */
121: public void addService(String serviceName, String serviceImpl,
122: boolean isJsr109) {
123: impl.addService(serviceName, serviceImpl, isJsr109);
124: }
125:
126: /** Add web service to jax-ws.xml
127: * intended for web services from wsdl
128: * @param name service display name (name of the node ws will be presented in Netbeans), e.g. "SearchService"
129: * @param serviceImpl package name of the implementation class, e.g. "org.netbeans.SerchServiceImpl"
130: * @param wsdlUrl url of the local wsdl file, e.g. file:/home/userXY/documents/wsdl/SearchService.wsdl"
131: * @param serviceName service name (from service wsdl element), e.g. SearchService
132: * @param portName port name (from service:port element), e.g. SearchServicePort
133: * @param packageName package name where java artifacts will be generated
134: * @param isJsr109 Indicates if the web service is being created in a project that supports a JSR 109 container
135: * @param useProvider Indicates if we should generate a Provider implementation
136: * @return returns the unique IDE service name
137: */
138: public String addService(String name, String serviceImpl,
139: String wsdlUrl, String serviceName, String portName,
140: String packageName, boolean isJsr109, boolean useProvider) {
141: return impl.addService(name, serviceImpl, wsdlUrl, serviceName,
142: portName, packageName, isJsr109, useProvider);
143: }
144:
145: /**
146: * Returns the list of web services in the project
147: * @return list of web services
148: */
149: public List getServices() {
150: return impl.getServices();
151: }
152:
153: /**
154: * Remove the web service entries from the project properties
155: * @param serviceName service IDE name
156: * project.xml files
157: */
158: public void removeService(String serviceName) {
159: impl.removeService(serviceName);
160: }
161:
162: /**
163: * Notification when Service (created from java) is removed from jax-ws.xml
164: * (JAXWSSupport needs to react when @WebService annotation is removed
165: * or when impl.class is removed (manually from project)
166: * @param serviceName service IDE name
167: */
168: public void serviceFromJavaRemoved(String serviceName) {
169: impl.serviceFromJavaRemoved(serviceName);
170: }
171:
172: /** Get the name of the implementation class
173: * given the service (ide) name
174: * @param serviceName service IDE name
175: * @return service implementation class package name
176: */
177: public String getServiceImpl(String serviceName) {
178: return impl.getServiceImpl(serviceName);
179: }
180:
181: /** Determine if the web service was created from WSDL
182: * @param serviceName service name
183: */
184: public boolean isFromWSDL(String serviceName) {
185: return impl.isFromWSDL(serviceName);
186: }
187:
188: /** Get WSDL folder for the project (folder containing wsdl files)
189: * The folder is used to save remote or local wsdl files to be available within the jar/war files.
190: * it is usually META-INF/wsdl folder (or WEB-INF/wsdl for web application)
191: * @param createFolder if (createFolder==true) the folder will be created (if not created before)
192: * @return the file object (folder) where wsdl files are located in project
193: */
194: public FileObject getWsdlFolder(boolean create)
195: throws java.io.IOException {
196: return impl.getWsdlFolder(create);
197: }
198:
199: /** Get folder for local WSDL and XML artifacts for given service
200: * This is the location where wsdl/xml files are downloaded to the project.
201: * JAX-WS java artifacts will be generated from these local files instead of remote.
202: * @param serviceName service IDE name (the web service node display name)
203: * @param createFolder if (createFolder==true) the folder will be created (if not created before)
204: * @return the file object (folder) where wsdl files are located in project
205: */
206: public FileObject getLocalWsdlFolderForService(String serviceName,
207: boolean createFolder) {
208: return impl.getLocalWsdlFolderForService(serviceName,
209: createFolder);
210: }
211:
212: /** Get folder for local jaxb binding (xml) files for given service
213: * This is the location where external jaxb binding files are downloaded to the project.
214: * JAX-WS java artifacts will be generated using these local binding files instead of remote.
215: * @param serviceName service IDE name (the web service node display name)
216: * @param createFolder if (createFolder==true) the folder will be created (if not created before)
217: * @return the file object (folder) where jaxb binding files are located in project
218: */
219: public FileObject getBindingsFolderForService(String serviceName,
220: boolean createFolder) {
221: return impl.getBindingsFolderForService(serviceName,
222: createFolder);
223: }
224:
225: /**
226: * Get the AntProjectHelper from the project
227: */
228: public AntProjectHelper getAntProjectHelper() {
229: return impl.getAntProjectHelper();
230: }
231:
232: /** Get EntityCatalog for local copies of wsdl and schema files
233: */
234: public URL getCatalog() {
235: return impl.getCatalog();
236: }
237:
238: /** Get wsdlLocation information
239: * Useful for web service from wsdl (the @WebService wsdlLocation attribute)
240: * @param serviceName service "display" name
241: */
242: public String getWsdlLocation(String serviceName) {
243: return impl.getWsdlLocation(serviceName);
244: }
245:
246: /**
247: * Remove all entries associated with a non-JSR 109 entries
248: * This may include entries in the module's deployment descriptor,
249: * and entries in the implementation-specific descriptor file, sun-jaxws.xml.
250: * This is provided as a service so that the node can also use it for cleanup.
251: */
252: public void removeNonJsr109Entries(String serviceName)
253: throws IOException {
254: impl.removeNonJsr109Entries(serviceName);
255: }
256:
257: /**
258: * Returns the directory that contains the deployment descriptor in the project
259: */
260: public FileObject getDeploymentDescriptorFolder() {
261: return impl.getDeploymentDescriptorFolder();
262: }
263:
264: /**
265: * Returns a metadata model of a webservices deployment descriptor
266: *
267: * @return metadata model of a webservices deployment descriptor
268: */
269: public MetadataModel<WebservicesMetadata> getWebservicesMetadataModel() {
270: return impl.getWebservicesMetadataModel();
271: }
272: }
|