KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > runtime > nodes > DomainRootNode


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.j2ee.sun.ide.runtime.nodes;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import javax.management.Attribute JavaDoc;
26 import javax.management.MBeanAttributeInfo JavaDoc;
27 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
28 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtContainerNode;
29 import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtController;
30 import org.openide.util.RequestProcessor;
31 import org.openide.util.actions.SystemAction;
32
33 import org.netbeans.modules.j2ee.sun.util.NodeTypes;
34 import org.netbeans.modules.j2ee.sun.ide.controllers.ControllerUtil;
35
36 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
37 import org.netbeans.modules.j2ee.sun.util.PropertySupportFactory;
38 import org.openide.nodes.PropertySupport;
39 import org.openide.nodes.Sheet;
40
41 /**
42  */

43 public class DomainRootNode extends AppserverMgmtContainerNode implements PropertyChangeListener JavaDoc, Runnable JavaDoc{
44     
45     private static final String JavaDoc NODE_TYPE = NodeTypes.DOMAIN;
46     private PropertySupportFactory propSupportFactory =
47                 PropertySupportFactory.getInstance();
48     private DeploymentManager JavaDoc deployMgr;
49     
50     
51     /**
52      *
53      */

54     public DomainRootNode(final DeploymentManager JavaDoc dm) {
55         super(null, NODE_TYPE);
56         deployMgr =dm;
57         SunDeploymentManagerInterface sdm=(SunDeploymentManagerInterface)deployMgr;
58         sdm.addPropertyChangeListener(this);
59         /*
60          this is to make sure classes are loaded in IDE classloader if
61          user runs an app from the projects tab
62         */

63         javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
64             public void run() {
65                  refresh();
66             }
67         });
68         
69         shutOffJMXAndAMXLogging();
70     }
71     
72     public void refresh(){
73         RequestProcessor.getDefault().post(this);
74     }
75     
76     public void run() {
77         SunDeploymentManagerInterface sdm=(SunDeploymentManagerInterface)deployMgr;
78         if (sdm.isSuspended()) {
79             return;
80         }
81         if (sdm.grabInnerDM(true)) {
82             try {
83                 AppserverMgmtController a= ControllerUtil.getAppserverMgmtControllerFromDeployMgr( deployMgr);
84                 setAppserverMgmtController(a);
85                 super.refresh();
86             } finally {
87                 sdm.releaseInnerDM();
88             }
89         } else {
90             javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
91                 public void run() {
92                      refresh();
93                 }
94             });
95         }
96     }
97     /**
98      * Return the actions associated with the menu drop down seen when
99      * a user right-clicks on an the node in the plugin. This method here
100      * is overidden to eliminate duplicate refresh options at the server
101      * node level.
102      *
103      * @param boolean true/false
104      * @return An array of Action objects.
105      */

106     public Action JavaDoc[] getActions(boolean flag) {
107         return new SystemAction[] {};
108     }
109     
110     /**
111      * Creates a properties Sheet for viewing when a user chooses the option
112      * from the right-click menu.
113      *
114      * @returns the Sheet to display when Properties is chosen by the user.
115      */

116     protected Sheet createSheet() {
117         Sheet sheet = Sheet.createDefault();
118         ClassLoader JavaDoc origClassLoader=Thread.currentThread().getContextClassLoader();
119         try {
120             Thread.currentThread().setContextClassLoader(
121                     this.getClass().getClassLoader());
122             Sheet.Set props = sheet.get(Sheet.PROPERTIES);
123             props.put(createPropertySupportArray(getSheetProperties()));
124             return sheet;
125         } catch(RuntimeException JavaDoc rex) {
126             return sheet;
127         } finally {
128             Thread.currentThread().setContextClassLoader(origClassLoader);
129         }
130     }
131     
132     /**
133      * Creates a PropertySupport array from a map of component properties.
134      *
135      * @param properties The properties of the component.
136      * @return An array of PropertySupport objects.
137      */

138     private PropertySupport[] createPropertySupportArray(final java.util.Map JavaDoc attrMap) {
139         PropertySupport[] supports = new PropertySupport[attrMap.size()];
140         int i = 0;
141         for(Iterator JavaDoc itr = attrMap.keySet().iterator(); itr.hasNext(); ) {
142             Attribute JavaDoc attr = (Attribute JavaDoc) itr.next();
143             MBeanAttributeInfo JavaDoc info = (MBeanAttributeInfo JavaDoc) attrMap.get(attr);
144             supports[i] =
145                 propSupportFactory.createLogLevelProperty(this, attr, info);
146             i++;
147         }
148         return supports;
149     }
150     
151    /**
152      * Return the SheetProperties to be displayed for the Domain Node
153      *
154      * @return A java.util.Map containing all Log levels
155     */

156     private java.util.Map JavaDoc getSheetProperties() {
157         return getAppserverMgmtController().getLogProperties("server"); //NOI18N
158
}
159     
160     /**
161      * Sets the property as an attribute to the underlying AMX mbeans. It
162      * usually will delegate to the controller object which is responsible for
163      * finding the correct AMX mbean objectname in order to execute a
164      * JMX setAttribute.
165      *
166      * @param attrName The name of the property to be set.
167      * @param value The value retrieved from the property sheet to be set in the
168      * backend.
169      * @returns the updated Attribute accessed from the Sheet.
170      */

171     public javax.management.Attribute JavaDoc setSheetProperty(String JavaDoc attrName, Object JavaDoc value) {
172         try {
173             return getAppserverMgmtController().setLogProperties("server", attrName, value); //NOI18N
174
} catch (RuntimeException JavaDoc rex) {
175             return null;
176         }
177     }
178     
179     /**
180      *
181      *
182      */

183     private void shutOffJMXAndAMXLogging() {
184         //local logger
185

186         java.util.logging.Logger.getLogger(
187                 "org.netbeans.modules.j2ee.sun").
188                         setLevel(java.util.logging.Level.OFF);
189         
190         //amx loggers
191
java.util.logging.Logger.getLogger(
192                 "javax.enterprise.system.tools.admin").
193                         setLevel(java.util.logging.Level.OFF);
194         java.util.logging.Logger.getLogger(
195                 "javax.enterprise.system.tools.admin.client").
196                         setLevel(java.util.logging.Level.OFF);
197         java.util.logging.Logger.getLogger(
198                 "javax.enterprise.system.tools.admin.server").
199                         setLevel(java.util.logging.Level.OFF);
200         java.util.logging.Logger.getLogger(
201                 "javax.enterprise.system.tools.admin.server.mbeans").
202                         setLevel(java.util.logging.Level.OFF);
203         
204         //jmx remote logger
205
java.util.logging.Logger.getLogger(
206                 "javax.management.remote").
207                         setLevel(java.util.logging.Level.OFF);
208     }
209
210     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
211
212         
213         //setAppserverMgmtController(ControllerUtil.getAppserverMgmtControllerFromDeployMgr( deployMgr));
214
javax.swing.SwingUtilities.invokeLater(new Runnable JavaDoc() {
215             public void run() {
216                 refresh();
217             }
218         });
219     }
220     
221
222
223 }
224
Popular Tags