KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > jaxws > WebProjectJAXWSClientSupport


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.web.project.jaxws;
21
22 import java.io.IOException JavaDoc;
23 import org.netbeans.api.java.classpath.ClassPath;
24 import org.netbeans.api.java.project.JavaProjectConstants;
25 import org.netbeans.api.project.ProjectUtils;
26 import org.netbeans.api.project.SourceGroup;
27 import org.netbeans.api.project.libraries.Library;
28 import org.netbeans.api.project.libraries.LibraryManager;
29 import org.netbeans.modules.web.api.webmodule.WebModule;
30 import org.netbeans.modules.web.project.WebProject;
31 import org.netbeans.modules.websvc.api.jaxws.project.WSUtils;
32 import org.netbeans.modules.websvc.api.jaxws.project.config.Client;
33 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
34 import org.netbeans.modules.websvc.spi.jaxws.client.ProjectJAXWSClientSupport;
35 import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender;
36 import org.openide.ErrorManager;
37 import org.openide.filesystems.FileObject;
38
39 /**
40  *
41  * @author mkuchtiak
42  */

43 public class WebProjectJAXWSClientSupport extends ProjectJAXWSClientSupport /*implements JAXWSClientSupportImpl*/ {
44     WebProject project;
45     
46     /** Creates a new instance of WebProjectJAXWSClientSupport */
47     public WebProjectJAXWSClientSupport(WebProject project) {
48         super(project);
49         this.project=project;
50     }
51
52     public FileObject getWsdlFolder(boolean create) throws IOException JavaDoc {
53         WebModule webModule = WebModule.getWebModule(project.getProjectDirectory());
54         if (webModule!=null) {
55             FileObject webInfFo = webModule.getWebInf();
56             if (webInfFo!=null) {
57                 FileObject wsdlFo = webInfFo.getFileObject("wsdl"); //NOI18N
58
if (wsdlFo!=null) return wsdlFo;
59                 else if (create) {
60                     return webInfFo.createFolder("wsdl"); //NOI18N
61
}
62             }
63         }
64         return null;
65     }
66
67     protected void addJaxWs20Library() throws Exception JavaDoc{
68         
69         SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
70         ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE);
71         FileObject wsimportFO = classPath.findResource("com/sun/tools/ws/ant/WsImport.class"); // NOI18N
72

73         if (wsimportFO == null) {
74             //Add the jaxws20 library to the project to be packed with the archive
75
ProjectClassPathExtender pce = (ProjectClassPathExtender)project.getLookup().lookup(ProjectClassPathExtender.class);
76             Library jaxws20_ext = LibraryManager.getDefault().getLibrary("jaxws20"); //NOI18N
77
if ((pce!=null) && (jaxws20_ext != null)) {
78                 try{
79                 pce.addLibrary(jaxws20_ext);
80                 }catch(IOException JavaDoc e){
81                     throw new Exception JavaDoc("Unable to add JAXWS 2.0 library", e.getCause());
82                 }
83             } else {
84                 throw new Exception JavaDoc("Unable to add JAXWS 2.0 Library. " +
85                         "ProjectClassPathExtender or library not found");
86             }
87         }
88     }
89     
90     /** return root folder for xml artifacts
91      */

92     protected FileObject getXmlArtifactsRoot() {
93         return project.getWebModule().getConfDir();
94     }
95
96     public String JavaDoc addServiceClient(String JavaDoc clientName, String JavaDoc wsdlUrl, String JavaDoc packageName, boolean isJsr109) {
97         // create jax-ws.xml if necessary
98
FileObject fo = project.findJaxWsFileObject();
99         if (fo==null) {
100             try {
101                 project.createJaxWsFileObject();
102             } catch (IOException JavaDoc ex) {
103                 ErrorManager.getDefault().notify(ex);
104             }
105         }
106         String JavaDoc finalClientName = super.addServiceClient(clientName, wsdlUrl, packageName, isJsr109);
107         
108         // copy resources to WEB-INF/wsdl/client/${clientName}
109
// this will be done only for local wsdl files
110
JaxWsModel jaxWsModel = (JaxWsModel)project.getLookup().lookup(JaxWsModel.class);
111         Client client = jaxWsModel.findClientByName(finalClientName);
112         if (client!=null && client.getWsdlUrl().startsWith("file:")) //NOI18N
113
try {
114                 FileObject wsdlFolder = getWsdlFolderForClient(finalClientName);
115                 FileObject xmlResorcesFo = getLocalWsdlFolderForClient(finalClientName,false);
116                 if (xmlResorcesFo!=null) WSUtils.copyFiles(xmlResorcesFo, wsdlFolder);
117             } catch (IOException JavaDoc ex) {
118                 ErrorManager.getDefault().notify(ex);
119             }
120         
121         return finalClientName;
122     }
123
124 }
125
Popular Tags