sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject [sling-org-apache-sling-jmx-provider] 02/39: SLING-2999 : JMX Resource Provider
Date Wed, 18 Oct 2017 23:24:25 GMT
This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jmx-provider.git

commit de180f90960b30e4fa557f27e25f07a6b6a14df1
Author: Carsten Ziegeler <cziegeler@apache.org>
AuthorDate: Fri Aug 9 15:43:41 2013 +0000

    SLING-2999 : JMX Resource Provider
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1512349 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/jmx/provider/impl/AttributeResource.java | 52 +++++++++++++++-------
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java b/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
index 5e303a3..f715d3b 100644
--- a/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
+++ b/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
@@ -18,17 +18,15 @@
  */
 package org.apache.sling.jmx.provider.impl;
 
+import java.lang.reflect.Array;
 import java.util.HashMap;
 import java.util.Map;
 
-import javax.management.AttributeNotFoundException;
-import javax.management.InstanceNotFoundException;
 import javax.management.MBeanAttributeInfo;
-import javax.management.MBeanException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
-import javax.management.ReflectionException;
-import javax.management.RuntimeMBeanException;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.TabularData;
 
 import org.apache.sling.api.SlingConstants;
 import org.apache.sling.api.resource.AbstractResource;
@@ -120,19 +118,41 @@ public class AttributeResource extends AbstractResource {
         try {
             final Object value = server.getAttribute(this.on, info.getName());
             if ( value != null ) {
-                result.put("value", value.toString());
+                if ( value.getClass().isArray() ) {
+                    final int length = Array.getLength(value);
+                    final Object[] values = new Object[length];
+                    for (int i = 0; i < length; i ++) {
+                        final Object o = Array.get(value, i);
+                        values[i] = convert(o);
+                    }
+                    result.put("value", values);
+                } else if (value instanceof TabularData) {
+                    // TODO
+                } else if (value instanceof CompositeData) {
+                    // TODO
+                } else {
+                    result.put("value", convert(value));
+                }
             }
-        } catch (final RuntimeMBeanException uoe) {
-            // ignore
-        } catch (final AttributeNotFoundException e) {
-            // ignore
-        } catch (final InstanceNotFoundException e) {
-            // ignore
-        } catch (final MBeanException e) {
-            // ignore
-        } catch (final ReflectionException e) {
-            // ignore
+        } catch (final Exception ignore) {
+            // ignore, but put this as info
+            result.put("exception", ignore.getMessage());
         }
         return result;
     }
+
+    private Object convert(final Object value) {
+        if ( value == null ) {
+            return "";
+        } else if ( value instanceof String ) {
+            return value;
+        } else if ( value instanceof Number ) {
+            return value;
+        } else if ( value instanceof Boolean ) {
+            return value;
+        } else if ( value instanceof Character ) {
+            return value;
+        }
+        return value.toString();
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <commits@sling.apache.org>.

Mime
View raw message