FELIX-1010 : Add several diffferently typed properties to the property tag.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@774907 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr-annotations/pom.xml b/scr-annotations/pom.xml
index d26196d..e6385d3 100644
--- a/scr-annotations/pom.xml
+++ b/scr-annotations/pom.xml
@@ -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>
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
index c3c624b..c4a7910 100644
--- a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
@@ -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
diff --git a/scrplugin/pom.xml b/scrplugin/pom.xml
index 88f8a49..493854a 100644
--- a/scrplugin/pom.xml
+++ b/scrplugin/pom.xml
@@ -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>
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 5d13e15..4fca54e 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
@@ -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;
- if (this.annotation.type() != AutoDetect.class) {
- type = this.annotation.type().getSimpleName();
+ 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";
}
- map.put(Constants.PROPERTY_TYPE, type);
+
+ 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, "");
+ }
if (this.annotation.cardinality() != 0) {
map.put(Constants.PROPERTY_CARDINALITY, String.valueOf(this.annotation.cardinality()));
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 4a9ed45..8ea1507 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
@@ -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) {