sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1515718 - in /sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl: AttributeResource.java AttributesResource.java Constants.java MBeanResource.java MapResource.java RootResource.java
Date Tue, 20 Aug 2013 06:48:59 GMT
Author: cziegeler
Date: Tue Aug 20 06:48:59 2013
New Revision: 1515718

URL: http://svn.apache.org/r1515718
Log:
SLING-2999 : JMX Resource Provider - add sorting of tabular data

Added:
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
  (with props)
Modified:
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributesResource.java
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java
    sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/RootResource.java

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java?rev=1515718&r1=1515717&r2=1515718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributeResource.java
Tue Aug 20 06:48:59 2013
@@ -19,10 +19,14 @@
 package org.apache.sling.jmx.provider.impl;
 
 import java.lang.reflect.Array;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
@@ -77,7 +81,7 @@ public class AttributeResource extends A
      * @see org.apache.sling.api.resource.Resource#getResourceType()
      */
     public String getResourceType() {
-        return "sling:mbeanattribute";
+        return Constants.TYPE_ATTRIBUTE;
     }
 
     /**
@@ -112,15 +116,15 @@ public class AttributeResource extends A
 
     private Map<String, Object> getPropertiesMap() {
         final Map<String, Object> result = new HashMap<String, Object>();
-        result.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, this.getResourceType());
+        result.put(Constants.PROP_RESOURCE_TYPE, this.getResourceType());
         if ( this.getResourceSuperType() != null ) {
-            result.put("sling:resourceSuperType", this.getResourceSuperType());
+            result.put(Constants.PROP_RESOURCE_SUPER_TYPE, this.getResourceSuperType());
         }
 
         if ( info.getDescription() != null ) {
-            result.put("mbean:description", info.getDescription());
+            result.put(Constants.PROP_DESCRIPTION, info.getDescription());
         }
-        result.put("mbean:type", info.getType());
+        result.put(Constants.PROP_TYPE, info.getType());
 
         try {
             final Object value = server.getAttribute(this.on, info.getName());
@@ -132,13 +136,13 @@ public class AttributeResource extends A
                         final Object o = Array.get(value, i);
                         values[i] = convert(o);
                     }
-                    result.put("mbean:value", values);
+                    result.put(Constants.PROP_VALUE, values);
                 } else if (value instanceof TabularData) {
                     // Nothing to do, value is child resource
                 } else if (value instanceof CompositeData) {
                     // Nothing to do, value is child resource
                 } else {
-                    result.put("mbean:value", convert(value));
+                    result.put(Constants.PROP_VALUE, convert(value));
                 }
             }
         } catch (final Exception ignore) {
@@ -202,17 +206,38 @@ public class AttributeResource extends A
     private Map<String, Object> convertObject(final TabularData td) {
         final TabularType type = td.getTabularType();
         final Map<String, Object> result = new HashMap<String, Object>();
-        result.put("sling:resourceSuperType", "mbean:attributes");
-        result.put("sling:resourceType", type.getTypeName());
+        result.put(Constants.PROP_RESOURCE_SUPER_TYPE, Constants.TYPE_ATTRIBUTES);
+        result.put(Constants.PROP_RESOURCE_TYPE, type.getTypeName());
 
         final Map<String, Map<String, Object>> rows = new LinkedHashMap<String,
Map<String, Object>>();
-        int index = 1;
-        // TODO - use index values
-        for(final CompositeData data : (Collection<CompositeData>)td.values()) {
-            rows.put(String.valueOf(index), convertObject(data));
-            index++;
+        int rowIndex = 1;
+        @SuppressWarnings("unchecked")
+        final List<CompositeData> values = new ArrayList<CompositeData>((Collection<CompositeData>)td.values());
+        Collections.sort(values, new Comparator<CompositeData>() {
+
+            public int compare(final CompositeData o1, final CompositeData o2) {
+                for(final String name : type.getIndexNames()) {
+                    final Object value1 = o1.get(name);
+                    final Object value2 = o2.get(name);
+                    final int result;
+                    if ( value1 instanceof Comparable ) {
+                        result = ((Comparable)value1).compareTo(value2);
+                    } else {
+                        result = value1.toString().compareTo(value2.toString());
+                    }
+                    if ( result != 0 ) {
+                        return result;
+                    }
+                }
+                return 0;
+            }
+
+        });
+        for(final CompositeData data : values) {
+            rows.put(String.valueOf(rowIndex), convertObject(data));
+            rowIndex++;
         }
-        result.put("mbean:value", rows);
+        result.put(Constants.RSRC_VALUE, rows);
 
         return result;
     }
@@ -220,24 +245,24 @@ public class AttributeResource extends A
     private Map<String, Object> convertObject(final CompositeData cd) {
         final CompositeType type = cd.getCompositeType();
         final Map<String, Object> result = new HashMap<String, Object>();
-        result.put("sling:resourceSuperType", "mbean:attributes");
-        result.put("sling:resourceType", type.getTypeName());
+        result.put(Constants.PROP_RESOURCE_SUPER_TYPE, Constants.TYPE_ATTRIBUTES);
+        result.put(Constants.PROP_RESOURCE_TYPE, type.getTypeName());
 
         final Map<String, Object> attrMap = new TreeMap<String, Object>();
-        attrMap.put("sling:resourceType", "mbean:attributes");
-        result.put("mbean:attributes", attrMap);
+        attrMap.put(Constants.PROP_RESOURCE_TYPE, Constants.TYPE_ATTRIBUTES);
+        result.put(Constants.RSRC_ATTRIBUTES, attrMap);
 
         final Set<String> names = type.keySet();
         for(final String name : names) {
             final Map<String, Object> dataMap = new HashMap<String, Object>();
             attrMap.put(name, dataMap);
             dataMap.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, type.getType(name));
-            dataMap.put("sling:resourceSuperType", "mbean:attributes");
+            dataMap.put(Constants.PROP_RESOURCE_SUPER_TYPE, Constants.TYPE_ATTRIBUTE);
 
             if ( type.getDescription() != null ) {
-                dataMap.put("mbean:description", type.getDescription());
+                dataMap.put(Constants.PROP_DESCRIPTION, type.getDescription());
             }
-            dataMap.put("mbean:type", type.getType(name));
+            dataMap.put(Constants.PROP_TYPE, type.getType(name).getTypeName());
 
             final Object value = cd.get(name);
             if ( value != null ) {
@@ -248,13 +273,13 @@ public class AttributeResource extends A
                         final Object o = Array.get(value, i);
                         values[i] = convert(o);
                     }
-                    dataMap.put("mbean:value", values);
+                    dataMap.put(Constants.PROP_VALUE, values);
                 } else if (value instanceof TabularData) {
-                    dataMap.put("mbean:value", convertObject((TabularData)value));
+                    dataMap.put(Constants.RSRC_VALUE, convertObject((TabularData)value));
                 } else if (value instanceof CompositeData) {
-                    dataMap.put("mbean:value", convertObject((CompositeData)value));
+                    dataMap.put(Constants.RSRC_VALUE, convertObject((CompositeData)value));
                 } else {
-                    dataMap.put("mbean:value", convert(value));
+                    dataMap.put(Constants.PROP_VALUE, convert(value));
                 }
             }
         }

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributesResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributesResource.java?rev=1515718&r1=1515717&r2=1515718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributesResource.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/AttributesResource.java
Tue Aug 20 06:48:59 2013
@@ -52,7 +52,7 @@ public class AttributesResource extends 
      * @see org.apache.sling.api.resource.Resource#getResourceType()
      */
     public String getResourceType() {
-        return "sling:mbeanattributes";
+        return Constants.TYPE_ATTRIBUTES;
     }
 
     /**
@@ -87,9 +87,9 @@ public class AttributesResource extends 
 
     private Map<String, Object> getPropertiesMap() {
         final Map<String, Object> result = new HashMap<String, Object>();
-        result.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, this.getResourceType());
+        result.put(Constants.PROP_RESOURCE_TYPE, this.getResourceType());
         if ( this.getResourceSuperType() != null ) {
-            result.put("sling:resourceSuperType", this.getResourceSuperType());
+            result.put(Constants.PROP_RESOURCE_SUPER_TYPE, this.getResourceSuperType());
         }
 
         return result;

Added: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java?rev=1515718&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
(added)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
Tue Aug 20 06:48:59 2013
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jmx.provider.impl;
+
+public abstract class Constants {
+
+    public static final String RSRC_ATTRIBUTES = "mbean:attributes";
+
+    public static final String RSRC_VALUE = "mbean:value";
+
+    public static final String PROP_VALUE = "mbean:value";
+
+    public static final String PROP_RESOURCE_TYPE = "sling:resourceType";
+
+    public static final String PROP_RESOURCE_SUPER_TYPE = "sling:resourceType";
+
+    public static final String PROP_TYPE = "mbean:type";
+
+    public static final String PROP_DESCRIPTION = "mbean:description";
+
+    public static final String PROP_CLASSNAME = "mbean:className";
+
+    public static final String PROP_OBJECTNAME = "mbean:objectName";
+
+    public static final String TYPE_ATTRIBUTES = "sling:mbeanattributes";
+
+    public static final String TYPE_ATTRIBUTE = "sling:mbeanattribute";
+
+    public static final String TYPE_MBEAN = "sling:mbean";
+
+    public static final String TYPE_MBEANS = "sling:mbeans";
+}

Propchange: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/Constants.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java?rev=1515718&r1=1515717&r2=1515718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MBeanResource.java
Tue Aug 20 06:48:59 2013
@@ -79,7 +79,7 @@ public class MBeanResource extends Abstr
      * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
      */
     public String getResourceSuperType() {
-        return "sling:mbean";
+        return Constants.TYPE_MBEAN;
     }
 
     /**
@@ -107,14 +107,14 @@ public class MBeanResource extends Abstr
 
     private Map<String, Object> getPropertiesMap() {
         final Map<String, Object> result = new HashMap<String, Object>();
-        result.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, this.getResourceType());
-        result.put("sling:resourceSuperType", this.getResourceSuperType());
+        result.put(Constants.PROP_RESOURCE_TYPE, this.getResourceType());
+        result.put(Constants.PROP_RESOURCE_SUPER_TYPE, this.getResourceSuperType());
 
         if ( this.info.getDescription() != null ) {
-            result.put("mbean:description", this.info.getDescription());
+            result.put(Constants.PROP_DESCRIPTION, this.info.getDescription());
         }
-        result.put("mbean:className", this.info.getClassName());
-        result.put("mbean:objectName", this.objectName.getCanonicalName());
+        result.put(Constants.PROP_CLASSNAME, this.info.getClassName());
+        result.put(Constants.PROP_OBJECTNAME, this.objectName.getCanonicalName());
 
         return result;
     }

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java?rev=1515718&r1=1515717&r2=1515718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/MapResource.java
Tue Aug 20 06:48:59 2013
@@ -60,14 +60,14 @@ public class MapResource extends Abstrac
      * @see org.apache.sling.api.resource.Resource#getResourceType()
      */
     public String getResourceType() {
-        return (String)properties.get("sling:resourceType");
+        return (String)properties.get(Constants.PROP_RESOURCE_TYPE);
     }
 
     /**
      * @see org.apache.sling.api.resource.Resource#getResourceSuperType()
      */
     public String getResourceSuperType() {
-        return (String)properties.get("sling:resourceSuperType");
+        return (String)properties.get(Constants.PROP_RESOURCE_SUPER_TYPE);
     }
 
     /**

Modified: sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/RootResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/RootResource.java?rev=1515718&r1=1515717&r2=1515718&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/RootResource.java
(original)
+++ sling/trunk/contrib/extensions/jmxprovider/src/main/java/org/apache/sling/jmx/provider/impl/RootResource.java
Tue Aug 20 06:48:59 2013
@@ -52,7 +52,7 @@ public class RootResource extends Abstra
      * @see org.apache.sling.api.resource.Resource#getResourceType()
      */
     public String getResourceType() {
-        return "sling:mbeans";
+        return Constants.TYPE_MBEANS;
     }
 
     /**
@@ -87,9 +87,9 @@ public class RootResource extends Abstra
 
     private Map<String, Object> getPropertiesMap() {
         final Map<String, Object> result = new HashMap<String, Object>();
-        result.put(ResourceResolver.PROPERTY_RESOURCE_TYPE, this.getResourceType());
+        result.put(Constants.PROP_RESOURCE_TYPE, this.getResourceType());
         if ( this.getResourceSuperType() != null ) {
-            result.put("sling:resourceSuperType", this.getResourceSuperType());
+            result.put(Constants.PROP_RESOURCE_SUPER_TYPE, this.getResourceSuperType());
         }
 
         return result;



Mime
View raw message