tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1518585 - in /tomee/tomee/trunk/container/openejb-core/src: main/java/org/apache/openejb/monitoring/ test/java/org/apache/openejb/config/ test/java/org/apache/openejb/mbeans/
Date Thu, 29 Aug 2013 11:08:11 GMT
Author: rmannibucau
Date: Thu Aug 29 11:08:11 2013
New Revision: 1518585

URL: http://svn.apache.org/r1518585
Log:
TOMEE-1024 @Description on parameters

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/DynamicMBeanWrapper.java
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/MBeanDeployerTest.java
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/Operation.java
    tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/OperationDescription.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/DynamicMBeanWrapper.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/DynamicMBeanWrapper.java?rev=1518585&r1=1518584&r2=1518585&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/DynamicMBeanWrapper.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/monitoring/DynamicMBeanWrapper.java
Thu Aug 29 11:08:11 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.openejb.monitoring;
 
+import com.sun.jmx.mbeanserver.Introspector;
 import org.apache.openejb.api.internal.Internal;
 import org.apache.openejb.api.jmx.Description;
 import org.apache.openejb.api.jmx.MBean;
@@ -30,6 +31,7 @@ import org.apache.webbeans.config.WebBea
 import javax.management.Attribute;
 import javax.management.AttributeList;
 import javax.management.AttributeNotFoundException;
+import javax.management.Descriptor;
 import javax.management.DynamicMBean;
 import javax.management.ImmutableDescriptor;
 import javax.management.IntrospectionException;
@@ -39,6 +41,7 @@ import javax.management.MBeanException;
 import javax.management.MBeanInfo;
 import javax.management.MBeanNotificationInfo;
 import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
 import javax.management.ReflectionException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
@@ -163,7 +166,7 @@ public class DynamicMBeanWrapper impleme
                         operationDescr = getDescription(descr, "-");
                     }
 
-                    operationInfos.add(new MBeanOperationInfo(operationDescr, m));
+                    operationInfos.add(newMethodDescriptor(operationDescr, m));
                 }
             }
 
@@ -224,6 +227,45 @@ public class DynamicMBeanWrapper impleme
         }
     }
 
+    private MBeanOperationInfo newMethodDescriptor(final String operationDescr, final Method
m) {
+        return new MBeanOperationInfo(
+            m.getName(),
+            operationDescr,
+            methodSignature(m),
+            m.getReturnType().getName(),
+            MBeanOperationInfo.UNKNOWN,
+            Introspector.descriptorForElement(m));
+    }
+
+    private static MBeanParameterInfo[] methodSignature(final Method method) {
+        final Class<?>[] classes = method.getParameterTypes();
+        final Annotation[][] annots = method.getParameterAnnotations();
+        return parameters(classes, annots);
+    }
+
+    static MBeanParameterInfo[] parameters(final Class<?>[] classes,
+                                           final Annotation[][] annots) {
+        final MBeanParameterInfo[] params =
+            new MBeanParameterInfo[classes.length];
+        assert(classes.length == annots.length);
+
+        String desc = "";
+        for (int i = 0; i < classes.length; i++) {
+            final Descriptor d = Introspector.descriptorForAnnotations(annots[i]);
+            final String pn = "arg" + i;
+            for (final Annotation a : annots[i]) {
+                final Class<? extends Annotation> type = a.annotationType();
+                if (type.equals(Description.class) || type.equals(OPENEJB_API_TO_JAVAX.get(Description.class)))
{
+                    desc = getDescription(annotationProxy(a, Description.class), desc);
+                    break;
+                }
+            }
+            params[i] = new MBeanParameterInfo(pn, classes[i].getName(), desc, d);
+        }
+
+        return params;
+    }
+
     private <T extends Annotation> T findAnnotation(final Method method, final Class<T>
searchedAnnotation) {
         final T annotation = method.getAnnotation(searchedAnnotation);
         if (annotation != null) {
@@ -260,14 +302,14 @@ public class DynamicMBeanWrapper impleme
         return (T) Proxy.newProxyInstance(DynamicMBeanWrapper.class.getClassLoader(), new
Class<?>[]{clazz}, new AnnotationHandler(javaxAnnotation));
     }
 
-    private MBeanNotificationInfo getNotificationInfo(NotificationInfo n) {
-        String description = getDescription(n.description(), "-");
+    private static MBeanNotificationInfo getNotificationInfo(final NotificationInfo n) {
+        final String description = getDescription(n.description(), "-");
         return new MBeanNotificationInfo(n.types(),
             n.notificationClass().getName(), description,
             new ImmutableDescriptor(n.descriptorFields()));
     }
 
-    private String getDescription(Description d, String defaultValue) {
+    private static String getDescription(final Description d, final String defaultValue)
{
         if (d != null) {
             if (d.bundleBaseName() != null && d.key() != null) {
                 try {

Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/MBeanDeployerTest.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/MBeanDeployerTest.java?rev=1518585&r1=1518584&r2=1518585&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/MBeanDeployerTest.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/config/MBeanDeployerTest.java
Thu Aug 29 11:08:11 2013
@@ -38,6 +38,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import javax.management.Attribute;
+import javax.management.MBeanInfo;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import java.util.Arrays;
@@ -137,6 +138,12 @@ public class MBeanDeployerTest {
                 assertTrue(cn.startsWith("openejb.user.mbeans"));
                 assertTrue(cn.contains("group=org.apache.openejb.mbeans"));
                 assertTrue(cn.contains("application=mbeans") || cn.contains("application=EjbModule"));
+                final MBeanInfo info = server.getMBeanInfo(on);
+                if ("desc".equals(info.getOperations()[0].getName())) {
+                    assertEquals("param", info.getOperations()[0].getSignature()[0].getDescription());
+                } else {
+                    assertEquals("param", info.getOperations()[1].getSignature()[0].getDescription());
+                }
                 assertTrue(server.isRegistered(on));
                 assertEquals("yes - no", server.invoke(on, "returnValue", null, null));
                 parsed.add(cn);

Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/Operation.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/Operation.java?rev=1518585&r1=1518584&r2=1518585&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/Operation.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/Operation.java
Thu Aug 29 11:08:11 2013
@@ -23,8 +23,13 @@ import javax.management.ManagedOperation
 @MBean
 @Description("descr ;)")
 public class Operation {
-	@ManagedOperation public String returnValue() {
-		return "yes - no";
-	}
+    @ManagedOperation
+    public String returnValue() {
+        return "yes - no";
+    }
 
+    @ManagedOperation
+    public String desc(final @Description("param") String p) {
+        return null;
+    }
 }

Modified: tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/OperationDescription.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/OperationDescription.java?rev=1518585&r1=1518584&r2=1518585&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/OperationDescription.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/test/java/org/apache/openejb/mbeans/OperationDescription.java
Thu Aug 29 11:08:11 2013
@@ -23,7 +23,14 @@ import javax.management.ManagedOperation
 @MBean
 @Description("descr ;)")
 public class OperationDescription {
-	@ManagedOperation @Description("just an op") public String returnValue() {
-		return "yes - no";
-	}
+    @ManagedOperation
+    @Description("just an op")
+    public String returnValue() {
+        return "yes - no";
+    }
+
+    @ManagedOperation
+    public String desc(final @Description("param") String p) {
+        return null;
+    }
 }



Mime
View raw message