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-2007 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.sun.manager.jbi.nodes;
042:
043: import com.sun.esb.management.api.administration.AdministrationService;
044: import com.sun.esb.management.api.configuration.ConfigurationService;
045: import com.sun.esb.management.api.deployment.DeploymentService;
046: import com.sun.esb.management.api.installation.InstallationService;
047: import com.sun.esb.management.common.ManagementRemoteException;
048: import java.util.Map;
049: import java.util.logging.Level;
050: import java.util.logging.Logger;
051: import javax.management.Attribute;
052: import javax.management.MBeanAttributeInfo;
053: import org.netbeans.modules.sun.manager.jbi.management.AppserverJBIMgmtController;
054: import org.netbeans.modules.sun.manager.jbi.management.wrapper.api.RuntimeManagementServiceWrapper;
055: import org.netbeans.modules.sun.manager.jbi.nodes.property.JBIPropertySupportFactory;
056: import org.netbeans.modules.sun.manager.jbi.nodes.property.PropertySheetOwner;
057: import org.openide.DialogDisplayer;
058: import org.openide.NotifyDescriptor;
059: import org.openide.nodes.AbstractNode;
060: import org.openide.nodes.Children;
061: import org.openide.nodes.PropertySupport;
062: import org.openide.nodes.Sheet;
063: import org.openide.util.NbBundle;
064:
065: /**
066: * Abstract super class for all nodes in JBI manager.
067: *
068: * @author jqian
069: */
070: public abstract class AppserverJBIMgmtNode extends AbstractNode
071: implements PropertySheetOwner {
072:
073: protected static final String GENERAL_SHEET_SET_NAME = "GENERAL"; // NOI18N
074:
075: protected static final String SERVER_TARGET = AppserverJBIMgmtController.SERVER_TARGET;
076:
077: protected static final String MODEL_BEAN_INFO_PACKAGE_NAME = "org.netbeans.modules.sun.manager.jbi.management.model.beaninfo"; // NOI18N
078:
079: private static Logger logger;
080: private NodeType nodeType;
081: private AppserverJBIMgmtController appsrvrJBIMgmtController;
082:
083: /**
084: *
085: *
086: */
087: public AppserverJBIMgmtNode(
088: final AppserverJBIMgmtController controller,
089: final Children children, final NodeType nodeType) {
090: super (children);
091:
092: this .nodeType = nodeType;
093:
094: appsrvrJBIMgmtController = controller;
095:
096: if (appsrvrJBIMgmtController == null) {
097: getLogger().log(
098: Level.FINE,
099: "AppserverJBIMgmtController is " + "null for ["
100: + nodeType + "]"); // NOI18N
101: }
102: }
103:
104: protected NodeType getNodeType() {
105: return nodeType;
106: }
107:
108: /**
109: *
110: */
111: public AppserverJBIMgmtController getAppserverJBIMgmtController() {
112: return appsrvrJBIMgmtController;
113: }
114:
115: /**
116: * Creates a new property sheet set and adds it into the property sheet.
117: *
118: * @param sheet property sheet
119: * @param name name of the property sheet set
120: * @param displayNameLabel bundle name of the diaplay name of the
121: * property sheet set
122: * @param descriptoinLabel bundle name of the description of the
123: * property sheet set
124: * @parm properties property map
125: */
126: protected void addSheetSet(Sheet sheet, String name,
127: String displayNameLabel, String descriptionLabel,
128: Map<Attribute, ? extends MBeanAttributeInfo> properties) {
129:
130: if (properties == null) {
131: return;
132: }
133:
134: try {
135: PropertySupport[] propertySupports = createPropertySupportArray(properties);
136:
137: Sheet.Set sheetSet = createSheetSet(name, displayNameLabel,
138: descriptionLabel, propertySupports);
139:
140: if (sheetSet != null) {
141: sheet.put(sheetSet);
142: }
143: } catch (Exception e) {
144: e.printStackTrace();
145: }
146: }
147:
148: /**
149: * Creates a property sheet set.
150: *
151: * @param name name of the property sheet set
152: * @param displayNameLabel bundle name of the diaplay name of the
153: * property sheet set
154: * @param descriptoinLabel bundle name of the description of the
155: * property sheet set
156: * @parm properties property map
157: */
158: protected Sheet.Set createSheetSet(String name,
159: String displayNameLabel, String descriptionLabel,
160: Map<Attribute, ? extends MBeanAttributeInfo> properties) {
161:
162: if (properties == null) {
163: return null;
164: }
165:
166: PropertySupport[] propertySupports = createPropertySupportArray(properties);
167:
168: Sheet.Set sheetSet = createSheetSet(name, displayNameLabel,
169: descriptionLabel, propertySupports);
170:
171: return sheetSet;
172: }
173:
174: protected Sheet.Set createSheetSet(String name,
175: String displayNameLabel, String descriptionLabel,
176: PropertySupport[] propertySupports) {
177:
178: Sheet.Set sheetSet = new Sheet.Set();
179: sheetSet.setName(name);
180: sheetSet.setDisplayName(NbBundle.getMessage(
181: AppserverJBIMgmtNode.class, displayNameLabel));
182: sheetSet.setShortDescription(NbBundle.getMessage(
183: AppserverJBIMgmtNode.class, descriptionLabel));
184: if (propertySupports != null) {
185: sheetSet.put(propertySupports);
186: }
187:
188: return sheetSet;
189: }
190:
191: /**
192: * Creates a PropertySupport array from a map of component properties.
193: *
194: * @param properties The properties of the component.
195: * @return An array of PropertySupport objects.
196: */
197: protected PropertySupport[] createPropertySupportArray(
198: final Map<Attribute, ? extends MBeanAttributeInfo> attrMap) {
199: PropertySupport[] supports = new PropertySupport[attrMap.size()];
200:
201: int i = 0;
202: for (Attribute attr : attrMap.keySet()) {
203: MBeanAttributeInfo info = attrMap.get(attr);
204: supports[i++] = JBIPropertySupportFactory
205: .getPropertySupport(this , attr, info);
206: }
207: return supports;
208: }
209:
210: protected RuntimeManagementServiceWrapper getRuntimeManagementServiceWrapper() {
211: try {
212: return getAppserverJBIMgmtController()
213: .getRuntimeManagementServiceWrapper();
214: } catch (ManagementRemoteException e) {
215: NotifyDescriptor d = new NotifyDescriptor.Message(e
216: .getMessage(), NotifyDescriptor.ERROR_MESSAGE);
217: DialogDisplayer.getDefault().notify(d);
218: }
219: return null;
220: }
221:
222: protected InstallationService getInstallationService() {
223: try {
224: return getAppserverJBIMgmtController()
225: .getInstallationService();
226: } catch (ManagementRemoteException e) {
227: NotifyDescriptor d = new NotifyDescriptor.Message(e
228: .getMessage(), NotifyDescriptor.ERROR_MESSAGE);
229: DialogDisplayer.getDefault().notify(d);
230: }
231: return null;
232: }
233:
234: protected DeploymentService getDeploymentService() {
235: try {
236: return getAppserverJBIMgmtController()
237: .getDeploymentService();
238: } catch (ManagementRemoteException e) {
239: NotifyDescriptor d = new NotifyDescriptor.Message(e
240: .getMessage(), NotifyDescriptor.ERROR_MESSAGE);
241: DialogDisplayer.getDefault().notify(d);
242: }
243: return null;
244: }
245:
246: protected ConfigurationService getConfigurationService() {
247: try {
248: return getAppserverJBIMgmtController()
249: .getConfigurationService();
250: } catch (ManagementRemoteException e) {
251: NotifyDescriptor d = new NotifyDescriptor.Message(e
252: .getMessage(), NotifyDescriptor.ERROR_MESSAGE);
253: DialogDisplayer.getDefault().notify(d);
254: }
255: return null;
256: }
257:
258: protected AdministrationService getAdministrationService() {
259: try {
260: return getAppserverJBIMgmtController()
261: .getAdministrationService();
262: } catch (ManagementRemoteException e) {
263: NotifyDescriptor d = new NotifyDescriptor.Message(e
264: .getMessage(), NotifyDescriptor.ERROR_MESSAGE);
265: DialogDisplayer.getDefault().notify(d);
266: }
267: return null;
268: }
269:
270: // /**
271: // * Sets the property as an attribute to the underlying AMX mbeans. It
272: // * usually will delegate to the controller object which is responsible for
273: // * finding the correct AMX mbean objectname in order to execute a
274: // * JMX setAttribute.
275: // *
276: // * @param attrName The name of the property to be set.
277: // * @param value The value retrieved from the property sheet to be set in the
278: // * backend.
279: // * @returns the updated Attribute accessed from the Sheet.
280: // */
281: // public abstract Attribute setSheetProperty(String attrName, Object value);
282:
283: /**
284: * Returns the logger for all nodes.
285: *
286: * @returns The java.util.logging.Logger impl. for this node.
287: */
288: protected final static Logger getLogger() {
289: if (logger == null) {
290: logger = Logger
291: .getLogger("org.netbeans.modules.sun.manager.jbi.nodes");
292: }
293:
294: return logger;
295: }
296: }
|