KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > nodes > JaxWsNode


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 package org.netbeans.modules.websvc.core.jaxws.nodes;
20
21 import java.awt.Dialog JavaDoc;
22 import java.awt.Image JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.UnsupportedEncodingException JavaDoc;
26 import java.net.HttpURLConnection JavaDoc;
27 import java.net.URL JavaDoc;
28 import java.net.URLConnection JavaDoc;
29 import java.net.URLEncoder JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
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 JavaDoc;
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     /**
149      * Find MultiViewCookie for given this node
150      */

151     public static MultiViewCookie getMultiViewCookie(Service service, DataObject dataObject) {
152         Collection JavaDoc<? 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 JavaDoc 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 JavaDoc getShortDescription() {
170         return getWsdlURL();
171     }
172     
173     private static final java.awt.Image JavaDoc WAITING_BADGE =
174             org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/waiting.png"); // NOI18N
175
private static final java.awt.Image JavaDoc ERROR_BADGE =
176             org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/error-badge.gif" ); //NOI18N
177
private static final java.awt.Image JavaDoc SERVICE_BADGE =
178             org.openide.util.Utilities.loadImage( "org/netbeans/modules/websvc/core/webservices/ui/resources/XMLServiceDataIcon.gif" ); //NOI18N
179

180     public java.awt.Image JavaDoc 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 JavaDoc 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 JavaDoc 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         //}
229
return oc;
230     }
231     
232     public Action JavaDoc getPreferredAction() {
233         return SystemAction.get(OpenAction.class);
234     }
235     
236     // Create the popup menu:
237
public Action JavaDoc[] 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     // Handle deleting:
262
public boolean canDestroy() {
263         return true;
264     }
265     
266     
267     /**
268      * get URL for Web Service WSDL file
269      */

270     public String JavaDoc 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         // getting port
279
String JavaDoc portNumber = instanceProperties.getProperty(InstanceProperties.HTTP_PORT_NUMBER);
280         if(portNumber == null || portNumber.equals("")) {
281             portNumber = "8080"; //NOI18N
282
}
283         
284         // getting hostName
285
String JavaDoc serverUrl = instanceProperties.getProperty(InstanceProperties.URL_ATTR);
286         String JavaDoc hostName="localhost"; //NOI18N
287
if (serverUrl!=null && serverUrl.indexOf("::")>0) { //NOI18N
288
int index1 = serverUrl.indexOf("::"); //NOI18N
289
int index2 = serverUrl.lastIndexOf(":"); //NOI18N
290
if (index2>index1+2) hostName = serverUrl.substring(index1+2,index2);
291         }
292         
293         String JavaDoc contextRoot = null;
294         Object JavaDoc moduleType = provider.getJ2eeModule().getModuleType();
295         // need to compute from annotations
296

297         String JavaDoc wsURI=null;
298         if (isJsr109Supported(project) && Util.isJavaEE5orHigher(project)) {
299             try {
300                 wsURI = getServiceUri(moduleType);
301             } catch (UnsupportedEncodingException JavaDoc ex) {
302                 // this shouldn't happen'
303
}
304         } else {
305             try {
306                 wsURI = getNonJsr109Uri(moduleType);
307             } catch (UnsupportedEncodingException JavaDoc ex) {
308                 // this shouldn't happen'
309
}
310         }
311         if(J2eeModule.WAR.equals(moduleType)) {
312             J2eeModuleProvider.ConfigSupport configSupport = provider.getConfigSupport();
313             contextRoot = configSupport.getWebContextRoot();
314             if(contextRoot != null && contextRoot.startsWith("/")) { //NOI18N
315
contextRoot = contextRoot.substring(1);
316             }
317         }/* else if(J2eeModule.EJB.equals(moduleType)) {
318             contextRoot = "webservice";//NO18N for now, we need to find the real value (see bug...57034 and 52265)
319         }*/

