1 19 20 package org.netbeans.modules.websvc.jaxrpc.dev.wizard; 21 22 import java.io.IOException ; 23 import java.net.URI ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 import org.netbeans.api.progress.ProgressHandle; 27 import org.netbeans.api.progress.ProgressHandleFactory; 28 import org.netbeans.api.project.Project; 29 import org.netbeans.modules.websvc.api.webservices.WebServicesSupport; 30 import org.netbeans.modules.websvc.api.webservices.WsCompileEditorSupport; 31 import org.netbeans.modules.websvc.core.ServiceCreator; 32 import org.netbeans.modules.websvc.core.dev.wizard.NewWebServiceWizardIterator; 33 import org.netbeans.modules.websvc.core.dev.wizard.ProjectInfo; 34 import org.netbeans.modules.websvc.core.dev.wizard.WizardProperties; 35 import org.netbeans.spi.project.ui.templates.support.Templates; 36 import org.openide.DialogDisplayer; 37 import org.openide.ErrorManager; 38 import org.openide.NotifyDescriptor; 39 import org.openide.WizardDescriptor; 40 import org.openide.filesystems.FileObject; 41 import org.openide.util.NbBundle; 42 import org.openide.util.RequestProcessor; 43 44 48 public class JaxRpcServiceCreator implements ServiceCreator { 49 50 private Project project; 51 private ProjectInfo projectInfo; 52 private WizardDescriptor wiz; 53 private String wsName; 54 private int serviceType; 55 private int projectType; 56 57 58 public JaxRpcServiceCreator(Project project, ProjectInfo projectInfo, WizardDescriptor wiz) { 59 this.project = project; 60 this.projectInfo = projectInfo; 61 this.wiz = wiz; 62 } 63 64 public void createService() throws IOException { 65 System.out.println("create JaxRpc Service"); 66 67 serviceType = ((Integer ) wiz.getProperty(WizardProperties.WEB_SERVICE_TYPE)).intValue(); 68 projectType = projectInfo.getProjectType(); 69 70 final ProgressHandle handle = ProgressHandleFactory.createHandle( NbBundle.getMessage(JaxRpcServiceCreator.class, "TXT_WebServiceGeneration")); handle.start(100); 73 74 Runnable r = new Runnable () { 75 public void run() { 76 try { 77 generateWebService(handle); 78 } catch (Exception e) { 79 handle.finish(); 81 String message = e.getLocalizedMessage(); 82 if(message != null) { 83 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 84 NotifyDescriptor nd = new NotifyDescriptor.Message(message, NotifyDescriptor.ERROR_MESSAGE); 85 DialogDisplayer.getDefault().notify(nd); 86 } else { 87 ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e); 88 } 89 } 90 } 91 }; 92 RequestProcessor.getDefault().post(r); 93 94 } 95 96 public void createServiceFromWsdl() throws IOException { 97 System.out.println("create JaxRpc Service from wsdl"); 98 } 99 100 private void generateWebService(ProgressHandle handle) throws Exception { 101 FileObject pkg = Templates.getTargetFolder(wiz); 102 WebServicesSupport wsSupport = WebServicesSupport.getWebServicesSupport(pkg); 103 assert wsSupport != null; 104 105 wsName = getUniqueJaxrpcName(wsSupport, Templates.getTargetName(wiz)); 106 107 WebServiceGenerator generator = new WebServiceGenerator(wsSupport, wsName, pkg, project); 108 handle.progress(NbBundle.getMessage(JaxRpcServiceCreator.class, "MSG_GEN_SEI_AND_IMPL"), 50); generator.generateWebService(); 110 111 URI targetNS = null; 112 URI typeNS = null; 113 try { 114 targetNS = generator.getTargetNS(); 115 typeNS = generator.getDefaultTypeNS(wsName); } catch(java.net.URISyntaxException e) { 117 String mes = NbBundle.getMessage(JaxRpcServiceCreator.class, "MSG_INVALID_URL_SYNTAX"); throw new Exception (mes); 119 } 120 handle.progress(NbBundle.getMessage(JaxRpcServiceCreator.class, "MSG_CREATING_WSCOMPILE_ARTIFACTS")); String servantClassName = generator.getServantClassName(); 123 String seiClassName = generator.getSEIClassName(); 124 FileObject configFile = null; 125 configFile = generator.generateConfigFile(seiClassName, servantClassName, targetNS, typeNS); 126 handle.progress(70); 127 128 wsSupport.addServiceImpl(wsName, configFile, false); 130 handle.progress(90); 131 132 wsSupport.addServiceEntriesToDD(wsName, seiClassName, servantClassName); 134 135 handle.progress(NbBundle.getMessage(NewWebServiceWizardIterator.class, "MSG_ADDING_DD_ENTRIES")); String portTypeName = null; 138 generator.addWebServiceEntry(seiClassName, portTypeName, targetNS); 139 140 handle.finish(); 141 } 142 143 private String getUniqueJaxrpcName(WebServicesSupport wsSupport, String origName){ 144 List <WsCompileEditorSupport.ServiceSettings> webServices = wsSupport.getServices(); 145 List <String > serviceNames = new ArrayList <String >(webServices.size()); 146 for(WsCompileEditorSupport.ServiceSettings service: webServices){ 147 serviceNames.add(service.getServiceName()); 148 } 149 return uniqueWSName(origName, serviceNames); 150 } 151 152 private String uniqueWSName(final String origName, List <String > names ){ 153 int uniquifier = 0; 154 String truename = origName; 155 while(names.contains(truename)){ 156 truename = origName + String.valueOf(++uniquifier); 157 } 158 return truename; 159 } 160 } 161 | Popular Tags |