You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by or...@apache.org on 2015/11/26 15:45:25 UTC

svn commit: r1716708 - in /qpid/java/branches/6.0.x: ./ broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ApiDocsServlet.java

Author: orudyy
Date: Thu Nov 26 14:45:25 2015
New Revision: 1716708

URL: http://svn.apache.org/viewvc?rev=1716708&view=rev
Log:
QPID-6912: Remove duplicate code
------------------------------------------------------------------------
Merged from trunk with command:
svn merge -c r1716636 https://svn.apache.org/repos/asf/qpid/java/trunk

Modified:
    qpid/java/branches/6.0.x/   (props changed)
    qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ApiDocsServlet.java

Propchange: qpid/java/branches/6.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Nov 26 14:45:25 2015
@@ -9,5 +9,5 @@
 /qpid/branches/java-broker-vhost-refactor/java:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java:805429-821809
 /qpid/branches/qpid-2935/qpid/java:1061302-1072333
-/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619
+/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636
 /qpid/trunk/qpid:796646-796653

Modified: qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ApiDocsServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ApiDocsServlet.java?rev=1716708&r1=1716707&r2=1716708&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ApiDocsServlet.java (original)
+++ qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ApiDocsServlet.java Thu Nov 26 14:45:25 2015
@@ -394,66 +394,20 @@ public class ApiDocsServlet extends Abst
     private String renderType(final ConfiguredObjectAttribute attribute)
     {
         final Class type = attribute.getType();
-        if(Enum.class.isAssignableFrom(type))
-        {
-            return "<div class=\"restriction\" title=\"enum: " + EnumSet.allOf(type) + "\">string</div>";
-        }
-        else if(ConfiguredObject.class.isAssignableFrom(type))
-        {
-            return "<div class=\"restriction\" title=\"name or id of a" + (VOWELS.contains(type.getSimpleName().toLowerCase().charAt(0)) ? "n " : " ") + type.getSimpleName() + "\">string</div>";
-        }
-        else if(UUID.class == type)
-        {
-            return "<div class=\"restriction\" title=\"must be a UUID\">string</div>";
-        }
-        else
-        {
-            boolean hasValuesRestriction = attribute instanceof ConfiguredAutomatedAttribute
-                                           && ((ConfiguredAutomatedAttribute)attribute).hasValidValues();
-
-            StringBuilder returnVal = new StringBuilder();
-            if(hasValuesRestriction)
-            {
-                returnVal.append("<div class=\"restricted\" title=\"Valid values: " + ((ConfiguredAutomatedAttribute)attribute).validValues() + "\">");
-            }
+        return renderType(type,
+                attribute instanceof ConfiguredAutomatedAttribute && ((ConfiguredAutomatedAttribute)attribute).hasValidValues()
+                        ?  ((ConfiguredAutomatedAttribute)attribute).validValues() : null);
 
-            if(Number.class.isAssignableFrom(type))
-            {
-                returnVal.append("number");
-            }
-            else if(Boolean.class == type)
-            {
-                returnVal.append("boolean");
-            }
-            else if(String.class == type)
-            {
-                returnVal.append("string");
-            }
-            else if(Collection.class.isAssignableFrom(type))
-            {
-                // TODO - generate a description of the type in the array
-                returnVal.append("array");
-            }
-            else if(Map.class.isAssignableFrom(type))
-            {
-                // TODO - generate a description of the type in the object
-                returnVal.append("object");
-            }
-            else
-            {
-                returnVal.append(type.getSimpleName());
-            }
-            if(hasValuesRestriction)
-            {
-                returnVal.append("</div>");
-            }
-            return returnVal.toString();
-        }
     }
 
     private String renderType(final OperationParameter parameter)
     {
         final Class type = parameter.getType();
+        List<String> validValues = parameter.getValidValues();
+        return renderType(type, validValues);
+    }
+
+    private String renderType(Class type, Collection<String> validValues) {
         if(Enum.class.isAssignableFrom(type))
         {
             return "<div class=\"restriction\" title=\"enum: " + EnumSet.allOf(type) + "\">string</div>";
@@ -469,10 +423,10 @@ public class ApiDocsServlet extends Abst
         else
         {
             StringBuilder returnVal = new StringBuilder();
-            final boolean hasValuesRestriction = parameter.getValidValues() != null && !parameter.getValidValues().isEmpty();
+            final boolean hasValuesRestriction = validValues != null && !validValues.isEmpty();
             if(hasValuesRestriction)
             {
-                returnVal.append("<div class=\"restricted\" title=\"Valid values: " + parameter.getValidValues() + "\">");
+                returnVal.append("<div class=\"restricted\" title=\"Valid values: " + validValues + "\">");
             }
 
             if(Number.class.isAssignableFrom(type))



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org