You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2013/07/03 18:45:24 UTC

svn commit: r1499468 - in /felix/trunk/scrplugin/ds-annotations: changelog.txt src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java

Author: cziegeler
Date: Wed Jul  3 16:45:23 2013
New Revision: 1499468

URL: http://svn.apache.org/r1499468
Log:
FELIX-4159 : Error when declaring a multivalued property using the OSGi 4.3 Annotation DS standard

Modified:
    felix/trunk/scrplugin/ds-annotations/changelog.txt
    felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java

Modified: felix/trunk/scrplugin/ds-annotations/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/ds-annotations/changelog.txt?rev=1499468&r1=1499467&r2=1499468&view=diff
==============================================================================
--- felix/trunk/scrplugin/ds-annotations/changelog.txt (original)
+++ felix/trunk/scrplugin/ds-annotations/changelog.txt Wed Jul  3 16:45:23 2013
@@ -1,3 +1,9 @@
+Changes from 1.2.4 to 1.2.2
+---------------------------
+** Bug
+    * [FELIX-4159] - Error when declaring a multivalued property using the OSGi 4.3 Annotation DS standard
+
+
 Changes from 1.2.2 to 1.2.0
 ----------------------------
 ** Bug

Modified: felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java?rev=1499468&r1=1499467&r2=1499468&view=diff
==============================================================================
--- felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java (original)
+++ felix/trunk/scrplugin/ds-annotations/src/main/java/org/apache/felix/scrplugin/ds/DSAnnotationProcessor.java Wed Jul  3 16:45:23 2013
@@ -179,12 +179,41 @@ public class DSAnnotationProcessor imple
                     final String type = (typeSep == -1 ? PropertyType.String.name() : prefix.substring(typeSep + 1));
 
                     final PropertyType propType = PropertyType.valueOf(type);
-                    final PropertyDescription pd = new PropertyDescription(cad);
-                    describedClass.add(pd);
-                    pd.setName(key);
-                    pd.setValue(value);
-                    pd.setType(propType);
-                    pd.setUnbounded(PropertyUnbounded.DEFAULT);
+                    // FELIX-4159 : check if this is a multi value prop
+                    final List<PropertyDescription> existingProps = describedClass.getDescriptions(PropertyDescription.class);
+                    PropertyDescription found = null;
+                    for(final PropertyDescription current : existingProps) {
+                        if ( current.getName().equals(key) ) {
+                            found = current;
+                            break;
+                        }
+                    }
+                    if ( found == null ) {
+                        final PropertyDescription pd = new PropertyDescription(cad);
+                        describedClass.add(pd);
+                        pd.setName(key);
+                        pd.setValue(value);
+                        pd.setType(propType);
+                        pd.setUnbounded(PropertyUnbounded.DEFAULT);
+                    } else {
+                        if ( propType != found.getType() ) {
+                            throw new SCRDescriptorException("Multi value property '" + key + "' has different types: "
+                                    + found.getType() + " & " + propType,
+                                    describedClass.getSource());
+                        }
+                        if ( found.getValue() != null ) {
+                            final String[] values = new String[2];
+                            values[0] = found.getValue();
+                            values[1] = value;
+                            found.setMultiValue(values);
+                        } else {
+                            final String[] oldValues = found.getMultiValue();
+                            final String[] newValues = new String[oldValues.length + 1];
+                            System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
+                            newValues[oldValues.length] = value;
+                            found.setMultiValue(newValues);
+                        }
+                    }
                 }
             }
         }