KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > jboss4 > nodes > actions > OpenServerLogAction


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.jboss4.nodes.actions;
21
22 import java.io.File JavaDoc;
23 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
24 import org.netbeans.modules.j2ee.deployment.plugins.api.UISupport;
25 import org.netbeans.modules.j2ee.jboss4.JBDeploymentManager;
26 import org.netbeans.modules.j2ee.jboss4.ide.JBLogWriter;
27 import org.netbeans.modules.j2ee.jboss4.ide.ui.JBPluginProperties;
28 import org.netbeans.modules.j2ee.jboss4.nodes.JBManagerNode;
29 import org.openide.nodes.Node;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32 import org.openide.util.actions.NodeAction;
33 import org.openide.windows.InputOutput;
34
35 /**
36  *
37  * @author Libor Kotouc
38  */

39 public class OpenServerLogAction extends NodeAction {
40     
41     public OpenServerLogAction() {
42     }
43
44     protected boolean enable(Node[] activatedNodes) {
45         return true;
46     }
47
48     protected void performAction(Node[] activatedNodes) {
49         for (Node activatedNode : activatedNodes) {
50             Object JavaDoc node = activatedNode.getLookup().lookup(JBManagerNode.class);
51             
52             if (!(node instanceof JBManagerNode)) {
53                 continue;
54             }
55             
56             JBDeploymentManager dm = ((JBManagerNode)node).getDeploymentManager();
57             InputOutput io = UISupport.getServerIO(dm.getUrl());
58             if (io != null) {
59                 io.select();
60             }
61             
62             String JavaDoc instanceName = dm.getInstanceProperties().getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
63             JBLogWriter logWriter = JBLogWriter.getInstance(instanceName);
64             if (logWriter == null) {
65                 if (JBLogWriter.VERBOSE) {
66                     System.out.println("CREATING LOG WRITER reading from the server.log file");
67                 }
68                 logWriter = JBLogWriter.createInstance(io, instanceName);
69                 String JavaDoc serverDir = dm.getInstanceProperties().getProperty(JBPluginProperties.PROPERTY_SERVER_DIR);
70                 String JavaDoc logFileName = serverDir + File.separator + "log" + File.separator + "server.log" ; // NOI18N
71
File JavaDoc logFile = new File JavaDoc(logFileName);
72                 if (logFile.exists()) {
73                     logWriter.start(logFile);
74                 }
75             }
76             else {
77                 logWriter.refresh();
78             }
79         }
80     }
81
82     public HelpCtx getHelpCtx() {
83         return HelpCtx.DEFAULT_HELP;
84     }
85
86     public String JavaDoc getName() {
87         return NbBundle.getMessage(OpenServerLogAction.class, "LBL_OpenServerLogAction");
88     }
89
90     public boolean asynchronous() {
91         return false;
92     }
93     
94 }
95
Popular Tags