001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.system.jmx;
017:
018: import java.util.Iterator;
019: import java.util.List;
020: import java.util.Set;
021: import javax.management.MBeanAttributeInfo;
022: import javax.management.MBeanConstructorInfo;
023: import javax.management.MBeanInfo;
024: import javax.management.MBeanNotificationInfo;
025: import javax.management.MBeanOperationInfo;
026: import javax.management.MBeanParameterInfo;
027:
028: import org.apache.geronimo.gbean.GAttributeInfo;
029: import org.apache.geronimo.gbean.GBeanInfo;
030: import org.apache.geronimo.gbean.GOperationInfo;
031: import org.apache.geronimo.kernel.management.NotificationType;
032:
033: /**
034: * Helper class for JMX Operations
035: *
036: * @version $Rev: 485321 $ $Date: 2006-12-10 16:14:46 -0800 (Sun, 10 Dec 2006) $
037: */
038: public final class JMXUtil {
039: private JMXUtil() {
040: }
041:
042: public static MBeanInfo toMBeanInfo(GBeanInfo gBeanInfo) {
043: String className = gBeanInfo.getClassName();
044: String description = "No description available";
045:
046: // attributes
047: Set gbeanAttributes = gBeanInfo.getAttributes();
048: MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[gbeanAttributes
049: .size()];
050: int a = 0;
051: for (Iterator iterator = gbeanAttributes.iterator(); iterator
052: .hasNext();) {
053: GAttributeInfo gAttributeInfo = (GAttributeInfo) iterator
054: .next();
055: attributes[a] = new MBeanAttributeInfo(gAttributeInfo
056: .getName(), gAttributeInfo.getType(),
057: "no description available", gAttributeInfo
058: .isReadable(), gAttributeInfo.isWritable(),
059: isIs(gAttributeInfo));
060: a++;
061: }
062:
063: //we don't expose managed constructors
064: MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[0];
065:
066: // operations
067: Set gbeanOperations = gBeanInfo.getOperations();
068: MBeanOperationInfo[] operations = new MBeanOperationInfo[gbeanOperations
069: .size()];
070: int o = 0;
071: for (Iterator iterator = gbeanOperations.iterator(); iterator
072: .hasNext();) {
073: GOperationInfo gOperationInfo = (GOperationInfo) iterator
074: .next();
075: //list of class names
076: List gparameters = gOperationInfo.getParameterList();
077: MBeanParameterInfo[] parameters = new MBeanParameterInfo[gparameters
078: .size()];
079: int p = 0;
080: for (Iterator piterator = gparameters.iterator(); piterator
081: .hasNext();) {
082: String type = (String) piterator.next();
083: parameters[p] = new MBeanParameterInfo("parameter" + p,
084: type, "no description available");
085: p++;
086: }
087: operations[o] = new MBeanOperationInfo(gOperationInfo
088: .getName(), "no description available", parameters,
089: gOperationInfo.getReturnType(),
090: MBeanOperationInfo.UNKNOWN);
091: o++;
092: }
093:
094: MBeanNotificationInfo[] notifications = new MBeanNotificationInfo[1];
095: notifications[0] = new MBeanNotificationInfo(
096: NotificationType.TYPES,
097: "javax.management.Notification", "J2EE Notifications");
098:
099: MBeanInfo mbeanInfo = new MBeanInfo(className, description,
100: attributes, constructors, operations, notifications);
101: return mbeanInfo;
102: }
103:
104: private static boolean isIs(GAttributeInfo gAttributeInfo) {
105: String getterName = gAttributeInfo.getGetterName();
106: if (getterName == null) {
107: return false;
108: }
109: return getterName.startsWith("is");
110: }
111: }
|