1 23 24 package com.sun.enterprise.admin.common; 25 26 import java.util.ArrayList ; 27 import java.util.Set ; 28 import java.util.Iterator ; 29 30 import javax.management.ObjectName ; 32 import javax.management.ObjectInstance ; 33 import javax.management.MBeanServer ; 34 35 import com.sun.enterprise.admin.common.ObjectNames; 37 38 41 42 public class ObjectNameHelper 43 { 44 50 51 public static String getType(ObjectName objectName) 52 { 53 String type = objectName.getKeyProperty(ObjectNames.kTypeKeyName); 54 56 return ( type ); 57 } 58 59 63 64 public static String getName(ObjectName objectName) 65 { 66 String name = objectName.getKeyProperty(ObjectNames.kNameKeyName); 67 68 return ( name ); 69 } 70 71 public static String getClassId(ObjectName objectName) 72 { 73 String classId = objectName.getKeyProperty(ObjectNames.kClassIdKeyName); 74 return ( classId ); 75 } 76 77 public static String getServerId(ObjectName objectName) 78 { 79 String serverId = objectName.getKeyProperty(ObjectNames.kServerIdKeyName); 80 return ( serverId ); 81 } 82 83 public static String getServerInstanceName(ObjectName objectName) 84 { 85 String instanceName = null; 86 87 if (getType(objectName) != null) { 88 if (getType(objectName).equals(ObjectNames.kServerInstance)) 89 { 90 instanceName = getName(objectName); 91 } 92 else 93 { 94 instanceName = objectName.getKeyProperty(ObjectNames.kServerInstanceKeyName); 95 } 96 } 97 98 return ( instanceName ); 99 } 100 101 public static String getModuleType(ObjectName objectName) 102 { 103 String moduleType = null; 104 105 moduleType = objectName.getKeyProperty(ObjectNames.kModuleTypeKeyName); 106 107 return ( moduleType ); 108 } 109 110 public static String getApplicationName(ObjectName objectName) 111 { 112 String app = null; 113 114 app = objectName.getKeyProperty(ObjectNames.kApplicationNameKeyName); 115 116 return ( app ); 117 } 118 119 public static String getGroupId(ObjectName objectName) 120 { 121 String moduleType = null; 122 123 moduleType = objectName.getKeyProperty(ObjectNames.kGroupIdKeyName); 124 125 return ( moduleType ); 126 } 127 128 public static String getVirtualServerClassId(ObjectName objectName) 129 { 130 String classId = objectName.getKeyProperty( 131 ObjectNames.kVirtualServerClassIdKeyName); 132 return ( classId ); 133 } 134 135 public static String getVirtualServerId(ObjectName objectName) 136 { 137 String virtualServerId = objectName.getKeyProperty( 138 ObjectNames.kVirtualServerIdKeyName); 139 return ( virtualServerId ); 140 } 141 142 public static String getHttpListenerId(ObjectName objectName) 143 { 144 String listenerId = null; 145 listenerId = objectName.getKeyProperty(ObjectNames.kHTTPListenerIdKeyName); 146 return ( listenerId ); 147 } 148 149 154 public static boolean isMonitorMBean(ObjectName objectName) 155 { 156 boolean isMonitor = false; 157 String monitorKeyValue = null; 158 159 monitorKeyValue = objectName.getKeyProperty( 160 ObjectNames.kTypeKeyName); 161 if (monitorKeyValue != null) 162 { 163 isMonitor = monitorKeyValue. 164 equals(ObjectNames.kMonitoringType); 165 } 166 return ( isMonitor ); 167 } 168 169 172 public static ObjectName [] getInstanceRelatedMBeans(MBeanServer mbs, String instanceName) { 173 final ObjectName pattern = ObjectNames.getAllObjectNamesPattern(); final Set names = mbs.queryMBeans(pattern, null); 175 176 final Iterator iter = names.iterator(); 177 final ArrayList arr = new ArrayList (); 178 while(iter.hasNext()) { 179 final ObjectInstance objectInstance = (ObjectInstance ) iter.next(); 180 final ObjectName objectName = objectInstance.getObjectName(); 181 final String name = ObjectNameHelper.getServerInstanceName(objectName); 182 if(instanceName.equals(name)) { 183 arr.add(objectName); 184 } 185 } 186 return (ObjectName [])arr.toArray(new ObjectName [arr.size()]); 187 } 188 } 189 | Popular Tags |