320         
321         return "http://"+hostName+":" + portNumber +"/" + (contextRoot != null && !contextRoot.equals("") ? contextRoot + "/" : "") + wsURI; //NOI18N
322
}
323     
324     private String JavaDoc getNonJsr109Uri(Object JavaDoc moduleType) throws UnsupportedEncodingException JavaDoc {
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"); //NOI18N
331
if (sunJaxwsFo!=null) {
332                     try {
333                         Endpoints endpoints = EndpointsProvider.getDefault().getEndpoints(sunJaxwsFo);
334                         if (endpoints!=null) {
335                             String JavaDoc urlPattern = findUrlPattern(endpoints, service.getImplementationClass());
336                             if (urlPattern!=null) return URLEncoder.encode(urlPattern, "UTF-8"); //NOI18N
337
}
338                     } catch (IOException JavaDoc ex) {
339                         ErrorManager.getDefault().log(ex.getLocalizedMessage());
340                     }
341                 }
342             }
343         }
344         return URLEncoder.encode(getNameFromPackageName(service.getImplementationClass()),"UTF-8"); //NOI18N
345
}
346     
347     private String JavaDoc findUrlPattern(Endpoints endpoints, String JavaDoc implementationClass) {
348         Endpoint[] endp = endpoints.getEndpoints();
349         for (int i=0;i<endp.length;i++) {
350             if (implementationClass.equals(endp[i].getImplementation())) {
351                 String JavaDoc urlPattern = endp[i].getUrlPattern();
352                 if (urlPattern!=null) {
353                     return urlPattern.startsWith("/")?urlPattern.substring(1):urlPattern; //NOI18N
354
}
355             }
356         }
357         return null;
358     }
359     
360     private String JavaDoc getServiceUri(final Object JavaDoc moduleType) throws UnsupportedEncodingException JavaDoc {
361         final String JavaDoc[] serviceName=new String JavaDoc[1];
362         final String JavaDoc[] name=new String JavaDoc[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 JavaDoc {
368                     controller.toPhase(Phase.ELEMENTS_RESOLVED);
369                     SourceUtils srcUtils = SourceUtils.newInstance(controller);
370                     TypeElement wsElement = controller.getElements().getTypeElement("javax.jws.WebService"); //NOI18N
371
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"); //NOI18N
380
List JavaDoc<? 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 JavaDoc ex) {
395                 ErrorManager.getDefault().notify(ex);
396             }
397         }
398         
399         String JavaDoc qualifiedImplClassName = service.getImplementationClass();
400         String JavaDoc implClassName = getNameFromPackageName(qualifiedImplClassName);
401         if (serviceName[0]==null) {
402             serviceName[0]=URLEncoder.encode(implClassName+"Service","UTF-8"); //NOI18N
403
}
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                     //per JSR 109, use qualified impl class name for EJB
410
name[0]=qualifiedImplClassName;
411                 } else{
412                     name[0]=implClassName;
413                 }
414                 name[0] = URLEncoder.encode(name[0],"UTF-8"); //NOI18N
415
}
416             return serviceName[0]+"/"+ name[0];
417         } else
418             return serviceName[0];
419     }
420     
421     private boolean resolveServiceUrl( Object JavaDoc moduleType,
422                                         CompilationController controller,
423                                         SourceUtils srcUtils,
424                                         TypeElement wsElement,
425                                         String JavaDoc[] serviceName,
426                                         String JavaDoc[] name) throws IOException JavaDoc {
427         boolean foundWsAnnotation = false;
428         List JavaDoc<? 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 JavaDoc<? extends ExecutableElement, ? extends AnnotationValue> expressions = anMirror.getElementValues();
433                 for(ExecutableElement ex:expressions.keySet()) {
434                     if (ex.getSimpleName().contentEquals("serviceName")) {
435                         serviceName[0] = (String JavaDoc)expressions.get(ex).getValue();
436                         if (serviceName[0]!=null) serviceName[0] = URLEncoder.encode(serviceName[0],"UTF-8"); //NOI18N
437
} else if (ex.getSimpleName().contentEquals("name")) {
438                         name[0] = (String JavaDoc)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             } // end if
445
} // end for
446
return foundWsAnnotation;
447     }
448     
449     private String JavaDoc getNameFromPackageName(String JavaDoc packageName) {
450         int index = packageName.lastIndexOf("."); //NOI18N
451
return index>=0?packageName.substring(index+1):packageName;
452     }
453     
454     public String JavaDoc getWsdlURL() {
455         String JavaDoc wsdlUrl = getWebServiceURL();
456         return wsdlUrl.length()==0?"":wsdlUrl+"?wsdl"; //NOI18N
457
}
458     /**
459      * get URL for Web Service Tester Page
460      */

