FELIX-1010: Fix handling of single scalar property values.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@776212 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
index 4fca54e..f5215fa 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
@@ -138,57 +138,81 @@
         // we now check all options
         if (values == null || values.length == 0 ) {
             long[] lValues = this.annotation.longValue();
-            if ( lValues.length == 0 ) {
+            if ( lValues == null || lValues.length == 0 ) {
                 double[] dValues = this.annotation.doubleValue();
-                if ( dValues.length == 0 ) {
+                if ( dValues == null || dValues.length == 0 ) {
                     float[] fValues = this.annotation.floatValue();
-                    if ( fValues.length == 0 ) {
+                    if ( fValues == null || fValues.length == 0 ) {
                         int[] iValues = this.annotation.intValue();
-                        if ( iValues.length == 0 ) {
+                        if ( iValues == null || iValues.length == 0 ) {
                             byte[] byteValues = this.annotation.byteValue();
-                            if ( byteValues.length == 0 ) {
+                            if ( byteValues == null || byteValues.length == 0 ) {
                                 char[] cValues = this.annotation.charValue();
-                                if ( cValues.length == 0 ) {
+                                if ( cValues == null || cValues.length == 0 ) {
                                     boolean[] boolValues = this.annotation.boolValue();
-                                    if ( boolValues.length == 0 ) {
+                                    if ( boolValues == null || boolValues.length == 0 ) {
                                         short[] sValues  = this.annotation.shortValue();
-                                        if ( boolValues.length != 0 ) {
-                                            values = Arrays.asList(sValues).toArray();
+                                        if ( sValues != null && sValues.length != 0 ) {
+                                            values = new Object[sValues.length];
+                                            for(int i=0;i<sValues.length;i++) {
+                                                values[i] = sValues[i];
+                                            }
                                             type = "Short";
                                         }
                                     } else {
-                                        values = Arrays.asList(boolValues).toArray();
+                                        values = new Object[boolValues.length];
+                                        for(int i=0;i<boolValues.length;i++) {
+                                            values[i] = boolValues[i];
+                                        }
                                         type = "Boolean";
                                     }
                                 } else {
-                                    values = Arrays.asList(cValues).toArray();
+                                    values = new Object[cValues.length];
+                                    for(int i=0;i<cValues.length;i++) {
+                                        values[i] = cValues[i];
+                                    }
                                     type = "Char";
                                 }
                             } else {
-                                values = Arrays.asList(byteValues).toArray();
+                                values = new Object[byteValues.length];
+                                for(int i=0;i<byteValues.length;i++) {
+                                    values[i] = byteValues[i];
+                                }
                                 type = "Byte";
                             }
                         } else {
-                            values = Arrays.asList(fValues).toArray();
+                            values = new Object[iValues.length];
+                            for(int i=0;i<iValues.length;i++) {
+                                values[i] = iValues[i];
+                            }
                             type = "Integer";
                         }
                     } else {
-                        values = Arrays.asList(fValues).toArray();
+                        values = new Object[fValues.length];
+                        for(int i=0;i<fValues.length;i++) {
+                            values[i] = fValues[i];
+                        }
                         type = "Float";
                     }
                 } else {
-                    values = Arrays.asList(dValues).toArray();
+                    values = new Object[dValues.length];
+                    for(int i=0;i<dValues.length;i++) {
+                        values[i] = dValues[i];
+                    }
                     type = "Double";
                 }
             } else {
-                values = Arrays.asList(lValues).toArray();
+                values = new Object[lValues.length];
+                for(int i=0;i<lValues.length;i++) {
+                    values[i] = lValues[i];
+                }
                 type = "Long";
             }
         } else {
             type = "String";
         }
 
-        if ( values != null ) {
+        if ( values != null && values.length > 0 ) {
             map.put(Constants.PROPERTY_TYPE, type);
             if (values.length == 1) {
                 map.put(Constants.PROPERTY_VALUE, values[0].toString());
diff --git a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
index 8ea1507..11f7b1e 100644
--- a/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
+++ b/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
@@ -18,7 +18,7 @@
  */
 package org.apache.felix.scrplugin.tags.annotation.defaulttag;
 
-import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.felix.scrplugin.tags.*;
@@ -69,19 +69,25 @@
         }
     }
 
-    public static String[] getStringValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as string values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of string values or null.
+     */
+    public static String[] getStringValues(Annotation annotation, JavaClassDescription desc, String name)
+    {
         final Object obj = annotation.getNamedParameter(name);
         if ( obj != null ) {
-            List<String> list;
-            if (obj instanceof String) {
-                list = new ArrayList<String>();
-                list.add((String)obj);
+            if (obj instanceof String)
+            {
+                return new String[] {stripQuotes(desc, obj.toString())};
             }
-            else {
-                list = (List<String>)obj;
-            }
+            final List<String> list = (List<String>)obj;
             String[] values = new String[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = stripQuotes(desc, list.get(i));
             }
             return values;
@@ -89,19 +95,26 @@
         return null;
     }
 
-    public static long[] getLongValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as long values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of long values or null.
+     */
+    public static long[] getLongValues(Annotation annotation, JavaClassDescription desc, String name)
+    {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Long> list;
-            if (obj instanceof Long) {
-                list = new ArrayList<Long>();
-                list.add((Long)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new long[] {Long.valueOf(stripQuotes(desc, obj.toString()))};
             }
-            else {
-                list = (List<Long>)obj;
-            }
+            final List<Long> list = (List<Long>)obj;
             long[] values = new long[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;
@@ -109,19 +122,26 @@
         return null;
     }
 
-    public static int[] getIntValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as long values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of long values or null.
+     */
+    public static int[] getIntValues(Annotation annotation, JavaClassDescription desc, String name)
+    {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Integer> list;
-            if (obj instanceof Integer) {
-                list = new ArrayList<Integer>();
-                list.add((Integer)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new int[] {Integer.valueOf(stripQuotes(desc, obj.toString()))};
             }
-            else {
-                list = (List<Integer>)obj;
-            }
+            final List<Integer> list = (List<Integer>)obj;
             int[] values = new int[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;
@@ -129,19 +149,26 @@
         return null;
     }
 
-    public static float[] getFloatValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as float values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of float values or null.
+     */
+    public static float[] getFloatValues(Annotation annotation, JavaClassDescription desc, String name)
+    {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Float> list;
-            if (obj instanceof Float) {
-                list = new ArrayList<Float>();
-                list.add((Float)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new float[] {Float.valueOf(stripQuotes(desc, obj.toString()))};
             }
-            else {
-                list = (List<Float>)obj;
-            }
+            final List<Float> list = (List<Float>)obj;
             float[] values = new float[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;
@@ -149,19 +176,26 @@
         return null;
     }
 
-    public static double[] getDoubleValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as double values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of double values or null.
+     */
+    public static double[] getDoubleValues(Annotation annotation, JavaClassDescription desc, String name)
+    {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Double> list;
-            if (obj instanceof Double) {
-                list = new ArrayList<Double>();
-                list.add((Double)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new double[] {Double.valueOf(stripQuotes(desc, obj.toString()))};
             }
-            else {
-                list = (List<Double>)obj;
-            }
+            final List<Double> list = (List<Double>)obj;
             double[] values = new double[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;
@@ -169,19 +203,25 @@
         return null;
     }
 
+    /**
+     * Helper method to get the values of an annotation as char values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of char values or null.
+     */
     public static char[] getCharValues(Annotation annotation, JavaClassDescription desc, String name) {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Character> list;
-            if (obj instanceof Character) {
-                list = new ArrayList<Character>();
-                list.add((Character)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new char[] {Character.valueOf(stripQuotes(desc, obj.toString()).charAt(0))};
             }
-            else {
-                list = (List<Character>)obj;
-            }
+            final List<Character> list = (List<Character>)obj;
             char[] values = new char[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;
@@ -189,19 +229,26 @@
         return null;
     }
 
-    public static short[] getShortValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as short values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of short values or null.
+     */
+   public static short[] getShortValues(Annotation annotation, JavaClassDescription desc, String name)
+   {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Short> list;
-            if (obj instanceof Short) {
-                list = new ArrayList<Short>();
-                list.add((Short)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new short[] {Short.valueOf(stripQuotes(desc, obj.toString()))};
             }
-            else {
-                list = (List<Short>)obj;
-            }
+            final List<Short> list = (List<Short>)obj;
             short[] values = new short[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;
@@ -209,19 +256,26 @@
         return null;
     }
 
-    public static byte[] getByteValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as byte values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of byte values or null.
+     */
+   public static byte[] getByteValues(Annotation annotation, JavaClassDescription desc, String name)
+   {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Byte> list;
-            if (obj instanceof Byte) {
-                list = new ArrayList<Byte>();
-                list.add((Byte)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new byte[] {Byte.valueOf(stripQuotes(desc, obj.toString()))};
             }
-            else {
-                list = (List<Byte>)obj;
-            }
+            final List<Byte> list = (List<Byte>)obj;
             byte[] values = new byte[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;
@@ -229,19 +283,26 @@
         return null;
     }
 
-    public static boolean[] getBooleanValues(Annotation annotation, JavaClassDescription desc, String name) {
+    /**
+     * Helper method to get the values of an annotation as boolean values.
+     * @param annotation The annotation.
+     * @param desc The java class description.
+     * @param name The attribute name from the annotation.
+     * @return The array of boolean values or null.
+     */
+    public static boolean[] getBooleanValues(Annotation annotation, JavaClassDescription desc, String name)
+    {
         final Object obj = annotation.getNamedParameter(name);
-        if ( obj != null ) {
-            List<Boolean> list;
-            if (obj instanceof Boolean) {
-                list = new ArrayList<Boolean>();
-                list.add((Boolean)obj);
+        if ( obj != null )
+        {
+            if ( !(obj instanceof Collection<?>))
+            {
+                return new boolean[] {Boolean.valueOf(stripQuotes(desc, obj.toString()))};
             }
-            else {
-                list = (List<Boolean>)obj;
-            }
+            final List<Boolean> list = (List<Boolean>)obj;
             boolean[] values = new boolean[list.size()];
-            for (int i=0; i<values.length; i++) {
+            for (int i=0; i<values.length; i++)
+            {
                 values[i] = list.get(i);
             }
             return values;