felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r774907 - in /felix/trunk: scr-annotations/ scr-annotations/src/main/java/org/apache/felix/scr/annotations/ scrplugin/ scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/
Date Thu, 14 May 2009 20:05:46 GMT
Author: cziegeler
Date: Thu May 14 20:05:45 2009
New Revision: 774907

URL: http://svn.apache.org/viewvc?rev=774907&view=rev
Log:
FELIX-1010 : Add several diffferently typed properties to the property tag.

Modified:
    felix/trunk/scr-annotations/pom.xml
    felix/trunk/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
    felix/trunk/scrplugin/pom.xml
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
    felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java

Modified: felix/trunk/scr-annotations/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr-annotations/pom.xml?rev=774907&r1=774906&r2=774907&view=diff
==============================================================================
--- felix/trunk/scr-annotations/pom.xml (original)
+++ felix/trunk/scr-annotations/pom.xml Thu May 14 20:05:45 2009
@@ -20,9 +20,9 @@
 
 	<modelVersion>4.0.0</modelVersion>
 	<parent>
-		<artifactId>felix</artifactId>
+        <artifactId>felix-parent</artifactId>
 		<groupId>org.apache.felix</groupId>
-		<version>1.0.4</version>
+		<version>1.2.0</version>
 		<relativePath>../pom/pom.xml</relativePath>
 	</parent>
 	

Modified: felix/trunk/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java?rev=774907&r1=774906&r2=774907&view=diff
==============================================================================
--- felix/trunk/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
(original)
+++ felix/trunk/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
Thu May 14 20:05:45 2009
@@ -60,15 +60,66 @@
      * The value(s) of the property. If the property type is not String, parsing
      * of the value is done using the valueOf(String) method of the class
      * defined by the property type.
+     * This attribute should not be used in combination with any of the other
+     * value attributes.
      */
     String[] value() default "";
 
     /**
-     * The type of the property value. This must be one of {@link String},
-     * {@link Long}, {@link Double}, {@link Float}, {@link Integer},
-     * {@link Byte}, {@link Character}, {@link Boolean} and {@link Short}.
+     * The long value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes or the type attribute.
      */
