KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > bridge > apis > AppserverMgmtActiveNode


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.bridge.apis;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import javax.management.Attribute JavaDoc;
24 import javax.management.MBeanAttributeInfo JavaDoc;
25 import org.netbeans.modules.j2ee.sun.util.PropertySupportFactory;
26 import org.openide.nodes.Children;
27 import org.openide.nodes.PropertySupport;
28 import org.openide.nodes.Sheet;
29
30
31
32 /**
33  * The parent class for all appserver plugin management leaf nodes. All leaf
34  * nodes for the NetBeans runtime tab J2EE plugin must extend this class for
35  * effectively communicating via AMX API.
36  */

37 public abstract class AppserverMgmtActiveNode extends AppserverMgmtNode {
38   
39     private Controller controller;
40     private PropertySupportFactory propSupportFactory =
41                 PropertySupportFactory.getInstance();
42     
43     /**
44      * Abstract constructor for an AppserverLeafNode called by subclass.
45      *
46      * @param nodeType The type of leaf node to construct (e.g. JVM, etc.)
47      */

48     public AppserverMgmtActiveNode(Children children, String JavaDoc nodeType) {
49         super(children, nodeType);
50     }
51
52     
53     /**
54      * Abstract constructor for an AppserverLeafNode called by subclass.
55      *
56      * @param nodeType The type of leaf node to construct (e.g. JVM, etc.)
57      */

58     public AppserverMgmtActiveNode(Children children, Controller controller,
59             String JavaDoc nodeType) {
60         super(children, nodeType);
61         this.controller = controller;
62     }
63     
64     
65     /**
66      * Abstract constructor for an AppserverLeafNode called by subclass.
67      *
68      * @param nodeType The type of leaf node to construct (e.g. JVM, etc.)
69      */

70     public AppserverMgmtActiveNode(final Children children,
71             final AppserverMgmtController controller,
72             final String JavaDoc nodeType) {
73         super(controller, children, nodeType);
74     }
75     
76     
77     /**
78      * Returns the controller object for interfacing with AMX apis.
79      *
80      * @return The controller.
81      */

82     protected final Controller getController() {
83         return controller;
84     }
85     
86     /**
87      * Creates a properties Sheet for viewing when a user chooses the option
88      * from the right-click menu.
89      *
90      * @returns the Sheet to display when Properties is chosen by the user.
91      */

92     protected Sheet createSheet() {
93         Sheet sheet = Sheet.createDefault();
94         
95         ClassLoader JavaDoc origClassLoader=Thread.currentThread().getContextClassLoader();
96         try {
97             Thread.currentThread().setContextClassLoader(
98                     this.getClass().getClassLoader());
99             
100             Sheet.Set props = sheet.get(Sheet.PROPERTIES);
101             props.put(createPropertySupportArray(getSheetProperties()));
102             return sheet;
103         }catch(NullPointerException JavaDoc ex){
104             return sheet;
105         } catch(RuntimeException JavaDoc rex) {
106             return sheet;
107         } finally {
108             Thread.currentThread().setContextClassLoader(origClassLoader);
109         }
110     }
111
112     
113     /**
114      * Creates a PropertySupport array from a map of component properties.
115      *
116      * @param properties The properties of the component.
117      * @return An array of PropertySupport objects.
118      */

119     PropertySupport[] createPropertySupportArray(final java.util.Map JavaDoc attrMap) {
120         PropertySupport[] supports = new PropertySupport[attrMap.size()];
121         int i = 0;
122         for(Iterator JavaDoc itr = attrMap.keySet().iterator(); itr.hasNext(); ) {
123             Attribute JavaDoc attr = (Attribute JavaDoc) itr.next();
124             MBeanAttributeInfo JavaDoc info = (MBeanAttributeInfo JavaDoc) attrMap.get(attr);
125             supports[i] =
126                 propSupportFactory.getPropertySupport(this, attr, info);
127             i++;
128         }
129         return supports;
130     }
131
132     
133     /**
134      * Return a list of all those String properties to be ignored for display.
135      *
136      * @return A java.util.List of all String properties to ignore in the
137      * display (Property editors).
138      */

139     protected List JavaDoc getPropertiesToIgnore() {
140         return null;
141     }
142     
143     
144     /**
145      * Returns all the properties of the leaf node to disply in the properties
146      * window (or Sheet). This must be overriden in order for the Sheet to be
147      * processed.
148      *
149      * @returns a java.util.Map of all properties to be accessed from the Sheet.
150      */

151     abstract protected java.util.Map JavaDoc getSheetProperties();
152     
153     /**
154      * Sets the property as an attribute to the underlying AMX mbeans. It
155      * usually will delegate to the controller object which is responsible for
156      * finding the correct AMX mbean objectname in order to execute a
157      * JMX setAttribute.
158      *
159      * @param attrName The name of the property to be set.
160      * @param value The value retrieved from the property sheet to be set in the
161      * backend.
162      * @returns the updated Attribute accessed from the Sheet.
163      */

164     abstract public javax.management.Attribute JavaDoc setSheetProperty(String JavaDoc attrName, Object JavaDoc value);
165     
166     
167 }
168
Popular Tags