Author: cziegeler
Date: Tue Feb 22 17:16:09 2011
New Revision: 1073416
URL: http://svn.apache.org/viewvc?rev=1073416&view=rev
Log:
FELIX-2838 : Allow classes to be specifed as values for the @Property annotation
Modified:
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
Modified:
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Property.java?rev=1073416&r1=1073415&r2=1073416&view=diff
==============================================================================
---
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
(original)
+++
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scr/annotations/Property.java
Tue Feb 22 17:16:09 2011
@@ -18,11 +18,7 @@
*/
package org.apache.felix.scr.annotations;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.lang.annotation.*;
/**
* The <code>Property</code> annotation defines properties which are made
@@ -70,6 +66,14 @@ public @interface Property {
String[] value() default {};
/**
+ * The class value(s) of the property.
+ * This attribute should not be used in combination with any of the other
+ * value attributes or the type attribute.
+ * @since 1.5
+ */
+ Class<?>[] classValue() default {};
+
+ /**
* 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.
Modified:
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java?rev=1073416&r1=1073415&r2=1073416&view=diff
==============================================================================
---
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
(original)
+++
felix/trunk/scrplugin/annotations/src/main/java/org/apache/felix/scrplugin/tags/annotation/defaulttag/PropertyTag.java
Tue Feb 22 17:16:09 2011
@@ -93,6 +93,10 @@ public class PropertyTag extends Abstrac
return Util.getStringValues(annotation, desc, "value");
}
+ public Class<?>[] classValue() {
+ return Util.getClassArrayValue(annotation, "classValue",
Property.class);
+ }
+
public boolean[] boolValue() {
return Util.getBooleanValues(annotation, desc, "boolValue");
}
@@ -153,76 +157,85 @@ public class PropertyTag extends Abstrac
Object[] values = this.annotation.value();
// we now check all options
if (values == null || values.length == 0 ) {
- long[] lValues = this.annotation.longValue();
- if ( lValues == null || lValues.length == 0 ) {
- double[] dValues = this.annotation.doubleValue();
- if ( dValues == null || dValues.length == 0 ) {
- float[] fValues = this.annotation.floatValue();
- if ( fValues == null || fValues.length == 0 ) {
- int[] iValues = this.annotation.intValue();
- if ( iValues == null || iValues.length == 0 ) {
- byte[] byteValues = this.annotation.byteValue();
- if ( byteValues == null || byteValues.length == 0
) {
- char[] cValues = this.annotation.charValue();
- if ( cValues == null || cValues.length == 0 ) {
- boolean[] boolValues =
this.annotation.boolValue();
- if ( boolValues == null ||
boolValues.length == 0 ) {
- short[] sValues =
this.annotation.shortValue();
- if ( sValues != null && sValues.length
!= 0 ) {
- values = new
Object[sValues.length];
- for(int i=0;i<sValues.length;i++) {
- values[i] = sValues[i];
+ final Class<?>[] classValues = this.annotation.classValue();
+ if ( classValues == null || classValues.length == 0 ) {
+ long[] lValues = this.annotation.longValue();
+ if ( lValues == null || lValues.length == 0 ) {
+ double[] dValues = this.annotation.doubleValue();
+ if ( dValues == null || dValues.length == 0 ) {
+ float[] fValues = this.annotation.floatValue();
+ if ( fValues == null || fValues.length == 0 ) {
+ int[] iValues = this.annotation.intValue();
+ if ( iValues == null || iValues.length == 0 ) {
+ byte[] byteValues =
this.annotation.byteValue();
+ if ( byteValues == null || byteValues.length
== 0 ) {
+ char[] cValues =
this.annotation.charValue();
+ if ( cValues == null || cValues.length ==
0 ) {
+ boolean[] boolValues =
this.annotation.boolValue();
+ if ( boolValues == null ||
boolValues.length == 0 ) {
+ short[] sValues =
this.annotation.shortValue();
+ 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 = new
Object[boolValues.length];
+ for(int
i=0;i<boolValues.length;i++) {
+ values[i] = boolValues[i];
}
- type = "Short";
+ type = "Boolean";
}
} else {
- values = new Object[boolValues.length];
- for(int i=0;i<boolValues.length;i++) {
- values[i] = boolValues[i];
+ values = new Object[cValues.length];
+ for(int i=0;i<cValues.length;i++) {
+ values[i] = cValues[i];
}
- type = "Boolean";
+ type = "Char";
}
} else {
- values = new Object[cValues.length];
- for(int i=0;i<cValues.length;i++) {
- values[i] = cValues[i];
+ values = new Object[byteValues.length];
+ for(int i=0;i<byteValues.length;i++) {
+ values[i] = byteValues[i];
}
- type = "Char";
+ type = "Byte";
}
} else {
- values = new Object[byteValues.length];
- for(int i=0;i<byteValues.length;i++) {
- values[i] = byteValues[i];
+ values = new Object[iValues.length];
+ for(int i=0;i<iValues.length;i++) {
+ values[i] = iValues[i];
}
- type = "Byte";
+ type = "Integer";
}
} else {
- values = new Object[iValues.length];
- for(int i=0;i<iValues.length;i++) {
- values[i] = iValues[i];
+ values = new Object[fValues.length];
+ for(int i=0;i<fValues.length;i++) {
+ values[i] = fValues[i];
}
- type = "Integer";
+ type = "Float";
}
} else {
- values = new Object[fValues.length];
- for(int i=0;i<fValues.length;i++) {
- values[i] = fValues[i];
+ values = new Object[dValues.length];
+ for(int i=0;i<dValues.length;i++) {
+ values[i] = dValues[i];
}
- type = "Float";
+ type = "Double";
}
} else {
- values = new Object[dValues.length];
- for(int i=0;i<dValues.length;i++) {
- values[i] = dValues[i];
+ values = new Object[lValues.length];
+ for(int i=0;i<lValues.length;i++) {
+ values[i] = lValues[i];
}
- type = "Double";
+ type = "Long";
}
} else {
- values = new Object[lValues.length];
- for(int i=0;i<lValues.length;i++) {
- values[i] = lValues[i];
+ values = new Object[classValues.length];
+ for(int i=0;i<classValues.length;i++) {
+ values[i] = classValues[i].getName();
}
- type = "Long";
+ type = "String";
}
} else {
type = "String";