KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > api > jaxws > client > JAXWSClientSupport


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.jaxws.client;
21
22 import java.io.IOException JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import org.netbeans.modules.websvc.jaxws.client.JAXWSClientSupportAccessor;
27 import org.netbeans.modules.websvc.spi.jaxws.client.JAXWSClientSupportImpl;
28
29 import org.openide.filesystems.FileObject;
30 import org.openide.util.Lookup;
31 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportProvider;
32 import org.openide.nodes.Node;
33
34 /** JAXWSClientSupport should be used to manipulate representations
35  * of JAX-WS service references (WS Clients) in a project.
36  * <p>
37  * A client may obtain a JAXWSClientSupport instance using
38  * <code>JAXWSClientSupport.getJAXWSClientSupport(fileObject)</code> static
39  * method, for any FileObject in the project directory structure.
40  *
41  * @author Peter Williams
42  */

43 public final class JAXWSClientSupport {
44     
45     private JAXWSClientSupportImpl impl;
46     private static final Lookup.Result implementations =
47         Lookup.getDefault().lookup(new Lookup.Template(WebServicesClientSupportProvider.class));
48
49     static {
50         JAXWSClientSupportAccessor.DEFAULT = new JAXWSClientSupportAccessor() {
51             public JAXWSClientSupport createJAXWSClientSupport(JAXWSClientSupportImpl spiWebServicesClientSupport) {
52                 return new JAXWSClientSupport(spiWebServicesClientSupport);
53             }
54
55             public JAXWSClientSupportImpl getJAXWSClientSupportImpl(JAXWSClientSupport wscs) {
56                 return wscs == null ? null : wscs.impl;
57             }
58         };
59     }
60
61     private JAXWSClientSupport(JAXWSClientSupportImpl impl) {
62         if (impl == null)
63             throw new IllegalArgumentException JavaDoc ();
64         this.impl = impl;
65     }
66
67     /** Find the JAXWSClientSupport for given file or null if the file does
68      * not belong to any module supporting JAX-WS service clients.
69      */

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

87     /** Add JAX-WS Client to project.
88      * <ul>
89      * <li> add client element to jax-ws.xml (Netbeans specific configuration file)
90      * <li> download the wsdl file(s) and all related XML artifacts to the project
91      * <li> generate JAX-WS artifacts for web service specified by wsdlUrl.
92      * <li> this can be achieved by creating specific target in build-impl.xml, that calls wsimport task.
93      * </ul>
94      * @param clientName proposed name for the client (the web service reference node display name)
95      * @param wsdlURL URL for web service WSDL file
96      * @param isJsr109 flag indicating the need to add JAX-WS libraries to project:
97      * if (isJsr109==false) JAX-WS libraries should be added to the project classpath
98      * @return unique name for WS Client in the project(can be different than requested clientName)
99      */

100     public String JavaDoc addServiceClient(String JavaDoc serviceName, String JavaDoc wsdlUrl, String JavaDoc packageName, boolean isJsr109) {
101         return impl.addServiceClient(serviceName, wsdlUrl, packageName, isJsr109);
102     }
103     
104     
105     /** Remove JAX-WS Client from project.
106      * <ul>
107      * <li> remove client element from jax-ws.xml (Netbeans specific configuration file)
108      * <li> remove all WSDL/XML artifacts related to this client
109      * <li> remove all JAX-WS java artifacts generated for this client
110      * </ul>
111      * @param clientName client name (the web service reference node display name)
112      */

113     public void removeServiceClient(String JavaDoc serviceName) {
114         impl.removeServiceClient(serviceName);
115     }
116
117     /** Get WSDL folder for the project (folder containing wsdl files)
118      * The folder is used to save remote or local wsdl files to be available within the jar/war files.
119      * it is usually META-INF/wsdl folder (or WEB-INF/wsdl for web application)
120      * @param createFolder if (createFolder==true) the folder will be created (if not created before)
121      * @return the file object (folder) where wsdl files are located in project
122      */

123     public FileObject getWsdlFolder(boolean create) throws IOException JavaDoc {
124         return impl.getWsdlFolder(create);
125     }
126     
127     /** Get folder for local WSDL and XML artifacts for given client
128      * This is the location where wsdl/xml files are downloaded to the project.
129      * JAX-WS java artifacts will be generated from these local files instead of remote.
130      * @param clientName client name (the web service reference node display name)
131      * @param createFolder if (createFolder==true) the folder will be created (if not created before)
132      * @return the file object (folder) where wsdl files are located in project
133      */

134     public FileObject getLocalWsdlFolderForClient(String JavaDoc clientName, boolean createFolder) {
135         return impl.getLocalWsdlFolderForClient(clientName,createFolder);
136     }
137     
138     /** Get folder for local jaxb binding (xml) files for given client
139      * This is the location where external jaxb binding files are downloaded to the project.
140      * JAX-WS java artifacts will be generated using these local binding files instead of remote.
141      * @param clientName client name (the web service reference node display name)
142      * @param createFolder if (createFolder==true) the folder will be created (if not created before)
143      * @return the file object (folder) where jaxb binding files are located in project
144      */

145     public FileObject getBindingsFolderForClient(String JavaDoc clientName, boolean createFolder) {
146         return impl.getBindingsFolderForClient(clientName,createFolder);
147     }
148     
149     /** gets the URL of catalog.xml file
150      * (the catalog is used by wsimport to locate local wsdl/xml resources)
151      * @return URL url of the car
152      */

153     public URL JavaDoc getCatalog() {
154         return impl.getCatalog();
155     }
156     
157     /** Get list of all JAX-WS Clients in project
158      * @param clientName client name (the web service reference node display name)
159      */

160     public List JavaDoc/*Client*/ getServiceClients() {
161         return impl.getServiceClients();
162     }
163     
164     /** intended to be used to obtain service-ref name for given web service reference
165      * (currently not used in projects)
166      */

167      public String JavaDoc getServiceRefName(Node clientNode){
168          return impl.getServiceRefName(clientNode);
169      }
170 }
Popular Tags