-    Class<?> type() default AutoDetect.class;
+    long[] longValue() default 0;
+
+    /**
+     * The double value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes.
+     */
+    double[] doubleValue() default 0.0;
+
+    /**
+     * The float value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes or the type attribute.
+     */
+    float[] floatValue() default 0;
+
+    /**
+     * The int value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes or the type attribute.
+     */
+    int[] intValue() default 0;
+
+    /**
+     * The byte value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes or the type attribute.
+     */
+    byte[] byteValue() default 0;
+
+    /**
+     * The char value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes or the type attribute.
+     */
+    char[] charValue() default '\0';
+
+    /**
+     * The bool value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes or the type attribute.
+     */
+    boolean[] boolValue() default false;
+
+    /**
+     * The short value(s) of the property.
+     * This attribute should not be used in combination with any of the other
+     * value attributes or the type attribute.
+     */
+    short[] shortValue() default 0;
 
     /**
      * Defines the cardinality of the property and its collection type. If the

Modified: felix/trunk/scrplugin/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/pom.xml?rev=774907&r1=774906&r2=774907&view=diff
==============================================================================
--- felix/trunk/scrplugin/pom.xml (original)
+++ felix/trunk/scrplugin/pom.xml Thu May 14 20:05:45 2009
@@ -20,9 +20,9 @@
 
     <modelVersion>4.0.0</modelVersion>
     <parent>
-        <artifactId>felix</artifactId>
+        <artifactId>felix-parent</artifactId>
         <groupId>org.apache.felix</groupId>
-        <version>1.0.4</version>
+        <version>1.2.0</version>
         <relativePath>../pom/pom.xml</relativePath>
     </parent>
 

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java?rev=774907&r1=774906&r2=774907&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
(original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
Thu May 14 20:05:45 2009
@@ -20,7 +20,8 @@
 
 import java.util.*;
 
-import org.apache.felix.scr.annotations.*;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.PropertyOption;
 import org.apache.felix.scrplugin.Constants;
 import org.apache.felix.scrplugin.tags.JavaClassDescription;
 import org.apache.felix.scrplugin.tags.JavaField;
@@ -75,13 +76,41 @@
                 return Util.getBooleanValue(annotation, "propertyPrivate", Property.class);
             }
 
-            public Class<?> type() {
-                return Util.getClassValue(annotation, "type", Property.class);
-            }
-
             public String[] value() {
                 // value property can be used as String[] or String property
-                return Util.getStringValues(annotation, desc, "value", Property.class);
+                return Util.getStringValues(annotation, desc, "value");
+            }
+
+            public boolean[] boolValue() {
+                return Util.getBooleanValues(annotation, desc, "boolValue");
+            }
+
+            public byte[] byteValue() {
+                return Util.getByteValues(annotation, desc, "byteValue");
+            }
+
+            public char[] charValue() {
+                return Util.getCharValues(annotation, desc, "charValue");
+            }
+
+            public double[] doubleValue() {
+                return Util.getDoubleValues(annotation, desc, "doubleValue");
+            }
+
+            public float[] floatValue() {
+                return Util.getFloatValues(annotation, desc, "floatValue");
+            }
+
+            public int[] intValue() {
+                return Util.getIntValues(annotation, desc, "intValue");
+            }
+
+            public long[] longValue() {
+                return Util.getLongValues(annotation, desc, "longValue");
+            }
+
+            public short[] shortValue() {
+                return Util.getShortValues(annotation, desc, "shortValue");
             }
 
             public Class<? extends java.lang.annotation.Annotation> annotationType()
{
@@ -103,22 +132,74 @@
         map.put(Constants.PROPERTY_LABEL, emptyToNull(this.annotation.label()));
         map.put(Constants.PROPERTY_DESCRIPTION, emptyToNull(this.annotation.description()));
 
-        String[] values = this.annotation.value();
-        if (values == null || values.length == 0) {
-            map.put(Constants.PROPERTY_VALUE, "");
-        } else if (values.length == 1) {
-            map.put(Constants.PROPERTY_VALUE, values[0]);
-        } else {
-            for (int i = 0; i < values.length; i++) {
-                map.put(Constants.PROPERTY_MULTIVALUE_PREFIX + '.' + i, values[i]);
+
+        String type = null;
+        Object[] values = this.annotation.value();
+        // we now check all options
+        if (values == null || values.length == 0 ) {
+            long[] lValues = this.annotation.longValue();
+            if ( lValues.length == 0 ) {
+                double[] dValues = this.annotation.doubleValue();
+                if ( dValues.length == 0 ) {
+                    float[] fValues = this.annotation.floatValue();
+                    if ( fValues.length == 0 ) {
+                        int[] iValues = this.annotation.intValue();
+                        if ( iValues.length == 0 ) {
+                            byte[] byteValues = this.annotation.byteValue();
+                            if ( byteValues.length == 0 ) {
+                                char[] cValues = this.annotation.charValue();
+                                if ( cValues.length == 0 ) {
+                                    boolean[] boolValues = this.annotation.boolValue();
+                                    if ( boolValues.length == 0 ) {
+                                        short[] sValues  = this.annotation.shortValue();
+                                        if ( boolValues.length != 0 ) {
+                                            values = Arrays.asList(sValues).toArray();
+                                            type = "Short";
+                                        }
+                                    } else {
+                                        values = Arrays.asList(boolValues).toArray();
+                                        type = "Boolean";
+                                    }
+                                } else {
+                                    values = Arrays.asList(cValues).toArray();
+                                    type = "Char";
+                                }
+                            } else {
+                                values = Arrays.asList(byteValues).toArray();
+                                type = "Byte";
+                            }
+                        } else {
+                            values = Arrays.asList(fValues).toArray();
+                            type = "Integer";
+                        }
+                    } else {
+                        values = Arrays.asList(fValues).toArray();
+                        type = "Float";
+                    }
+                } else {
+                    values = Arrays.asList(dValues).toArray();
+                    type = "Double";
+                }
+            } else {
+                values = Arrays.asList(lValues).toArray();
+                type = "Long";
             }
+        } else {
+            type = "String";
         }
 
-        String type = null;
-        if (this.annotation.type() != AutoDetect.class) {
-            type = this.annotation.type().getSimpleName();
+        if ( values != null ) {
+            map.put(Constants.PROPERTY_TYPE, type);
+            if (values.length == 1) {
+                map.put(Constants.PROPERTY_VALUE, values[0].toString());
+            } else {
+                for (int i = 0; i < values.length; i++) {
+                    map.put(Constants.PROPERTY_MULTIVALUE_PREFIX + '.' + i, values[i].toString());
+                }
+            }
+        } else {
+            map.put(Constants.PROPERTY_VALUE, "");
         }
-        map.put(Constants.PROPERTY_TYPE, type);
 
         if (this.annotation.cardinality() != 0) {
             map.put(Constants.PROPERTY_CARDINALITY, String.valueOf(this.annotation.cardinality()));

Modified: felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java?rev=774907&r1=774906&r2=774907&view=diff
==============================================================================
--- felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
(original)
+++ felix/trunk/scrplugin/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/Util.java
Thu May 14 20:05:45 2009
@@ -69,7 +69,7 @@
         }
     }
 
-    public static String[] getStringValues(Annotation annotation, JavaClassDescription desc,
String name, final Class<?> clazz) {
+    public static String[] getStringValues(Annotation annotation, JavaClassDescription desc,
String name) {
         final Object obj = annotation.getNamedParameter(name);
         if ( obj != null ) {
             List<String> list;
@@ -86,12 +86,167 @@
             }
             return values;
         }
-        try {
-            return (String[]) clazz.getMethod(name).getDefaultValue();
-        } catch( NoSuchMethodException mnfe) {
-            // we ignore this
-            return null;
+        return 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);
+            }
+            else {
+                list = (List<Long>)obj;
+            }
+            long[] values = new long[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
+        }
+        return 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);
+            }
+            else {
+                list = (List<Integer>)obj;
+            }
+            int[] values = new int[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
+        }
+        return 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);
+            }
+            else {
+                list = (List<Float>)obj;
+            }
+            float[] values = new float[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
+        }
+        return 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);
+            }
+            else {
+                list = (List<Double>)obj;
+            }
+            double[] values = new double[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
+        }
+        return 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);
+            }
+            else {
+                list = (List<Character>)obj;
+            }
+            char[] values = new char[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
+        }
+        return 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);
+            }
+            else {
+                list = (List<Short>)obj;
+            }
+            short[] values = new short[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
         }
+        return 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);
+            }
+            else {
+                list = (List<Byte>)obj;
+            }
+            byte[] values = new byte[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
+        }
+        return 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);
+            }
+            else {
+                list = (List<Boolean>)obj;
+            }
+            boolean[] values = new boolean[list.size()];
+            for (int i=0; i<values.length; i++) {
+                values[i] = list.get(i);
+            }
+            return values;
+        }
+        return null;
     }
 
     public static String getStringValue(Annotation annotation, JavaClassDescription desc,
String name, final Class<?> clazz) {



Mime
View raw message