User: juhalindfors
Date: 01/12/08 08:06:50
Modified: src/main/org/jboss/mx/interceptor Invocation.java
StandardMBeanInterceptor.java
Log:
standard attributes
Revision Changes Path
1.2 +11 -4 jmx/src/main/org/jboss/mx/interceptor/Invocation.java
Index: Invocation.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/interceptor/Invocation.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Invocation.java 2001/12/07 00:02:36 1.1
+++ Invocation.java 2001/12/08 16:06:50 1.2
@@ -15,7 +15,7 @@
* @see org.jboss.mx.interceptor.Interceptor
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
*/
public class Invocation
@@ -70,16 +70,23 @@
public String getOperationWithSignature()
{
- if (signature == null)
+ if (signature == null && type == OPERATION)
return name;
-
+
if (fullName != null)
return fullName;
StringBuffer strBuf = new StringBuffer(1000);
+
+ if (type == ATTRIBUTE && impact == READ)
+ strBuf.append("get");
+ if (type == ATTRIBUTE && impact == WRITE)
+ strBuf.append("set");
+
strBuf.append(name);
- for (int i = 0; i < signature.length; ++i)
- strBuf.append(signature[i]);
+ if (signature != null)
+ for (int i = 0; i < signature.length; ++i)
+ strBuf.append(signature[i]);
fullName = strBuf.toString();
return fullName;
1.2 +62 -6
jmx/src/main/org/jboss/mx/interceptor/StandardMBeanInterceptor.java
Index: StandardMBeanInterceptor.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/interceptor/StandardMBeanInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- StandardMBeanInterceptor.java 2001/12/06 23:02:41 1.1
+++ StandardMBeanInterceptor.java 2001/12/08 16:06:50 1.2
@@ -13,6 +13,7 @@
import java.lang.reflect.InvocationTargetException;
import javax.management.MBeanInfo;
+import javax.management.MBeanAttributeInfo;
import javax.management.MBeanParameterInfo;
import javax.management.MBeanOperationInfo;
import javax.management.ReflectionException;
@@ -31,7 +32,7 @@
* @see org.jboss.mx.server.StandardMBean
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*
*/
public class StandardMBeanInterceptor
@@ -39,8 +40,7 @@
{
// Attributes ----------------------------------------------------
- private HashMap operationMap = new HashMap();
- private HashMap attributeMap = new HashMap();
+ private Map methodMap = new HashMap();
private Class invocationInterface;
private MBeanInfo info;
private Object resource;
@@ -68,8 +68,8 @@
strBuf.append(params[j].getType());
}
- operationMap.put(name + strBuf.toString(),
invocationInterface.getMethod(
- name, getSignatureAsClassArray(params,
resource.getClass().getClassLoader())));
+ methodMap.put(name + strBuf.toString(), invocationInterface.getMethod(
+ name, getSignatureAsClassArray(params,
resource.getClass().getClassLoader())));
}
catch (ClassNotFoundException e)
{
@@ -80,10 +80,64 @@
throw new ReflectionException(e);
}
}
+
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+
+ for (int i = 0; i < attributes.length; ++i)
+ {
+ String name = attributes[i].getName();
+ String type = attributes[i].getType();
+
+ try
+ {
+ boolean isReadable = attributes[i].isReadable();
+ boolean isWritable = attributes[i].isWritable();
+ boolean isIs = attributes[i].isIs();
+
+ if (isReadable)
+ if (isIs)
+ methodMap.put("get" + name, invocationInterface.getMethod("is" +
name, null));
+ else
+ methodMap.put("get" + name, invocationInterface.getMethod("get" +
name, null));
+
+ if (isWritable)
+ methodMap.put("set" + name + type, invocationInterface.getMethod(
+ "set" + name, getSignatureAsClassArray(
+ new String[] { type },
+ resource.getClass().getClassLoader())));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new ReflectionException(e, "Unable to load type for attribute " +
name + ": " + type);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new ReflectionException(e);
+ }
+ }
}
// Public ------------------------------------------------------------
+ public static Class[] getSignatureAsClassArray(String[] signature, ClassLoader
cl) throws ClassNotFoundException
+ {
+ Class[] sign = new Class[signature.length];
+ for (int i = 0; i < signature.length; ++i)
+ {
+ try
+ {
+ sign[i] = getClassForType(signature[i], cl);
+ }
+ catch (ClassNotFoundException e)
+ {
+ // if the explicit CL fails, go to the repository... allow CNFE to be
thrown
+ DefaultLoaderRepository.loadClass(signature[i]);
+ }
+ }
+
+ return sign;
+ }
+
public static Class[] getSignatureAsClassArray(MBeanParameterInfo[] signature,
ClassLoader cl) throws ClassNotFoundException
{
Class[] sign = new Class[signature.length];
@@ -106,6 +160,8 @@
public static Class getClassForType(String type, ClassLoader cl) throws
ClassNotFoundException
{
+System.out.println("TYPE: " + type);
+
if (int.class.getName().equals(type))
return Integer.TYPE;
else if (float.class.getName().equals(type))
@@ -132,7 +188,7 @@
{
try
{
- Method m =
(Method)operationMap.get(invocation.getOperationWithSignature());
+ Method m = (Method)methodMap.get(invocation.getOperationWithSignature());
return m.invoke(resource, invocation.getArgs());
}
catch (IllegalAccessException e)
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development