public Object getAttribute(String name)
throws AttributeNotFoundException, MBeanException,
ReflectionException {
// Validate the input parameters
if (name == null)
throw new RuntimeOperationsException
(new IllegalArgumentException("Attribute name is null"),
"Attribute name is null");
if( (resource instanceof DynamicMBean) &&
! ( resource instanceof BaseModelMBean )) {
return ((DynamicMBean)resource).getAttribute(name);
}
// Extract the method from cache
Method m=(Method)getAttMap.get( name );
if( m==null ) {
// Look up the actual operation to be used
ModelMBeanAttributeInfo attrInfo = info.getAttribute(name);
if (attrInfo == null)
throw new AttributeNotFoundException(" Cannot find attribute " + name);
Descriptor attrDesc = attrInfo.getDescriptor();
if (attrDesc == null)
throw new AttributeNotFoundException("Cannot find attribute " + name + " descriptor");
String getMethod = (String) attrDesc.getFieldValue("getMethod");
if (getMethod == null)
throw new AttributeNotFoundException("Cannot find attribute " + name + " get method name");
Object object = null;
NoSuchMethodException exception = null;
try {
object = this;
m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
} catch (NoSuchMethodException e) {
exception = e;;
}
if( m== null && resource != null ) {
try {
object = resource;
m = object.getClass().getMethod(getMethod, NO_ARGS_PARAM_SIG);
exception=null;
} catch (NoSuchMethodException e) {
exception = e;
}
}
if( exception != null )
throw new ReflectionException(exception,
"Cannot find getter method " + getMethod);
getAttMap.put( name, m );
}
Object result = null;
try {
Class declaring=m.getDeclaringClass();
// workaround for catalina weird mbeans - the declaring class is BaseModelMBean.
// but this is the catalina class.
if( declaring.isAssignableFrom(this.getClass()) ) {
result = m.invoke(this, NO_ARGS_PARAM );
} else {
result = m.invoke(resource, NO_ARGS_PARAM );
}
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
if (t == null)
t = e;
if (t instanceof RuntimeException)
throw new RuntimeOperationsException
((RuntimeException) t, "Exception invoking method " + name);
else if (t instanceof Error)
throw new RuntimeErrorException
((Error) t, "Error invoking method " + name);
else