KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > runtime > actions > RunASVerifierAction


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
20 package org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.actions;
21
22 import org.netbeans.modules.j2ee.sun.ide.j2ee.PluginProperties;
23 import org.openide.nodes.Node;
24 import org.openide.util.HelpCtx;
25 import org.openide.filesystems.FileObject;
26 import org.openide.filesystems.FileUtil;
27 import org.openide.loaders.DataObject;
28 import org.openide.util.NbBundle;
29 import org.openide.util.RequestProcessor;
30 import org.openide.util.actions.NodeAction;
31
32
33 import org.netbeans.modules.j2ee.sun.ide.j2ee.VerifierSupport;
34 /** Action that can always be invoked and work procedurally.
35  * This action will display the verifier tool from app server
36  * @author ludo
37  */

38 public class RunASVerifierAction extends NodeAction {
39     
40     protected Class JavaDoc[] cookieClasses() {
41         return new Class JavaDoc[] {/* SourceCookie.class */};
42     }
43     
44     
45     protected void performAction(Node[] nodes) {
46         if(nodes.length==0 || nodes.length>1) {
47             return;
48         }else{
49             Node node=nodes[0];
50             DataObject dob = (DataObject) node.getCookie(DataObject.class);
51             if(dob!=null){
52                 //System.out.println("Found a dob " + dob+ " which is loaded by "+dob.getLoader());
53
FileObject fo=dob.getPrimaryFile();
54                 String JavaDoc ext=fo.getExt();
55                 //System.out.println(fo + " " + ext);
56
if("jar".equals(ext) || "war".equals(ext) || "ear".equals(ext) || "rar".equals(ext)){
57                      final String JavaDoc jname = FileUtil.toFile(fo).getAbsolutePath();
58                      RequestProcessor.getDefault().post(new Runnable JavaDoc() {
59                         public void run() {
60                             launchVerifier(jname);
61                         }
62                     });
63                 }
64             }
65             
66         }
67     }
68     
69     public void launchVerifier(String JavaDoc archiveLocation){
70         java.io.File JavaDoc irf = org.netbeans.modules.j2ee.sun.api.ServerLocationManager.getLatestPlatformLocation();
71         if (null != irf && irf.exists()) {
72             String JavaDoc installRoot = irf.getAbsolutePath(); //System.getProperty("com.sun.aas.installRoot");
73
System.setProperty("com.sun.aas.configRoot", installRoot+"/config");
74             System.setProperty("com.sun.aas.verifier.xsl", installRoot+"/lib/verifier");
75             System.setProperty("server.name", "server");
76       // ClassLoader origClassLoader=Thread.currentThread().getContextClassLoader();
77
// Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
78
}
79         try{
80             VerifierSupport.launchVerifier(archiveLocation,null);
81         } catch (Throwable JavaDoc t) {
82             t.printStackTrace();
83         } finally {
84    // Thread.currentThread().setContextClassLoader(origClassLoader);
85
}
86     }
87     
88     public String JavaDoc getName() {
89         return NbBundle.getMessage(ShowAdminToolAction.class, "LBL_RunASVeriferAction");
90     }
91     
92     protected String JavaDoc iconResource() {
93         return "org/netbeans/modules/j2ee/sun/ide/resources/ServerInstanceIcon.png";
94     }
95     
96     public HelpCtx getHelpCtx() {
97         return null; // HelpCtx.DEFAULT_HELP;
98
// If you will provide context help then use:
99
// return new HelpCtx(RefreshAction.class);
100
}
101     
102     protected boolean enable(Node[] nodes) {
103         boolean result=false;
104         if(nodes.length==0 || nodes.length>1) {
105             result=false;
106         }else{
107             Node node=nodes[0];
108             DataObject dob = (DataObject) node.getCookie(DataObject.class);
109             if(dob!=null){
110                 //System.out.println("Found a dob " + dob+ " which is loaded by "+dob.getLoader());
111
FileObject fo=dob.getPrimaryFile();
112                 String JavaDoc ext=fo.getExt();
113                 //System.out.println(fo + " " + ext);
114
if("jar".equals(ext) || "war".equals(ext) || "ear".equals(ext) || "rar".equals(ext)){
115                     result=true;
116                 }
117             }
118         }
119         return result;
120     }
121     
122     protected boolean asynchronous() {
123         return false;
124     }
125     
126     
127 }
128
Popular Tags