461     public String JavaDoc getTesterPageURL() {
462         if (isJsr109Supported(project) && (Util.isJavaEE5orHigher(project))) {
463             return getWebServiceURL()+"?Tester"; //NOI18N
464
} else {
465             return getWebServiceURL(); //NOI18N
466
}
467         
468     }
469     
470     /**
471      * refresh service information obtained from wsdl (when wsdl file was changed)
472      */

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 JavaDoc {
497         String JavaDoc 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                     // removing local wsdl and xml artifacts
507
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                     // removing wsdl and xml artifacts from WEB-INF/wsdl
516
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                     // cleaning java artifacts
529
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 JavaDoc[]{"wsimport-service-clean-"+serviceName},null); //NOI18N
535
wsimportTask.waitFinished();
536                     } catch (java.io.IOException JavaDoc ex) {
537                         ErrorManager.getDefault().log(ex.getLocalizedMessage());
538                     } catch (IllegalArgumentException JavaDoc ex) {
539                         ErrorManager.getDefault().log(ex.getLocalizedMessage());
540                     }
541                 }
542                 
543                 // removing service from jax-ws.xml
544
wss.removeService(serviceName);
545                 
546                 // remove non JSR109 entries
547
Boolean JavaDoc isJsr109 = jaxWsModel.getJsr109();
548                 if(isJsr109!=null && !isJsr109.booleanValue()){
549                     if(service.getWsdlUrl() != null){ //if coming from wsdl
550
serviceName = service.getServiceName();
551                     }
552                     wss.removeNonJsr109Entries(serviceName);
553                 }
554                 super.destroy();
555             }
556         }
557     }
558     
559     private FileObject getImplBean() {
560         String JavaDoc 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     /**
576      * Adds possibility to display custom delete dialog
577      */

578     
579     public Object JavaDoc getValue(String JavaDoc attributeName) {
580         Object JavaDoc retValue;
581         if (attributeName.equals("customDelete")) { //NOI18N
582
retValue = Boolean.TRUE;
583         } else {
584             retValue = super.getValue(attributeName);
585         }
586         return retValue;
587     }
588     
589     /**
590      * Implementation of the ConfigureHandlerCookie
591      */

592     public void configureHandler() {
593         FileObject implBeanFo = getImplBean();
594         List JavaDoc<String JavaDoc> handlerClasses = new ArrayList JavaDoc<String JavaDoc>();
595         FileObject handlerFO = null;
596         HandlerChains handlerChains = null;
597         //obtain the handler config file, if any from annotation in implbean
598
final String JavaDoc[] handlerFileName = new String JavaDoc[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 JavaDoc {
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 JavaDoc<? extends ExecutableElement, ? extends AnnotationValue> expressions = handlerAnnotation.getElementValues();
609                     for(ExecutableElement ex:expressions.keySet()) {
610                         if (ex.getSimpleName().contentEquals("file")) {
611                             handlerFileName[0] = (String JavaDoc)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 JavaDoc ex) {
622             ErrorManager.getDefault().notify(ex);
623         }
624         
625         if (!isNew[0] && handlerFileName[0]!=null) {
626             // look for handlerFile in the same directory as the implbean
627
handlerFO = implBeanFo.getParent().getFileObject(handlerFileName[0]);
628             if (handlerFO!=null) {
629                 try{
630                     handlerChains =
631                             HandlerChainsProvider.getDefault().getHandlerChains(handlerFO);
632                 }catch(Exception JavaDoc e){
633                     ErrorManager.getDefault().notify(e);
634                     return; //TODO handle this
635
}
636                 HandlerChain[] handlerChainArray = handlerChains.getHandlerChains();
637                 //there is always only one, so get the first one
638
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 { //unable to find the handler file, display a warning
644
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 JavaDoc[])handlerClasses.toArray(new String JavaDoc[handlerClasses.size()]), true, service.getName());
652         String JavaDoc 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 JavaDoc dialog = DialogDisplayer.getDefault().createDialog(dialogDesc);
657         dialog.setVisible(true);
658     }
659   
660     static AnnotationMirror getAnnotation(CompilationController controller, SourceUtils srcUtils, String JavaDoc annotationType) {
661         TypeElement anElement = controller.getElements().getTypeElement(annotationType);
662         if (anElement!=null) {
663             List JavaDoc<? 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 JavaDoc properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
677             String JavaDoc serverInstance = (String JavaDoc)properties.get("j2ee.server.instance"); //NOI18N
678
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 JavaDoc clipboardCopy() throws IOException JavaDoc {
705         URL JavaDoc url = new URL JavaDoc(getWsdlURL());
706         boolean connectionOK=false;
707         try {
708             URLConnection JavaDoc connection = url.openConnection();
709             if (connection instanceof HttpURLConnection JavaDoc) {
710                 HttpURLConnection JavaDoc httpConnection = (HttpURLConnection JavaDoc)connection;
711                 try {
712                     httpConnection.setRequestMethod("GET"); //NOI18N
713
httpConnection.connect();
714                     if (HttpURLConnection.HTTP_OK == httpConnection.getResponseCode())
715                         connectionOK=true;
716                 } catch (java.net.ConnectException JavaDoc ex) {
717                     //TODO: throw exception here?
718
url = null;
719                 } finally {
720                     if (httpConnection!=null)
721                         httpConnection.disconnect();
722                 }
723                 if(!connectionOK){
724                     //TODO: throw exception here?
725
url = null;
726                 }
727             }
728         } catch (IOException JavaDoc ex) {
729             //TODO: throw exception here?
730
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