1 19 package org.netbeans.modules.websvc.core.jaxws.nodes; 20 21 import java.awt.Dialog ; 22 import java.awt.Image ; 23 import java.awt.datatransfer.Transferable ; 24 import java.io.IOException ; 25 import java.io.UnsupportedEncodingException ; 26 import java.net.HttpURLConnection ; 27 import java.net.URL ; 28 import java.net.URLConnection ; 29 import java.net.URLEncoder ; 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.List ; 33 import java.util.Map ; 34 import javax.lang.model.element.AnnotationMirror; 35 import javax.lang.model.element.AnnotationValue; 36 import javax.lang.model.element.ExecutableElement; 37 import javax.lang.model.element.TypeElement; 38 import javax.swing.Action ; 39 import org.apache.tools.ant.module.api.support.ActionUtils; 40 import org.netbeans.api.java.source.CancellableTask; 41 import org.netbeans.api.java.source.CompilationController; 42 import org.netbeans.api.java.source.JavaSource; 43 import org.netbeans.api.java.source.JavaSource.Phase; 44 import org.netbeans.api.project.FileOwnerQuery; 45 import org.netbeans.api.project.Project; 46 import org.netbeans.modules.j2ee.common.Util; 47 import org.netbeans.modules.j2ee.common.source.SourceUtils; 48 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 49 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 50 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 51 import org.netbeans.modules.j2ee.deployment.devmodules.spi.J2eeModuleProvider; 52 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties; 53 import org.netbeans.modules.web.api.webmodule.WebModule; 54 import org.netbeans.modules.websvc.api.jaxws.project.GeneratedFilesHelper; 55 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoints; 56 import org.netbeans.modules.websvc.api.jaxws.project.config.Handler; 57 import org.netbeans.modules.websvc.api.jaxws.project.config.HandlerChain; 58 import org.netbeans.modules.websvc.api.jaxws.project.config.HandlerChains; 59 import org.netbeans.modules.websvc.api.jaxws.project.config.HandlerChainsProvider; 60 import org.netbeans.modules.websvc.api.jaxws.wsdlmodel.WsdlModeler; 61 import org.netbeans.modules.websvc.core.WebServiceReference; 62 import org.netbeans.modules.websvc.core.WebServiceTransferable; 63 import org.netbeans.modules.websvc.core.jaxws.actions.AddOperationAction; 64 import org.netbeans.modules.websvc.core.jaxws.actions.JaxWsRefreshAction; 65 import org.netbeans.modules.websvc.core.jaxws.actions.WsTesterPageAction; 66 import org.netbeans.modules.websvc.core.jaxws.nodes.HandlerButtonListener; 67 import org.netbeans.modules.websvc.core.webservices.action.ConfigureHandlerAction; 68 import org.netbeans.modules.websvc.core.webservices.action.ConfigureHandlerCookie; 69 import org.netbeans.modules.websvc.core.webservices.ui.panels.MessageHandlerPanel; 70 import org.netbeans.modules.websvc.core.wseditor.support.EditWSAttributesCookie; 71 import org.netbeans.modules.websvc.core.wseditor.support.WSEditAttributesAction; 72 import org.netbeans.modules.websvc.jaxws.api.JaxWsRefreshCookie; 73 import org.netbeans.modules.websvc.jaxws.api.JaxWsTesterCookie; 74 import org.netbeans.modules.websvc.jaxws.api.JaxWsWsdlCookie; 75 import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel; 76 import org.netbeans.modules.websvc.api.jaxws.project.config.Service; 77 import org.openide.DialogDescriptor; 78 import org.openide.DialogDisplayer; 79 import org.openide.ErrorManager; 80 import org.openide.actions.DeleteAction; 81 import org.openide.actions.OpenAction; 82 import org.openide.actions.PropertiesAction; 83 import org.openide.cookies.OpenCookie; 84 import org.openide.execution.ExecutorTask; 85 import org.openide.filesystems.FileObject; 86 import org.openide.loaders.DataObject; 87 import org.openide.loaders.DataObjectNotFoundException; 88 import org.openide.nodes.AbstractNode; 89 import org.openide.util.HelpCtx; 90 import org.openide.util.NbBundle; 91 import org.openide.util.actions.SystemAction; 92 import org.openide.util.lookup.AbstractLookup; 93 import org.openide.util.lookup.InstanceContent; 94 import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoint; 95 import org.netbeans.modules.websvc.api.jaxws.project.config.EndpointsProvider; 96 import org.netbeans.modules.websvc.core.MultiViewCookie; 97 import org.netbeans.modules.websvc.core.MultiViewCookieProvider; 98 import org.netbeans.modules.websvc.core.wseditor.support.EditWSAttributesCookieImpl; 99 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 100 import org.openide.NotifyDescriptor; 101 import org.openide.actions.EditAction; 102 import org.openide.filesystems.FileLock; 103 import org.openide.util.Lookup; 104 105 public class JaxWsNode extends AbstractNode implements JaxWsWsdlCookie, JaxWsTesterCookie, JaxWsRefreshCookie, 106 ConfigureHandlerCookie{ 107 Service service; 108 FileObject srcRoot; 109 JaxWsModel jaxWsModel; 110 private FileObject implBeanClass; 111 InstanceContent content; 112 Project project; 113 114 public JaxWsNode(JaxWsModel jaxWsModel, Service service, FileObject srcRoot, FileObject implBeanClass) { 115 this(jaxWsModel, service, srcRoot, implBeanClass, new InstanceContent()); 116 } 117 118 private JaxWsNode(JaxWsModel jaxWsModel, Service service, FileObject srcRoot, FileObject implBeanClass, InstanceContent content) { 119 super(new JaxWsChildren(service,srcRoot, implBeanClass),new AbstractLookup(content)); 120 this.jaxWsModel=jaxWsModel; 121 this.service=service; 122 this.srcRoot=srcRoot; 123 this.content = content; 124 this.implBeanClass=implBeanClass; 125 setName(service.getName()); 126 content.add(this); 127 content.add(service); 128 content.add(implBeanClass); 129 content.add(new EditWSAttributesCookieImpl(this, jaxWsModel)); 130 OpenCookie cookie = getMultiViewCookie(service, getDataObject()); 131 if(cookie==null) { 132 cookie = new OpenCookie() { 133 public void open() { 134 OpenCookie oc = getOpenCookie(); 135 if (oc != null) { 136 oc.open(); 137 } 138 } 139 }; 140 } 141 content.add(cookie); 142 project = FileOwnerQuery.getOwner(srcRoot); 143 } 144 145 private static final Lookup.Result<MultiViewCookieProvider> multiviewCookieProviders = 146 Lookup.getDefault().lookup(new Lookup.Template<MultiViewCookieProvider>(MultiViewCookieProvider.class)); 147 148 151 public static MultiViewCookie getMultiViewCookie(Service service, DataObject dataObject) { 152 Collection <? extends MultiViewCookieProvider> instances = multiviewCookieProviders.allInstances(); 153 for (MultiViewCookieProvider impl: instances) { 154 MultiViewCookie cookie = impl.getMultiViewCookie(service, dataObject); 155 if (cookie != null) { 156 return cookie; 157 } 158 } 159 return null; 160 } 161 162 public String getDisplayName() { 163 if (service.getWsdlUrl()!=null) 164 return NbBundle.getMessage(JaxWsNode.class,"LBL_serviceNodeName",service.getServiceName(),service.getPortName()); 165 else 166 return service.getName(); 167 } 168 169 public String getShortDescription() { 170 return getWsdlURL(); 171 } 172 173 private static final java.awt.Image WAITING_BADGE = 174 org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/waiting.png"); private static final java.awt.Image ERROR_BADGE = 176 org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/error-badge.gif" ); private static final java.awt.Image SERVICE_BADGE = 178 org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/XMLServiceDataIcon.gif" ); 180 public java.awt.Image getIcon(int type) { 181 WsdlModeler wsdlModeler = ((JaxWsChildren)getChildren()).getWsdlModeler(); 182 if (wsdlModeler==null) return SERVICE_BADGE; 183 else if (wsdlModeler.getCreationException()==null) { 184 if (((JaxWsChildren)getChildren()).isModelGenerationFinished()) 185 return SERVICE_BADGE; 186 else 187 return org.openide.util.Utilities.mergeImages(SERVICE_BADGE, WAITING_BADGE, 15, 8); 188 } else { 189 Image dirtyNodeImage = org.openide.util.Utilities.mergeImages(SERVICE_BADGE, ERROR_BADGE, 6, 6); 190 if (((JaxWsChildren)getChildren()).isModelGenerationFinished()) 191 return dirtyNodeImage; 192 else 193 return org.openide.util.Utilities.mergeImages(dirtyNodeImage, WAITING_BADGE, 15, 8); 194 } 195 } 196 197 void changeIcon() { 198 fireIconChange(); 199 } 200 201 public Image getOpenedIcon(int type){ 202 return getIcon( type); 203 } 204 205 private DataObject getDataObject() { 206 FileObject f = getImplBean(); 207 if (f != null) { 208 try { 209 return DataObject.find(f); 210 } catch (DataObjectNotFoundException de) { 211 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, de.toString()); 212 } 213 } 214 return null; 215 } 216 217 private OpenCookie getOpenCookie() { 218 OpenCookie oc = null; 219 FileObject f = getImplBean(); 220 if (f != null) { 221 try { 222 DataObject d = DataObject.find(f); 223 oc = (OpenCookie)d.getCookie(OpenCookie.class); 224 } catch (DataObjectNotFoundException de) { 225 ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL, de.toString()); 226 } 227 } 228 return oc; 230 } 231 232 public Action getPreferredAction() { 233 return SystemAction.get(OpenAction.class); 234 } 235 236 public Action [] getActions(boolean context) { 238 return new SystemAction[] { 239 SystemAction.get(OpenAction.class), 240 SystemAction.get(EditAction.class), 241 SystemAction.get(JaxWsRefreshAction.class), 242 null, 243 SystemAction.get(AddOperationAction.class), 244 null, 245 SystemAction.get(WsTesterPageAction.class), 246 null, 247 SystemAction.get(WSEditAttributesAction.class), 248 null, 249 SystemAction.get(ConfigureHandlerAction.class), 250 null, 251 SystemAction.get(DeleteAction.class), 252 null, 253 SystemAction.get(PropertiesAction.class), 254 }; 255 } 256 257 public HelpCtx getHelpCtx() { 258 return HelpCtx.DEFAULT_HELP; 259 } 260 261 public boolean canDestroy() { 263 return true; 264 } 265 266 267 270 public String getWebServiceURL() { 271 J2eeModuleProvider provider = (J2eeModuleProvider)project.getLookup().lookup(J2eeModuleProvider.class); 272 InstanceProperties instanceProperties = provider.getInstanceProperties(); 273 if (instanceProperties==null) { 274 DialogDisplayer.getDefault().notify( 275 new NotifyDescriptor.Message(NbBundle.getMessage(JaxWsNode.class,"MSG_MissingServer"),NotifyDescriptor.ERROR_MESSAGE)); 276 return ""; 277 } 278 String portNumber = instanceProperties.getProperty(InstanceProperties.HTTP_PORT_NUMBER); 280 if(portNumber == null || portNumber.equals("")) { 281 portNumber = "8080"; } 283 284 String serverUrl = instanceProperties.getProperty(InstanceProperties.URL_ATTR); 286 String hostName="localhost"; if (serverUrl!=null && serverUrl.indexOf("::")>0) { int index1 = serverUrl.indexOf("::"); int index2 = serverUrl.lastIndexOf(":"); if (index2>index1+2) hostName = serverUrl.substring(index1+2,index2); 291 } 292 293 String contextRoot = null; 294 Object moduleType = provider.getJ2eeModule().getModuleType(); 295 297 String wsURI=null; 298 if (isJsr109Supported(project) && Util.isJavaEE5orHigher(project)) { 299 try { 300 wsURI = getServiceUri(moduleType); 301 } catch (UnsupportedEncodingException ex) { 302 } 304 } else { 305 try { 306 wsURI = getNonJsr109Uri(moduleType); 307 } catch (UnsupportedEncodingException ex) { 308 } 310 } 311 if(J2eeModule.WAR.equals(moduleType)) { 312 J2eeModuleProvider.ConfigSupport configSupport = provider.getConfigSupport(); 313 contextRoot = configSupport.getWebContextRoot(); 314 if(contextRoot != null && contextRoot.startsWith("/")) { contextRoot = contextRoot.substring(1); 316 } 317 } 320 321 return "http://"+hostName+":" + portNumber +"/" + (contextRoot != null && !contextRoot.equals("") ? contextRoot + "/" : "") + wsURI; } 323 324 private String getNonJsr109Uri(Object moduleType) throws UnsupportedEncodingException { 325 JAXWSSupport support = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 326 if (J2eeModule.WAR.equals(moduleType)) { 327 WebModule webModule = WebModule.getWebModule(project.getProjectDirectory()); 328 FileObject webInfFo = webModule.getWebInf(); 329 if (webInfFo!=null) { 330 FileObject sunJaxwsFo = webInfFo.getFileObject("sun-jaxws","xml"); if (sunJaxwsFo!=null) { 332 try { 333 Endpoints endpoints = EndpointsProvider.getDefault().getEndpoints(sunJaxwsFo); 334 if (endpoints!=null) { 335 String urlPattern = findUrlPattern(endpoints, service.getImplementationClass()); 336 if (urlPattern!=null) return URLEncoder.encode(urlPattern, "UTF-8"); } 338 } catch (IOException ex) { 339 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 340 } 341 } 342 } 343 } 344 return URLEncoder.encode(getNameFromPackageName(service.getImplementationClass()),"UTF-8"); } 346 347 private String findUrlPattern(Endpoints endpoints, String implementationClass) { 348 Endpoint[] endp = endpoints.getEndpoints(); 349 for (int i=0;i<endp.length;i++) { 350 if (implementationClass.equals(endp[i].getImplementation())) { 351 String urlPattern = endp[i].getUrlPattern(); 352 if (urlPattern!=null) { 353 return urlPattern.startsWith("/")?urlPattern.substring(1):urlPattern; } 355 } 356 } 357 return null; 358 } 359 360 private String getServiceUri(final Object moduleType) throws UnsupportedEncodingException { 361 final String [] serviceName=new String [1]; 362 final String [] name=new String [1]; 363 final boolean[] isProvider = {false}; 364 JavaSource javaSource = getImplBeanJavaSource(); 365 if (javaSource!=null) { 366 CancellableTask<CompilationController> task = new CancellableTask<CompilationController>() { 367 public void run(CompilationController controller) throws IOException { 368 controller.toPhase(Phase.ELEMENTS_RESOLVED); 369 SourceUtils srcUtils = SourceUtils.newInstance(controller); 370 TypeElement wsElement = controller.getElements().getTypeElement("javax.jws.WebService"); if (srcUtils!=null && wsElement!=null) { 372 boolean foundWsAnnotation = resolveServiceUrl( moduleType, 373 controller, 374 srcUtils, 375 wsElement, 376 serviceName, 377 name); 378 if (!foundWsAnnotation) { 379 TypeElement wsProviderElement = controller.getElements().getTypeElement("javax.jws.WebServiceProvider"); List <? extends AnnotationMirror> annotations = srcUtils.getTypeElement().getAnnotationMirrors(); 381 for (AnnotationMirror anMirror : annotations) { 382 if (controller.getTypes().isSameType(wsProviderElement.asType(), anMirror.getAnnotationType())) { 383 isProvider[0] = true; 384 } 385 } 386 } 387 } 388 } 389 390 public void cancel() {} 391 }; 392 try { 393 javaSource.runUserActionTask(task, true); 394 } catch (IOException ex) { 395 ErrorManager.getDefault().notify(ex); 396 } 397 } 398 399 String qualifiedImplClassName = service.getImplementationClass(); 400 String implClassName = getNameFromPackageName(qualifiedImplClassName); 401 if (serviceName[0]==null) { 402 serviceName[0]=URLEncoder.encode(implClassName+"Service","UTF-8"); } 404 if (J2eeModule.WAR.equals(moduleType)) { 405 return serviceName[0]; 406 } else if (J2eeModule.EJB.equals(moduleType)) { 407 if (name[0]==null){ 408 if(isProvider[0]){ 409 name[0]=qualifiedImplClassName; 411 } else{ 412 name[0]=implClassName; 413 } 414 name[0] = URLEncoder.encode(name[0],"UTF-8"); } 416 return serviceName[0]+"/"+ name[0]; 417 } else 418 return serviceName[0]; 419 } 420 421 private boolean resolveServiceUrl( Object moduleType, 422 CompilationController controller, 423 SourceUtils srcUtils, 424 TypeElement wsElement, 425 String [] serviceName, 426 String [] name) throws IOException { 427 boolean foundWsAnnotation = false; 428 List <? extends AnnotationMirror> annotations = srcUtils.getTypeElement().getAnnotationMirrors(); 429 for (AnnotationMirror anMirror : annotations) { 430 if (controller.getTypes().isSameType(wsElement.asType(), anMirror.getAnnotationType())) { 431 foundWsAnnotation=true; 432 Map <? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues(); 433 for(ExecutableElement ex:expressions.keySet()) { 434 if (ex.getSimpleName().contentEquals("serviceName")) { 435 serviceName[0] = (String )expressions.get(ex).getValue(); 436 if (serviceName[0]!=null) serviceName[0] = URLEncoder.encode(serviceName[0],"UTF-8"); } else if (ex.getSimpleName().contentEquals("name")) { 438 name[0] = (String )expressions.get(ex).getValue(); 439 if (name[0]!=null) name[0] = URLEncoder.encode(name[0],"UTF-8"); 440 } 441 if (serviceName[0]!=null && name[0]!=null) break; 442 } 443 break; 444 } } return foundWsAnnotation; 447 } 448 449 private String getNameFromPackageName(String packageName) { 450 int index = packageName.lastIndexOf("."); return index>=0?packageName.substring(index+1):packageName; 452 } 453 454 public String getWsdlURL() { 455 String wsdlUrl = getWebServiceURL(); 456 return wsdlUrl.length()==0?"":wsdlUrl+"?wsdl"; } 458 461 public String getTesterPageURL() { 462 if (isJsr109Supported(project) && (Util.isJavaEE5orHigher(project))) { 463 return getWebServiceURL()+"?Tester"; } else { 465 return getWebServiceURL(); } 467 468 } 469 470 473 public void refreshService(boolean downloadWsdl) { 474 if(downloadWsdl){ 475 int result = RefreshWsDialog.open(downloadWsdl, service.getImplementationClass(), service.getWsdlUrl()); 476 if (RefreshWsDialog.CLOSE==result) return; 477 if (RefreshWsDialog.DO_ALL==result) 478 ((JaxWsChildren)getChildren()).refreshKeys(true, true); 479 else if (RefreshWsDialog.DOWNLOAD_WSDL==result) 480 ((JaxWsChildren)getChildren()).refreshKeys(true, false); 481 else if (RefreshWsDialog.REGENERATE_IMPL_CLASS==result) 482 ((JaxWsChildren)getChildren()).refreshKeys(false, true); 483 else 484 ((JaxWsChildren)getChildren()).refreshKeys(false, false); 485 } else{ 486 int result = RefreshWsDialog.openWithOKButtonOnly(downloadWsdl, service.getImplementationClass(), 487 service.getWsdlUrl()); 488 if(RefreshWsDialog.REGENERATE_IMPL_CLASS==result){ 489 ((JaxWsChildren)getChildren()).refreshKeys(false, true); 490 } else{ 491 ((JaxWsChildren)getChildren()).refreshKeys(false, false); 492 } 493 } 494 } 495 496 public void destroy() throws java.io.IOException { 497 String serviceName = service.getName(); 498 NotifyDescriptor.Confirmation notifyDesc = 499 new NotifyDescriptor.Confirmation(NbBundle.getMessage(JaxWsNode.class, "MSG_CONFIRM_DELETE", serviceName)); 500 DialogDisplayer.getDefault().notify(notifyDesc); 501 if(notifyDesc.getValue() == NotifyDescriptor.YES_OPTION) { 502 JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 503 if (wss!=null) { 504 FileObject localWsdlFolder = wss.getLocalWsdlFolderForService(serviceName,false); 505 if (localWsdlFolder!=null) { 506 FileLock lock=null; 508 FileObject clientArtifactsFolder = localWsdlFolder.getParent(); 509 try { 510 lock = clientArtifactsFolder.lock(); 511 clientArtifactsFolder.delete(lock); 512 } finally { 513 if (lock!=null) lock.releaseLock(); 514 } 515 FileObject wsdlFolder = wss.getWsdlFolder(false); 517 if (wsdlFolder!=null) { 518 FileObject serviceWsdlFolder = wsdlFolder.getFileObject(serviceName); 519 if (serviceWsdlFolder!=null) { 520 try { 521 lock = serviceWsdlFolder.lock(); 522 serviceWsdlFolder.delete(lock); 523 } finally { 524 if (lock!=null) lock.releaseLock(); 525 } 526 } 527 } 528 Project project = FileOwnerQuery.getOwner(srcRoot); 530 FileObject buildImplFo = project.getProjectDirectory().getFileObject(GeneratedFilesHelper.BUILD_IMPL_XML_PATH); 531 try { 532 ExecutorTask wsimportTask = 533 ActionUtils.runTarget(buildImplFo, 534 new String []{"wsimport-service-clean-"+serviceName},null); wsimportTask.waitFinished(); 536 } catch (java.io.IOException ex) { 537 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 538 } catch (IllegalArgumentException ex) { 539 ErrorManager.getDefault().log(ex.getLocalizedMessage()); 540 } 541 } 542 543 wss.removeService(serviceName); 545 546 Boolean isJsr109 = jaxWsModel.getJsr109(); 548 if(isJsr109!=null && !isJsr109.booleanValue()){ 549 if(service.getWsdlUrl() != null){ serviceName = service.getServiceName(); 551 } 552 wss.removeNonJsr109Entries(serviceName); 553 } 554 super.destroy(); 555 } 556 } 557 } 558 559 private FileObject getImplBean() { 560 String implBean = service.getImplementationClass(); 561 if(implBean != null) { 562 return srcRoot.getFileObject(implBean.replace('.','/')+".java"); 563 } 564 return null; 565 } 566 567 private JavaSource getImplBeanJavaSource() { 568 FileObject implBean = getImplBean(); 569 if(implBean != null) { 570 return JavaSource.forFileObject(implBean); 571 } 572 return null; 573 } 574 575 578 579 public Object getValue(String attributeName) { 580 Object retValue; 581 if (attributeName.equals("customDelete")) { retValue = Boolean.TRUE; 583 } else { 584 retValue = super.getValue(attributeName); 585 } 586 return retValue; 587 } 588 589 592 public void configureHandler() { 593 FileObject implBeanFo = getImplBean(); 594 List <String > handlerClasses = new ArrayList <String >(); 595 FileObject handlerFO = null; 596 HandlerChains handlerChains = null; 597 final String [] handlerFileName = new String [1]; 599 final boolean[] isNew = new boolean[]{true}; 600 JavaSource implBeanJavaSrc = JavaSource.forFileObject(implBeanFo); 601 CancellableTask<CompilationController> task = new CancellableTask<CompilationController>() { 602 public void run(CompilationController controller) throws IOException { 603 controller.toPhase(Phase.ELEMENTS_RESOLVED); 604 SourceUtils srcUtils = SourceUtils.newInstance(controller); 605 AnnotationMirror handlerAnnotation = getAnnotation(controller, srcUtils, "javax.jws.HandlerChain"); 606 if (handlerAnnotation!=null) { 607 isNew[0] = false; 608 Map <? extends ExecutableElement, ? extends AnnotationValue> expressions = handlerAnnotation.getElementValues(); 609 for(ExecutableElement ex:expressions.keySet()) { 610 if (ex.getSimpleName().contentEquals("file")) { 611 handlerFileName[0] = (String )expressions.get(ex).getValue(); 612 break; 613 } 614 } 615 } 616 } 617 public void cancel() {} 618 }; 619 try { 620 implBeanJavaSrc.runUserActionTask(task, true); 621 } catch (IOException ex) { 622 ErrorManager.getDefault().notify(ex); 623 } 624 625 if (!isNew[0] && handlerFileName[0]!=null) { 626 handlerFO = implBeanFo.getParent().getFileObject(handlerFileName[0]); 628 if (handlerFO!=null) { 629 try{ 630 handlerChains = 631 HandlerChainsProvider.getDefault().getHandlerChains(handlerFO); 632 }catch(Exception e){ 633 ErrorManager.getDefault().notify(e); 634 return; } 636 HandlerChain[] handlerChainArray = handlerChains.getHandlerChains(); 637 HandlerChain chain = handlerChainArray[0]; 639 Handler[] handlers = chain.getHandlers(); 640 for(int i = 0; i < handlers.length; i++){ 641 handlerClasses.add(handlers[i].getHandlerClass()); 642 } 643 } else { NotifyDescriptor.Message dialogDesc 645 = new NotifyDescriptor.Message(NbBundle.getMessage(JaxWsNode.class, 646 "MSG_HANDLER_FILE_NOT_FOUND", handlerFileName), NotifyDescriptor.INFORMATION_MESSAGE); 647 DialogDisplayer.getDefault().notify(dialogDesc); 648 } 649 } 650 final MessageHandlerPanel panel = new MessageHandlerPanel(project, 651 (String [])handlerClasses.toArray(new String [handlerClasses.size()]), true, service.getName()); 652 String title = NbBundle.getMessage(JaxWsNode.class,"TTL_MessageHandlerPanel"); 653 DialogDescriptor dialogDesc = new DialogDescriptor(panel, title); 654 dialogDesc.setButtonListener(new HandlerButtonListener( panel, 655 handlerChains, handlerFO, implBeanFo, service, isNew[0])); 656 Dialog dialog = DialogDisplayer.getDefault().createDialog(dialogDesc); 657 dialog.setVisible(true); 658 } 659 660 static AnnotationMirror getAnnotation(CompilationController controller, SourceUtils srcUtils, String annotationType) { 661 TypeElement anElement = controller.getElements().getTypeElement(annotationType); 662 if (anElement!=null) { 663 List <? extends AnnotationMirror> annotations = srcUtils.getTypeElement().getAnnotationMirrors(); 664 for(AnnotationMirror annotation : annotations) { 665 if (controller.getTypes().isSameType(anElement.asType(), annotation.getAnnotationType())) { 666 return annotation; 667 } 668 } 669 } 670 return null; 671 } 672 673 private boolean isJsr109Supported(Project project) { 674 JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 675 if (wss != null) { 676 Map properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 677 String serverInstance = (String )properties.get("j2ee.server.instance"); if (serverInstance != null) { 679 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance); 680 if (j2eePlatform != null) { 681 return j2eePlatform.isToolSupported(J2eePlatform.TOOL_JSR109); 682 } 683 } 684 } 685 return false; 686 } 687 688 void refreshImplClass() { 689 if (implBeanClass != null) { 690 content.remove(implBeanClass); 691 } 692 implBeanClass = getImplBean(); 693 content.add(implBeanClass); 694 } 695 696 public boolean canCopy() { 697 return true; 698 } 699 700 public boolean canCut() { 701 return true; 702 } 703 704 public Transferable clipboardCopy() throws IOException { 705 URL url = new URL (getWsdlURL()); 706 boolean connectionOK=false; 707 try { 708 URLConnection connection = url.openConnection(); 709 if (connection instanceof HttpURLConnection ) { 710 HttpURLConnection httpConnection = (HttpURLConnection )connection; 711 try { 712 httpConnection.setRequestMethod("GET"); httpConnection.connect(); 714 if (HttpURLConnection.HTTP_OK == httpConnection.getResponseCode()) 715 connectionOK=true; 716 } catch (java.net.ConnectException ex) { 717 url = null; 719 } finally { 720 if (httpConnection!=null) 721 httpConnection.disconnect(); 722 } 723 if(!connectionOK){ 724 url = null; 726 } 727 } 728 } catch (IOException ex) { 729 url = null; 731 } 732 733 return new WebServiceTransferable(new WebServiceReference(url, 734 service.getWsdlUrl() != null ? service.getServiceName() :service.getName(), project.getProjectDirectory().getName())); 735 } 736 } 737 | Popular Tags |