KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > core > jaxws > actions > WsTesterPageAction


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.actions;
20
21 import java.io.IOException JavaDoc;
22 import java.net.HttpURLConnection JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.net.URLConnection JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import java.util.Map JavaDoc;
28 import org.netbeans.api.project.FileOwnerQuery;
29 import org.netbeans.api.project.Project;
30 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment;
31 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform;
32 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport;
33 import org.netbeans.modules.websvc.jaxws.api.JaxWsTesterCookie;
34 import org.openide.DialogDisplayer;
35 import org.openide.ErrorManager;
36 import org.openide.NotifyDescriptor;
37 import org.openide.awt.HtmlBrowser;
38 import org.openide.awt.StatusDisplayer;
39 import org.openide.filesystems.FileObject;
40 import org.openide.util.RequestProcessor;
41 import org.openide.util.actions.CookieAction;
42 import org.openide.util.HelpCtx;
43 import org.openide.util.NbBundle;
44 import org.openide.nodes.Node;
45
46 public class WsTesterPageAction extends CookieAction {
47     public String JavaDoc getName() {
48         return NbBundle.getMessage(WsTesterPageAction.class, "LBL_TesterPageAction");
49     }
50     
51     public HelpCtx getHelpCtx() {
52         return HelpCtx.DEFAULT_HELP;
53     }
54     
55     protected int mode() {
56         return MODE_EXACTLY_ONE;
57     }
58     
59     protected Class JavaDoc[] cookieClasses() {
60         return new Class JavaDoc[] {JaxWsTesterCookie.class};
61     }
62     
63     protected boolean asynchronous() {
64         return false;
65     }
66     
67     protected void performAction(Node[] activatedNodes) {
68         JaxWsTesterCookie cookie =
69            activatedNodes[0].getCookie(JaxWsTesterCookie.class);
70         String JavaDoc wsdlURL = cookie.getTesterPageURL();
71         try {
72             final URL JavaDoc url = new URL JavaDoc(wsdlURL);
73             if (url!=null) {
74                 RequestProcessor.getDefault().post(new Runnable JavaDoc() {
75                     public void run() {
76                         boolean connectionOK=false;
77                         try {
78                             URLConnection JavaDoc connection = url.openConnection();
79                             if (connection instanceof HttpURLConnection JavaDoc) {
80                                 HttpURLConnection JavaDoc httpConnection = (HttpURLConnection JavaDoc)connection;
81                                 try {
82                                     httpConnection.setRequestMethod("GET"); //NOI18N
83
httpConnection.connect();
84                                     if (HttpURLConnection.HTTP_OK == httpConnection.getResponseCode())
85                                         connectionOK=true;
86                                 } catch (java.net.ConnectException JavaDoc ex) {
87                                     // doing nothing - display warning
88
} finally {
89                                     if (httpConnection!=null)
90                                     httpConnection.disconnect();
91                                 }
92                             }
93
94                         } catch (IOException JavaDoc ex) {
95                             ErrorManager.getDefault().notify(ex);
96                         }
97                         if (connectionOK) {
98                             HtmlBrowser.URLDisplayer.getDefault().showURL(url);
99                         } else {
100                             DialogDisplayer.getDefault().notify(
101                                     new NotifyDescriptor.Message(
102                                         NbBundle.getMessage(WsTesterPageAction.class,"MSG_UNABLE_TO_OPEN_TEST_PAGE",url),
103                                         NotifyDescriptor.WARNING_MESSAGE));
104                         }
105                     }
106                     
107                 });
108             }
109         } catch (MalformedURLException JavaDoc ex) {
110             StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(WsTesterPageAction.class,
111                     "TXT_TesterPageUrl", wsdlURL)); //NOI18N
112
}
113     }
114     
115     protected boolean enable(Node[] activatedNodes) {
116         if (activatedNodes==null || activatedNodes.length==0) return false;
117         FileObject srcRoot = (FileObject)activatedNodes[0].getLookup().lookup(FileObject.class);
118         if (srcRoot!=null) {
119             Project project = FileOwnerQuery.getOwner(srcRoot);
120             if (project!=null) {
121                 return isTesterPageSupported(project);
122             }
123         }
124         return false;
125     }
126     
127     private boolean isTesterPageSupported(Project project) {
128         JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory());
129         if (wss != null) {
130             Map JavaDoc properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties();
131             String JavaDoc serverInstance = (String JavaDoc)properties.get("j2ee.server.instance"); //NOI18N
132
if (serverInstance != null) {
133                 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance);
134                 if (j2eePlatform != null) {
135                     return j2eePlatform.isToolSupported("jaxws-tester"); //NOI18N
136
}
137             }
138         }
139         return false;
140     }
141     
142
143 }
144
Popular Tags