1 23 24 29 30 package com.sun.enterprise.admin.monitor.jndi; 31 32 import com.sun.enterprise.admin.common.constant.AdminConstants; 33 import com.sun.enterprise.util.i18n.StringManager; 34 import java.lang.reflect.InvocationTargetException ; 35 import java.lang.reflect.Method ; 36 import java.util.logging.Level ; 37 import java.util.logging.Logger ; 38 import javax.management.AttributeList ; 39 import javax.management.AttributeNotFoundException ; 40 import javax.management.InvalidAttributeValueException ; 41 import javax.management.MBeanException ; 42 import javax.management.MBeanInfo ; 43 import javax.management.MBeanOperationInfo ; 44 import javax.management.MBeanParameterInfo ; 45 import javax.management.ReflectionException ; 46 import javax.naming.NameClassPair ; 47 import javax.naming.NamingException ; 48 49 55 public class JndiMBeanImpl implements JndiMBean { 56 57 private JndiMBeanHelper helper; 58 MBeanInfo mbeanInfo; 59 private static final Logger logger = 60 Logger.getLogger(AdminConstants.kLoggerName); 61 private static final StringManager sm = 62 StringManager.getManager(JndiMBeanImpl.class); 63 64 65 public JndiMBeanImpl() { 66 initialize(); 67 } 68 69 75 void initialize() { 76 helper = new JndiMBeanHelper(); 77 } 78 79 82 public Object getAttribute(String str) 83 throws AttributeNotFoundException , 84 MBeanException , ReflectionException { 85 throw new UnsupportedOperationException ( 86 sm.getString("monitor.jndi.unsupported_method")); 87 } 88 89 92 public AttributeList getAttributes(String [] str) { 93 throw new UnsupportedOperationException ( 94 sm.getString("monitor.jndi.unsupported_method")); 95 } 96 97 100 public MBeanInfo getMBeanInfo() { 101 if(mbeanInfo == null) { 102 mbeanInfo = new MBeanInfo (this.getClass().getName(), 103 "Managed Object for " + this.getClass().getName(), 104 null, null, getOperationInfo(), null); 105 } 106 return mbeanInfo; 107 } 108 109 112 MBeanOperationInfo [] getOperationInfo() { 113 Method [] methods = this.getClass().getMethods(); 114 MBeanOperationInfo [] mInfo = new MBeanOperationInfo [methods.length]; 115 for(int i= 0; i < methods.length; i++){ 116 mInfo[i]= createOperationInfo(methods[i]); 117 } 118 return mInfo; 119 } 120 121 124 MBeanOperationInfo createOperationInfo(Method method){ 125 return new MBeanOperationInfo (method.getName(), 126 "Method " + method.getName(), 127 getParameterInfo(method.getParameterTypes()), 128 method.getReturnType().getName(), 129 MBeanOperationInfo.INFO); 130 } 131 132 135 MBeanParameterInfo [] getParameterInfo(Class [] paramTypes){ 136 MBeanParameterInfo [] params=null; 137 if(paramTypes != null){ 138 params = new MBeanParameterInfo [paramTypes.length]; 139 for(int i = 0; i < paramTypes.length; i++){ 140 try { 141 params[i] = new MBeanParameterInfo ("param" + i, 142 paramTypes[i].getName(), 143 paramTypes[i].getName()); 144 } catch(java.lang.IllegalArgumentException e){ 145 logger.log(Level.INFO, e.toString()); 146 } 147 } 148 } 149 return params; 150 } 151 152 155 boolean isAttrGetterOrSetter(Method operation){ 156 if(operation.getName().startsWith("get") 157 || operation.getName().startsWith("set")){ 158 return true; 159 } 160 return false; 161 } 162 163 166 public Object invoke(String str, Object [] obj, String [] str2) 167 throws MBeanException , ReflectionException { 168 Object a = null; 169 Class [] c = new Class [str2.length]; 170 for(int i=0; i < str2.length; i++){ 171 c[i] = str2[i].getClass(); 172 } 173 try { 174 a = (Object )this.getClass().getMethod(str, c).invoke(this, obj); 175 } catch(InvocationTargetException e){ 176 logger.log(Level.INFO,e.getMessage(), e); 177 MBeanException me = 178 new MBeanException ((Exception )e.getTargetException()); 179 throw me; 180 } catch (Exception e) { 181 throw new MBeanException (e); 182 } 183 return a; 184 } 185 186 189 public void setAttribute(javax.management.Attribute attribute) 190 throws AttributeNotFoundException , InvalidAttributeValueException , 191 MBeanException , ReflectionException { 192 throw new UnsupportedOperationException ( 193 sm.getString("monitor.jndi.unsupported_method")); 194 } 195 196 199 public AttributeList setAttributes(AttributeList attributeList) { 200 throw new UnsupportedOperationException ( 201 sm.getString("monitor.jndi.unsupported_method")); 202 } 203 204 215 public java.util.ArrayList getNames(String context) 216 throws NamingException { 217 java.util.ArrayList names = null; 218 names = helper.getJndiEntriesByContextPath(context); 219 return names; 220 } 221 } 222 | Popular Tags |