001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.j2ee.sun.ide.runtime.nodes;
042:
043: import java.beans.PropertyChangeEvent;
044: import java.beans.PropertyChangeListener;
045: import java.util.Iterator;
046: import javax.swing.Action;
047: import javax.management.Attribute;
048: import javax.management.MBeanAttributeInfo;
049: import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
050: import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtContainerNode;
051: import org.netbeans.modules.j2ee.sun.bridge.apis.AppserverMgmtController;
052: import org.openide.util.RequestProcessor;
053: import org.openide.util.actions.SystemAction;
054:
055: import org.netbeans.modules.j2ee.sun.util.NodeTypes;
056: import org.netbeans.modules.j2ee.sun.ide.controllers.ControllerUtil;
057:
058: import javax.enterprise.deploy.spi.DeploymentManager;
059: import org.netbeans.modules.j2ee.sun.util.PropertySupportFactory;
060: import org.openide.nodes.PropertySupport;
061: import org.openide.nodes.Sheet;
062:
063: /**
064: */
065: public class DomainRootNode extends AppserverMgmtContainerNode
066: implements PropertyChangeListener, Runnable {
067:
068: private static final String NODE_TYPE = NodeTypes.DOMAIN;
069: private PropertySupportFactory propSupportFactory = PropertySupportFactory
070: .getInstance();
071: private DeploymentManager deployMgr;
072:
073: /**
074: *
075: */
076: public DomainRootNode(final DeploymentManager dm) {
077: super (null, NODE_TYPE);
078: deployMgr = dm;
079: SunDeploymentManagerInterface sdm = (SunDeploymentManagerInterface) deployMgr;
080: sdm.addPropertyChangeListener(this );
081: /*
082: this is to make sure classes are loaded in IDE classloader if
083: user runs an app from the projects tab
084: */
085: javax.swing.SwingUtilities.invokeLater(new Runnable() {
086: public void run() {
087: refresh();
088: }
089: });
090:
091: shutOffJMXAndAMXLogging();
092: }
093:
094: public void refresh() {
095: RequestProcessor.getDefault().post(this );
096: }
097:
098: public void run() {
099: SunDeploymentManagerInterface sdm = (SunDeploymentManagerInterface) deployMgr;
100: if (sdm.isSuspended()) {
101: return;
102: }
103: if (sdm.grabInnerDM(true)) {
104: try {
105: AppserverMgmtController a = ControllerUtil
106: .getAppserverMgmtControllerFromDeployMgr(deployMgr);
107: setAppserverMgmtController(a);
108: super .refresh();
109: } finally {
110: sdm.releaseInnerDM();
111: }
112: } else {
113: javax.swing.SwingUtilities.invokeLater(new Runnable() {
114: public void run() {
115: refresh();
116: }
117: });
118: }
119: }
120:
121: /**
122: * Return the actions associated with the menu drop down seen when
123: * a user right-clicks on an the node in the plugin. This method here
124: * is overidden to eliminate duplicate refresh options at the server
125: * node level.
126: *
127: * @param boolean true/false
128: * @return An array of Action objects.
129: */
130: public Action[] getActions(boolean flag) {
131: return new SystemAction[] {};
132: }
133:
134: /**
135: * Creates a properties Sheet for viewing when a user chooses the option
136: * from the right-click menu.
137: *
138: * @returns the Sheet to display when Properties is chosen by the user.
139: */
140: protected Sheet createSheet() {
141: Sheet sheet = Sheet.createDefault();
142: ClassLoader origClassLoader = Thread.currentThread()
143: .getContextClassLoader();
144: try {
145: Thread.currentThread().setContextClassLoader(
146: this .getClass().getClassLoader());
147: Sheet.Set props = sheet.get(Sheet.PROPERTIES);
148: props.put(createPropertySupportArray(getSheetProperties()));
149: return sheet;
150: } catch (RuntimeException rex) {
151: return sheet;
152: } finally {
153: Thread.currentThread().setContextClassLoader(
154: origClassLoader);
155: }
156: }
157:
158: /**
159: * Creates a PropertySupport array from a map of component properties.
160: *
161: * @param properties The properties of the component.
162: * @return An array of PropertySupport objects.
163: */
164: private PropertySupport[] createPropertySupportArray(
165: final java.util.Map attrMap) {
166: PropertySupport[] supports = new PropertySupport[attrMap.size()];
167: int i = 0;
168: for (Iterator itr = attrMap.keySet().iterator(); itr.hasNext();) {
169: Attribute attr = (Attribute) itr.next();
170: MBeanAttributeInfo info = (MBeanAttributeInfo) attrMap
171: .get(attr);
172: supports[i] = propSupportFactory.createLogLevelProperty(
173: this , attr, info);
174: i++;
175: }
176: return supports;
177: }
178:
179: /**
180: * Return the SheetProperties to be displayed for the Domain Node
181: *
182: * @return A java.util.Map containing all Log levels
183: */
184: private java.util.Map getSheetProperties() {
185: return getAppserverMgmtController().getLogProperties("server"); //NOI18N
186: }
187:
188: /**
189: * Sets the property as an attribute to the underlying AMX mbeans. It
190: * usually will delegate to the controller object which is responsible for
191: * finding the correct AMX mbean objectname in order to execute a
192: * JMX setAttribute.
193: *
194: * @param attrName The name of the property to be set.
195: * @param value The value retrieved from the property sheet to be set in the
196: * backend.
197: * @returns the updated Attribute accessed from the Sheet.
198: */
199: public javax.management.Attribute setSheetProperty(String attrName,
200: Object value) {
201: try {
202: return getAppserverMgmtController().setLogProperties(
203: "server", attrName, value); //NOI18N
204: } catch (RuntimeException rex) {
205: return null;
206: }
207: }
208:
209: /**
210: *
211: *
212: */
213: private void shutOffJMXAndAMXLogging() {
214: //local logger
215:
216: java.util.logging.Logger.getLogger(
217: "org.netbeans.modules.j2ee.sun").setLevel(
218: java.util.logging.Level.OFF);
219:
220: //amx loggers
221: java.util.logging.Logger.getLogger(
222: "javax.enterprise.system.tools.admin").setLevel(
223: java.util.logging.Level.OFF);
224: java.util.logging.Logger.getLogger(
225: "javax.enterprise.system.tools.admin.client").setLevel(
226: java.util.logging.Level.OFF);
227: java.util.logging.Logger.getLogger(
228: "javax.enterprise.system.tools.admin.server").setLevel(
229: java.util.logging.Level.OFF);
230: java.util.logging.Logger.getLogger(
231: "javax.enterprise.system.tools.admin.server.mbeans")
232: .setLevel(java.util.logging.Level.OFF);
233:
234: //jmx remote logger
235: java.util.logging.Logger.getLogger("javax.management.remote")
236: .setLevel(java.util.logging.Level.OFF);
237: }
238:
239: public void propertyChange(PropertyChangeEvent evt) {
240:
241: //setAppserverMgmtController(ControllerUtil.getAppserverMgmtControllerFromDeployMgr( deployMgr));
242: javax.swing.SwingUtilities.invokeLater(new Runnable() {
243: public void run() {
244: refresh();
245: }
246: });
247: }
248:
249: }
|