FELIX-2478 : Cardinality attribute for Property annotation should be of type string
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@965433 13f79535-47bb-0310-9956-ffa450edef68
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 0961f5e..348a73a 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
@@ -128,18 +128,25 @@
* the Wrapper class), if the cardinality is positive, the property is
* stored in an array (primitve types are unboxed, that is Boolean type
* values are stored in boolean[]). The actual value defines the maximum
- * number of elements in the vector or array, where −2147483648
- * (Integer.MIN_INT) describes an unbounded Vector and 2147483647
- * (Integer.MAX_INT) describes an unbounded array. If the cardinality is
+ * number of elements in the vector or array. If the cardinality is
* zero, the property is a scalar value. If the defined value of the
- * property is set in the value attribute, the cardinality defaults to0
+ * property is set in the value attribute, the cardinality defaults to 0
* (zero for scalar value). If the property is defined in one or more
* properties starting with values, the cardinality defaults to
- * 2147483647 (Integer.MAX_INT), that is an unbounded array.
+ * an unbounded array.
*/
int cardinality() default 0;
/**
+ * This defines if the property is unbounded. The property can either be
+ * an unbounded array or vector. If this attribute is set to any other
+ * value than {@link PropertyUnbounded#DEFAULT},
+ * this overrides the {@link #cardinality()}.
+ * @since 1.4
+ */
+ PropertyUnbounded unbounded() default PropertyUnbounded.DEFAULT;
+
+ /**
* Boolean flag defining whether a metatype descriptor entry should be
* generated for this property or not. By default a metatype descriptor
* entry, i.e. an AD element, is generated except for the properties
diff --git a/scr-annotations/src/main/java/org/apache/felix/scr/annotations/PropertyUnbounded.java b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/PropertyUnbounded.java
new file mode 100644
index 0000000..4dc01d9
--- /dev/null
+++ b/scr-annotations/src/main/java/org/apache/felix/scr/annotations/PropertyUnbounded.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.annotations;
+
+/**
+ * Options for {@link Property#unbounded()} property.
+ * @since 1.4
+ */
+public enum PropertyUnbounded {
+
+ /** Property is not unbounded. This is the default. */
+ DEFAULT,
+
+ /** Property is an unbounded array. */
+ ARRAY,
+
+ /** Property is an unbounded vector. */
+ VECTOR
+}
diff --git a/scrplugin/pom.xml b/scrplugin/pom.xml
index 7c79a4f..8b383a9 100644
--- a/scrplugin/pom.xml
+++ b/scrplugin/pom.xml
@@ -67,7 +67,7 @@
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
- <version>1.3.0</version>
+ <version>1.3.1-SNAPSHOT</version>
</dependency>
<!-- Sling Servlet SCR Annotation -->
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 33ca627..4900d9e 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,8 +20,7 @@
import java.util.*;
-import org.apache.felix.scr.annotations.Property;
-import org.apache.felix.scr.annotations.PropertyOption;
+import org.apache.felix.scr.annotations.*;
import org.apache.felix.scrplugin.Constants;
import org.apache.felix.scrplugin.tags.JavaClassDescription;
import org.apache.felix.scrplugin.tags.JavaField;
@@ -124,6 +123,10 @@
return Util.getShortValues(annotation, desc, "shortValue");
}
+ public PropertyUnbounded unbounded() {
+ return Util.getEnumValue(annotation, "unbounded", PropertyUnbounded.class, Property.class);
+ }
+
public Class<? extends java.lang.annotation.Annotation> annotationType() {
return null;
}
@@ -234,7 +237,15 @@
}
}
- if (this.annotation.cardinality() != 0) {
+ // cardinality handling
+ final PropertyUnbounded pu = this.annotation.unbounded();
+ if ( pu != PropertyUnbounded.DEFAULT ) {
+ if ( pu == PropertyUnbounded.ARRAY ) {
+ map.put(Constants.PROPERTY_CARDINALITY, "+");
+ } else {
+ map.put(Constants.PROPERTY_CARDINALITY, "-");
+ }
+ } else if (this.annotation.cardinality() != 0) {
map.put(Constants.PROPERTY_CARDINALITY, String.valueOf(this.annotation.cardinality()));
}