1 19 20 package org.netbeans.modules.websvc.dev.wizard; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.URI ; 25 import java.net.URL ; 26 import java.text.DateFormat ; 27 import java.util.ArrayList ; 28 import java.util.Date ; 29 import java.util.List ; 30 import java.util.Map ; 31 import javax.xml.transform.stream.StreamSource ; 32 import org.apache.tools.ant.module.api.support.ActionUtils; 33 import org.netbeans.api.java.classpath.ClassPath; 34 import org.netbeans.api.java.project.JavaProjectConstants; 35 import org.netbeans.api.progress.ProgressHandle; 36 import org.netbeans.api.progress.ProgressHandleFactory; 37 import org.netbeans.api.project.Project; 38 import org.netbeans.api.project.ProjectUtils; 39 import org.netbeans.api.project.SourceGroup; 40 import org.netbeans.api.project.libraries.Library; 41 import org.netbeans.api.project.libraries.LibraryManager; 42 import org.netbeans.modules.j2ee.api.ejbjar.EjbJar; 43 import org.netbeans.modules.j2ee.common.Util; 44 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 45 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 46 import org.netbeans.modules.web.api.webmodule.WebModule; 47 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 48 import org.netbeans.modules.websvc.api.jaxws.project.config.Service; 49 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModelListener; 50 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModeler; 51 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 52 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 53 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModel; 54 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlPort; 55 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlService; 56 import org.netbeans.modules.websvc.api.webservices.WsCompileEditorSupport; 57 import org.netbeans.modules.websvc.core.jaxws.JaxWsUtils; 58 import org.netbeans.modules.websvc.dev.dd.gen.wscreation.Bean; 59 import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; 60 import org.netbeans.spi.project.support.ant.GeneratedFilesHelper; 61 import org.netbeans.spi.project.ui.templates.support.Templates; 62 import org.openide.DialogDisplayer; 63 import org.openide.ErrorManager; 64 import org.openide.NotifyDescriptor; 65 import org.openide.WizardDescriptor; 66 import org.openide.cookies.EditorCookie; 67 import org.openide.execution.ExecutorTask; 68 import org.openide.filesystems.FileLock; 69 import org.openide.filesystems.FileObject; 70 import org.openide.filesystems.FileUtil; 71 import org.openide.loaders.DataFolder; 72 import org.openide.loaders.DataObject; 73 import org.openide.nodes.Node; 74 import org.openide.util.NbBundle; 75 import org.openide.util.RequestProcessor; 76 77 81 public class WebServiceCreator { 82 83 private Project project; 84 private String wsName; 85 private int serviceType; 86 private WizardDescriptor wiz; 87 private int projectType; 88 89 protected static final int JSE_PROJECT_TYPE = 0; 90 protected static final int WEB_PROJECT_TYPE = 1; 91 protected static final int EJB_PROJECT_TYPE = 2; 92 93 private boolean jwsdpSupported = false; 94 private boolean jsr109Supported = false; 95 private boolean jsr109oldSupported = false; 96 97 98 99 public WebServiceCreator(Project project, WizardDescriptor wiz) { 100 this.project = project; 101 this.wiz = wiz; 102 } 103 104 public WebServiceCreator(Project project) { 105 this.project = project; 106 } 107 108 public void create() { 109 110 serviceType = ((Integer ) wiz.getProperty(WizardProperties.WEB_SERVICE_TYPE)).intValue(); 111 initProjectInfo(project); 112 113 final ProgressHandle handle = ProgressHandleFactory.createHandle( NbBundle.getMessage(WebServiceCreator.class, "TXT_WebServiceGeneration")); handle.start(100); 116 117 Runnable r = new Runnable () { 118 public void run() { 119 try { 120 generateWebService(handle); 121 } catch (Exception e) { 122 handle.finish(); 124 String message = e.getLocalizedMessage(); 125 if(message != null) { 126 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 127 NotifyDescriptor nd = new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE); 128 DialogDisplayer.getDefault().notify(nd); 129 } else { 130 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 131 } 132 } 133 } 134 }; 135 RequestProcessor.getDefault().post(r); 136 } 137 138 public void createFromWSDL() { 139 140 initProjectInfo(project); 141 142 final ProgressHandle handle = ProgressHandleFactory.createHandle( NbBundle.getMessage(WebServiceCreator.class, "TXT_WebServiceGeneration")); 144 Runnable r = new Runnable () { 145 public void run() { 146 try { 147 if (Util.isJavaEE5orHigher(project) || 148 (!jsr109Supported && projectType == WEB_PROJECT_TYPE && !jsr109oldSupported) 149 || jwsdpSupported) { 150 handle.start(); 151 generateWsFromWsdl15(handle); 152 } else { 153 handle.start(100); 154 generateWsFromWsdl14(handle); 155 } 156 } catch (Exception e) { 157 handle.finish(); 159 String message = e.getLocalizedMessage(); 160 if(message != null) { 161 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 162 NotifyDescriptor nd = new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE); 163 DialogDisplayer.getDefault().notify(nd); 164 } else { 165 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 166 } 167 } 168 } 169 }; 170 RequestProcessor.getDefault().post(r); 171 } 172 173 private void initProjectInfo(Project project) { 174 JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 175 if (wss != null) { 176 Map properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 177 String serverInstance = (String )properties.get("j2ee.server.instance"); if (serverInstance != null) { 179 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance); 180 if (j2eePlatform != null) { 181 jwsdpSupported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_JWSDP); 182 jsr109Supported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109); 183 jsr109oldSupported = j2eePlatform.isToolSupported(J2eePlatform.TOOL_WSCOMPILE); 184 } 185 } 186 } 187 188 WebModule wm = WebModule.getWebModule(project.getProjectDirectory()); 189 EjbJar em = EjbJar.getEjbJar(project.getProjectDirectory()); 190 if (em != null) 191 projectType = EJB_PROJECT_TYPE; 192 else if (wm != null) 193 projectType = WEB_PROJECT_TYPE; 194 else 195 projectType = JSE_PROJECT_TYPE; 196 } 197 198 private FileObject generateJaxWSImplFromTemplate(FileObject pkg) throws Exception { 199 DataFolder df = DataFolder.findFolder(pkg); 200 FileObject template = Templates.getTemplate(wiz); 201 202 if (projectType==EJB_PROJECT_TYPE) { FileObject templateParent = template.getParent(); 204 template = templateParent.getFileObject("EjbWebService","java"); } 206 DataObject dTemplate = DataObject.find(template); 207 DataObject dobj = dTemplate.createFromTemplate(df, wsName); 208 FileObject createdFile = dobj.getPrimaryFile(); 209 210 211 JaxWsModel jaxWsModel = project.getLookup().lookup(JaxWsModel.class); 212 if ( jaxWsModel!= null) { 213 ClassPath classPath = ClassPath.getClassPath(createdFile, ClassPath.SOURCE); 214 String serviceImplPath = classPath.getResourceName(createdFile, '.', false); 215 jaxWsModel.addService(wsName, serviceImplPath); 216 jaxWsModel.write(); 217 } 218 219 openFileInEditor(dobj); 220 return createdFile; 221 } 222 223 private void openFileInEditor(DataObject dobj){ 224 final EditorCookie ec = (EditorCookie)dobj.getCookie(EditorCookie.class); 225 RequestProcessor.getDefault().post(new Runnable (){ 226 public void run(){ 227 ec.open(); 228 } 229 }, 1000); 230 } 231 232 private String uniqueWSName(final String origName, List <String > names ){ 233 int uniquifier = 0; 234 String truename = origName; 235 while(names.contains(truename)){ 236 truename = origName + String.valueOf(++uniquifier); 237 } 238 return truename; 239 } 240 241 private String getUniqueJaxwsName(JAXWSSupport jaxWsSupport, String origName){ 242 List <Service> webServices = jaxWsSupport.getServices(); 243 List <String > serviceNames = new ArrayList <String >(webServices.size()); 244 for(Service service : webServices){ 245 serviceNames.add(service.getName()); 246 } 247 return uniqueWSName(origName, serviceNames); 248 } 249 250 private String getUniqueJaxrpcName(WebServicesSupport wsSupport, String origName){ 251 List <WsCompileEditorSupport.ServiceSettings> webServices = wsSupport.getServices(); 252 List <String > serviceNames = new ArrayList <String >(webServices.size()); 253 for(WsCompileEditorSupport.ServiceSettings service: webServices){ 254 serviceNames.add(service.getServiceName()); 255 } 256 return uniqueWSName(origName, serviceNames); 257 } 258 259 private void generateWebService(ProgressHandle handle) throws Exception { 261 262 FileObject pkg = Templates.getTargetFolder(wiz); 263 wsName = Templates.getTargetName(wiz); 264 265 if (serviceType == WizardProperties.FROM_SCRATCH){ 266 if ((projectType == JSE_PROJECT_TYPE && Util.isSourceLevel16orHigher(project)) || 267 ((Util.isJavaEE5orHigher(project) && 268 (projectType == WEB_PROJECT_TYPE || projectType == EJB_PROJECT_TYPE))) || 269 (jwsdpSupported) 270 ) { 271 JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 272 wsName = getUniqueJaxwsName(jaxWsSupport, wsName); 273 handle.progress(NbBundle.getMessage(WebServiceCreator.class, "MSG_GEN_WS"), 50); FileObject createdFile = generateJaxWSImplFromTemplate(pkg); 275 handle.finish(); 276 return; 277 } else if (!Util.isJavaEE5orHigher(project) && (projectType == WEB_PROJECT_TYPE ||projectType == EJB_PROJECT_TYPE)) { if ((!jsr109Supported && projectType == WEB_PROJECT_TYPE && !jsr109oldSupported)) { 280 JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 281 wsName = getUniqueJaxwsName(jaxWsSupport, wsName); 282 handle.progress(NbBundle.getMessage(WebServiceCreator.class, "MSG_GEN_WS"), 50); addJaxws20Library(project); 285 generateJaxWSImplFromTemplate(pkg); 286 287 handle.finish(); 288 289 } else { WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(pkg); 291 assert wsSupport != null; 292 wsName = getUniqueJaxrpcName(wsSupport, wsName); 293 WebServiceGenerator generator = new WebServiceGenerator(wsSupport, wsName, pkg, project); 294 handle.progress(NbBundle.getMessage(WebServiceCreator.class, "MSG_GEN_SEI_AND_IMPL"), 50); generator.generateWebService(); 296 297 URI targetNS = null; 298 URI typeNS = null; 299 try { 300 targetNS = generator.getTargetNS(); 301 typeNS = generator.getDefaultTypeNS(wsName); } catch(java.net.URISyntaxException e) { 303 String mes = NbBundle.getMessage(WebServiceCreator.class, "MSG_INVALID_URL_SYNTAX"); throw new Exception (mes); 305 } 306 handle.progress(NbBundle.getMessage(WebServiceCreator.class, "MSG_CREATING_WSCOMPILE_ARTIFACTS")); String servantClassName = generator.getServantClassName(); 309 String seiClassName = generator.getSEIClassName(); 310 FileObject configFile = null; 311 configFile = generator.generateConfigFile(seiClassName, servantClassName, targetNS, typeNS); 312 handle.progress(70); 313 314 wsSupport.addServiceImpl(wsName, configFile, false); 316 handle.progress(90); 317 318 wsSupport.addServiceEntriesToDD(wsName, seiClassName, servantClassName); 320 321 handle.progress(NbBundle.getMessage(NewWebServiceWizardIterator.class, "MSG_ADDING_DD_ENTRIES")); String portTypeName = null; 324 generator.addWebServiceEntry(seiClassName, portTypeName, targetNS); 325 326 handle.finish(); 327 328 return; 329 } 330 } 331 } 332 if (serviceType == WizardProperties.ENCAPSULATE_SESSION_BEAN) { 333 if ((projectType == JSE_PROJECT_TYPE && Util.isSourceLevel16orHigher(project)) || 334 (Util.isJavaEE5orHigher(project) && (projectType == WEB_PROJECT_TYPE 335 ||projectType == EJB_PROJECT_TYPE)) ) { 337 338 JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 339 wsName = getUniqueJaxwsName(jaxWsSupport, wsName); 340 WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(pkg); 343 assert wsSupport != null; 344 WebServiceGenerator generator = new WebServiceGenerator(wsSupport, wsName, pkg, project); 345 handle.progress(NbBundle.getMessage(WebServiceCreator.class, "MSG_GEN_SEI_AND_IMPL"), 50); Node[] nodes = (Node[]) wiz.getProperty(WizardProperties.DELEGATE_TO_SESSION_BEAN); 347 generator.generateWebServiceJavaEE5(nodes); 348 349 handle.progress(70); 350 351 String servantClassName = generator.getServantClassName(); 352 generator.addReferences(servantClassName, nodes); 353 354 355 jaxWsSupport.addService(wsName,servantClassName, jsr109Supported); 356 357 handle.finish(); 358 359 return; 360 } else if (projectType == WEB_PROJECT_TYPE ||projectType == EJB_PROJECT_TYPE) { 361 WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(pkg); 362 assert wsSupport != null; 363 wsName = getUniqueJaxrpcName(wsSupport, wsName); 364 WebServiceGenerator generator = new WebServiceGenerator(wsSupport, wsName, pkg, project); 365 handle.progress(NbBundle.getMessage(WebServiceCreator.class, "MSG_GEN_SEI_AND_IMPL"), 50); Node[] nodes = (Node[]) wiz.getProperty(WizardProperties.DELEGATE_TO_SESSION_BEAN); 367 generator.generateWebService(nodes); 368 369 URI targetNS = null; 370 URI typeNS = null; 371 try { 372 targetNS = generator.getTargetNS(); 373 typeNS = generator.getDefaultTypeNS(wsName); } catch(java.net.URISyntaxException e) { 375 String mes = NbBundle.getMessage(WebServiceCreator.class, "MSG_INVALID_URL_SYNTAX"); throw new Exception (mes); 377 } 378 handle.progress(NbBundle.getMessage(WebServiceCreator.class, "MSG_CREATING_WSCOMPILE_ARTIFACTS")); String servantClassName = generator.getServantClassName(); 381 String seiClassName = generator.getSEIClassName(); 382 FileObject configFile = null; 383 configFile = generator.generateConfigFile(seiClassName, servantClassName, targetNS, typeNS); 384 handle.progress(70); 385 386 wsSupport.addServiceImpl(wsName, configFile, false); 388 handle.progress(90); 389 390 wsSupport.addServiceEntriesToDD(wsName, seiClassName, servantClassName); 392 393 handle.progress(NbBundle.getMessage(NewWebServiceWizardIterator.class, "MSG_ADDING_DD_ENTRIES")); String portTypeName = null; 396 generator.addWebServiceEntry(seiClassName, portTypeName, targetNS); 397 398 generator.addReferences(servantClassName, nodes); 399 400 handle.finish(); 401 } 402 403 return; 404 } 405 } 406 407 private void addJaxws20Library(Project project) throws Exception { 408 409 SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 411 ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE); 412 FileObject wsimportFO = classPath.findResource("com/sun/tools/ws/ant/WsImport.class"); if (wsimportFO != null) { 414 return; 415 } 416 417 ProjectClassPathExtender pce = (ProjectClassPathExtender)project.getLookup().lookup(ProjectClassPathExtender.class); 418 Library jaxws20_ext = LibraryManager.getDefault().getLibrary("jaxws20"); if (pce != null && jaxws20_ext != null) { 420 try{ 421 pce.addLibrary(jaxws20_ext); 422 } catch(IOException e){ 423 throw new Exception ("Unable to add JAXWS 2.0 Library. " + e.getMessage()); 424 } 425 } else{ 426 throw new Exception ("Unable to add JAXWS 2.0 Library. " + 427 "ProjectClassPathExtender or library not found"); 428 } 429 } 430 431 private void generateWsFromWsdl14(ProgressHandle handle) throws Exception { 432 FileObject pkg = Templates.getTargetFolder(wiz); 433 wsName = Templates.getTargetName(wiz); 434 WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(pkg); 435 assert wsSupport != null; 436 WebServiceGenerator generator = new WebServiceGenerator(wsSupport, wsName, pkg, project); 437 438 FileObject wsDDFolder = wsSupport.getWsDDFolder(); 440 FileObject wsdlFolder = wsDDFolder.getFileObject("wsdl"); if(wsdlFolder == null) { 443 wsdlFolder = wsDDFolder.createFolder("wsdl"); } 445 446 handle.progress(NbBundle.getMessage(WebServiceWizard.class, "MSG_PARSING_WSDL"), 30); String wsdlFilePath = (String )wiz.getProperty(WizardProperties.WSDL_FILE_PATH); 448 File normalizedWsdlFilePath = FileUtil.normalizeFile(new File (wsdlFilePath)); 449 final FileObject sourceWsdlFile = FileUtil.toFileObject(normalizedWsdlFilePath); 450 if(sourceWsdlFile == null) { 451 String mes = NbBundle.getMessage(WebServiceWizard.class, "MSG_CANNOT_GET_FILE_OBJECT", normalizedWsdlFilePath.getAbsolutePath()); throw new IOException (mes); 453 } 454 List schemaFiles = WSGenerationUtil.getSchemaNames(sourceWsdlFile,true); 455 String changedWsName = null; 456 try { 457 changedWsName = generator.parseWSDL(sourceWsdlFile.getInputStream()); 458 } catch (NoWSPortDefinedException exc) { 459 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, "WSDL does not contain any defined ports"); String mes = NbBundle.getMessage(WebServiceGenerator.class, "ERR_WsdlNoPortDefined"); NotifyDescriptor desc = new NotifyDescriptor.Message(mes, NotifyDescriptor.Message.ERROR_MESSAGE); 462 DialogDisplayer.getDefault().notify(desc); 463 handle.finish(); 464 return; 465 } 466 if (changedWsName==null) changedWsName = wsName; 467 handle.progress(NbBundle.getMessage(WebServiceWizard.class, "MSG_CREATING_NEW_WSDL"), 50); FileObject wsdlFO = generator.generateWSDL(WebServiceGenerator.WSDL_TEMPLATE, changedWsName, generator.getSoapBinding(), 469 generator.getPortTypeName(), wsdlFolder, sourceWsdlFile.getParent(), wsName, new StreamSource (sourceWsdlFile.getInputStream())); 470 471 URI targetNS = null; 472 URI typeNS = null; 473 try { 474 targetNS = generator.getTargetNS(); 475 typeNS = generator.getDefaultTypeNS(wsName); } catch(java.net.URISyntaxException e) { 477 String mes = NbBundle.getMessage(WebServiceWizard.class, "MSG_INVALID_URL_SYNTAX"); throw new Exception (mes); 479 } 480 handle.progress(NbBundle.getMessage(WebServiceWizard.class, "MSG_CREATING_WSCOMPILE_ARTIFACTS")); String servantClassName = generator.getServantClassName(); 483 String seiClassName = generator.getSEIClassName(); 484 FileObject configFile = null; 485 486 File wsdlFile = FileUtil.toFile(wsdlFO); 487 URI wsdlURI = wsdlFile.toURI(); 488 configFile = generator.generateConfigFile(wsdlURI); 489 490 handle.progress(70); 491 492 wsSupport.addServiceImpl(wsName, configFile, true, generator.getWscompileFeatures()); 494 handle.progress(NbBundle.getMessage(WebServiceWizard.class, "MSG_RUNNING_WSCOMPILE_TARGET")); String targetName = wsName + "_wscompile"; ExecutorTask task = ActionUtils.runTarget(findBuildXml(), new String []{targetName}, null); 498 task.waitFinished(); 499 if(task.result() != 0) { 500 String mes = NbBundle.getMessage(WebServiceWizard.class, "MSG_WSCOMPILE_UNSUCCESSFUL"); wsSupport.removeProjectEntries(wsName); 502 try { 503 deleteFile(configFile); 504 deleteFile(wsdlFO); 505 } catch(IOException e) { 506 String message = NbBundle.getMessage(WebServiceWizard.class, "MSG_UNABLE_DELETE_FILES"); NotifyDescriptor nd = 508 new NotifyDescriptor.Message(message, 509 NotifyDescriptor.ERROR_MESSAGE); 510 DialogDisplayer.getDefault().notify(nd); 511 } 513 throw new Exception (mes); 514 } 515 handle.progress(90); 516 addHeaderComments(wsName, servantClassName, pkg); 517 wsSupport.addInfrastructure(servantClassName, pkg); 518 519 String implClassName = servantClassName.substring(servantClassName.lastIndexOf(".") + 1); FileObject clz = pkg.getFileObject(implClassName, "java"); DataObject dobj = DataObject.find(clz); 523 EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); 524 ec.open(); 525 526 wsSupport.addServiceEntriesToDD(wsName, seiClassName, servantClassName); 528 529 handle.progress(NbBundle.getMessage(WebServiceWizard.class, "MSG_ADDING_DD_ENTRIES")); String portTypeName = null; 532 533 portTypeName = generator.getPortTypeName(); 534 535 generator.addWebServiceEntry(seiClassName, portTypeName, targetNS); 536 537 handle.finish(); 538 } 539 540 private void generateWsFromWsdl15(final ProgressHandle handle) throws Exception { 541 String wsdlFilePath = (String ) wiz.getProperty(WizardProperties.WSDL_FILE_PATH); 542 File normalizedWsdlFilePath = FileUtil.normalizeFile(new File (wsdlFilePath)); 543 final URL wsdlURL = normalizedWsdlFilePath.toURI().toURL(); 545 final WsdlService service = (WsdlService) wiz.getProperty(WizardProperties.WSDL_SERVICE); 546 if (service==null) { 547 JAXWSSupport jaxWsSupport = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 548 FileObject targetFolder = Templates.getTargetFolder(wiz); 549 String targetName = Templates.getTargetName(wiz); 550 WsdlServiceHandler handler = (WsdlServiceHandler)wiz.getProperty(WizardProperties.WSDL_SERVICE_HANDLER); 551 JaxWsUtils.generateJaxWsArtifacts(project,targetFolder,targetName,wsdlURL,handler.getServiceName(),handler.getPortName()); 552 WsdlModeler wsdlModeler = (WsdlModeler) wiz.getProperty(WizardProperties.WSDL_MODELER); 553 if (wsdlModeler!=null && wsdlModeler.getCreationException()!=null) { 554 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 555 NbBundle.getMessage(WebServiceCreator.class,"TXT_CannotGenerateArtifacts", 556 wsdlModeler.getCreationException().getLocalizedMessage()), 557 NotifyDescriptor.ERROR_MESSAGE) 558 ); 559 } 560 handle.finish(); 561 } else { 562 final WsdlPort port = (WsdlPort) wiz.getProperty(WizardProperties.WSDL_PORT); 563 WsdlModeler wsdlModeler = (WsdlModeler) wiz.getProperty(WizardProperties.WSDL_MODELER); 565 wsdlModeler.generateWsdlModel(new WsdlModelListener() { 567 public void modelCreated(WsdlModel model) { 568 WsdlService service1 = model.getServiceByName(service.getName()); 569 WsdlPort port1 = service1.getPortByName(port.getName()); 570 port1.setSOAPVersion(port.getSOAPVersion()); 571 FileObject targetFolder = Templates.getTargetFolder(wiz); 572 String targetName = Templates.getTargetName(wiz); 573 try { 574 JaxWsUtils.generateJaxWsImplementationClass(project, targetFolder, targetName, wsdlURL, service1, port1); 575 handle.finish(); 576 } catch (Exception ex) { 577 handle.finish(); 578 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, ex); 579 } 580 } 581 }); 582 } 583 } 584 585 private void addHeaderComments(String wsName, String servantClassName, FileObject pkg) { 586 String comment = NbBundle.getMessage(NewWebServiceWizardIterator.class, "MSG_WS_CLASS_COMMENT", wsName); StringBuffer buffer = new StringBuffer (comment + "\n"); buffer.append(NbBundle.getMessage(NewWebServiceWizardIterator.class, "MSG_CREATED_COMMENT")+ " " + DateFormat.getDateTimeInstance().format(new Date ()) + "\n" ); buffer.append("@author " + System.getProperty("user.name") ); } 598 599 private void deleteFile(FileObject file)throws IOException { 600 FileLock lock = null; 601 try { 602 lock = file.lock(); 603 file.delete(lock); 604 } finally { 605 if(lock != null) { 606 lock.releaseLock(); 607 } 608 } 609 } 610 611 private FileObject findBuildXml() { 612 return project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_XML_PATH); 613 } 614 615 public void createMessageHandler() throws IOException { 616 617 initProjectInfo(project); 618 619 SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 621 ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE); 622 FileObject wsimportFO = classPath.findResource("com/sun/tools/ws/ant/WsImport.class"); 624 if ((projectType == JSE_PROJECT_TYPE && Util.isSourceLevel16orHigher(project)) || 625 (projectType == JSE_PROJECT_TYPE && Util.getSourceLevel(project).equals("1.5") && wsimportFO != null) || (Util.isJavaEE5orHigher(project) && (projectType == WEB_PROJECT_TYPE || projectType == EJB_PROJECT_TYPE)) || (jwsdpSupported) || (!jsr109Supported && projectType == WEB_PROJECT_TYPE && !jsr109oldSupported) 628 ) { 629 String handlerName = Templates.getTargetName(wiz); 630 FileObject pkg = Templates.getTargetFolder(wiz); 631 DataFolder df = DataFolder.findFolder(pkg); 632 FileObject template = Templates.getTemplate(wiz); 633 DataObject dTemplate = DataObject.find(template); 634 DataObject dobj = dTemplate.createFromTemplate(df, handlerName); 635 636 final EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); 638 RequestProcessor.getDefault().post(new Runnable (){ 639 public void run(){ 640 ec.open(); 641 } 642 }, 1000); 643 } else { 644 WSGenerationUtil wsgenUtil = new WSGenerationUtil(); 645 final String HANDLER_TEMPLATE = WSGenerationUtil.TEMPLATE_BASE + "MessageHandler.xml"; FileObject pkg = Templates.getTargetFolder(wiz); 647 String handlerName = Templates.getTargetName(wiz); 648 String pkgName = wsgenUtil.getSelectedPackageName(pkg, project); 649 Bean b = wsgenUtil.getDefaultBean(); 650 b.setCommentDataWsName(handlerName); 651 b.setClassname(true); 652 b.setClassnameName(handlerName); 653 if(pkgName != null) { 654 b.setClassnamePackage(pkgName); 655 } 656 String handlerClass = wsgenUtil.getFullClassName(pkgName, wsgenUtil.generateClass(HANDLER_TEMPLATE, b, pkg, true)); 657 } 658 } 659 660 public void createLogicalHandler() throws IOException { 661 662 initProjectInfo(project); 663 664 SourceGroup[] sgs = ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 666 ClassPath classPath = ClassPath.getClassPath(sgs[0].getRootFolder(),ClassPath.COMPILE); 667 FileObject wsimportFO = classPath.findResource("com/sun/tools/ws/ant/WsImport.class"); 669 if ((projectType == JSE_PROJECT_TYPE && Util.isSourceLevel16orHigher(project)) || 670 (projectType == JSE_PROJECT_TYPE && Util.getSourceLevel(project).equals("1.5") && wsimportFO != null) || (Util.isJavaEE5orHigher(project) && (projectType == WEB_PROJECT_TYPE || projectType == EJB_PROJECT_TYPE)) || (jwsdpSupported) || (!jsr109Supported && projectType == WEB_PROJECT_TYPE && !jsr109oldSupported) 673 ) { 674 String handlerName = Templates.getTargetName(wiz); 675 FileObject pkg = Templates.getTargetFolder(wiz); 676 DataFolder df = DataFolder.findFolder(pkg); 677 FileObject template = Templates.getTemplate(wiz); 678 DataObject dTemplate = DataObject.find(template); 679 DataObject dobj = dTemplate.createFromTemplate(df, handlerName); 680 681 final EditorCookie ec = (EditorCookie) dobj.getCookie(EditorCookie.class); 683 RequestProcessor.getDefault().post(new Runnable (){ 684 public void run(){ 685 ec.open(); 686 } 687 }, 1000); 688 } 689 } 690 691 public int getProjectType() { 692 initProjectInfo(project); 693 return projectType; 694 } 695 696 } 697 698 | Popular Tags |