You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ja...@apache.org on 2015/02/18 13:39:54 UTC

svn commit: r1660612 - in /felix/trunk/metatype: ./ src/main/java/org/apache/felix/metatype/ src/main/java/org/apache/felix/metatype/internal/ src/test/java/org/apache/felix/metatype/

Author: jawi
Date: Wed Feb 18 12:39:54 2015
New Revision: 1660612

URL: http://svn.apache.org/r1660612
Log:
FELIX-4799 - Support multiple designates with same factory PID:

- gather all Designates in a list instead of a map, which 
  allows us to obtain all Designates with the same factory
  PID, but different Objects;
- updated changelog to reflect the latest changes for the
  upcoming release.


Modified:
    felix/trunk/metatype/changelog.txt
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/DefaultMetaTypeProvider.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
    felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
    felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java

Modified: felix/trunk/metatype/changelog.txt
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/changelog.txt?rev=1660612&r1=1660611&r2=1660612&view=diff
==============================================================================
--- felix/trunk/metatype/changelog.txt (original)
+++ felix/trunk/metatype/changelog.txt Wed Feb 18 12:39:54 2015
@@ -2,86 +2,91 @@ Changes from 1.0.10 to 1.0.12
 -----------------------------
 
 ** Improvement
-    * [FELIX-4649] - Get MetaTypeInformation while bundle is starting
+	* [FELIX-4649] - Get MetaTypeInformation while bundle is starting
+
+** Bug
+	* [FELIX-4644] - Designates with multiple Objects
+	* [FELIX-4665] - Metatype service does not allow a default empty string in XML resource
+	* [FELIX-4771] - Possible NPE when accessing content of attribute
 
 
 Changes from 1.0.8 to 1.0.10
 ----------------------------
 
 ** Bug
-    * [FELIX-4289] - Spaces within values are removed for default values
+	* [FELIX-4289] - Spaces within values are removed for default values
+
 
- 
 Changes from 1.0.6 to 1.0.8
 ---------------------------
 
 ** Bug
-    * [FELIX-3756] - Optional attributes validated invalid data as correct;
-    * [FELIX-3757] - If an AttributeDefinition did not specify a minimum, maximum or option values, it did not detect missing values;
-    * [FELIX-3758] - AttributeDefinition.validate() did not take non-zero cardinality into consideration.
-    * [FELIX-4214] - Cache in BundleResources works only for a single metatype properties file per bundle
-    * [FELIX-3884] - Default value and options 
+	* [FELIX-3756] - Optional attributes validated invalid data as correct;
+	* [FELIX-3757] - If an AttributeDefinition did not specify a minimum, maximum or option values, it did not detect missing values;
+	* [FELIX-3758] - AttributeDefinition.validate() did not take non-zero cardinality into consideration.
+	* [FELIX-4214] - Cache in BundleResources works only for a single metatype properties file per bundle
+	* [FELIX-3884] - Default value and options 
 
 
 Changes from 1.0.4 to 1.0.6
 ---------------------------
 
 ** Bug
-    * [FELIX-2094] - AttributeDefinition with an empty default value must attribute must result in a single (empty string) entry string array
-    * [FELIX-2097] - DefaultMetaTypeProvider.getLocales() must not reuturn an empty string entry
-    * [FELIX-2860] - getLocales() in DefaultMetaTypeProvider needs to check return of findEntries
-    * [FELIX-2867] - getIcon() in LocalizedObjectClassDefinition keyset iteration incorrect
-    * [FELIX-2868] - Icon only works if absolute path specified, but specification allows for relative urls
-    * [FELIX-3183] - Attribute requirement is not validated
-    * [FELIX-3364] - MetaDataReader exposes a private exception class on the public API
-    * [FELIX-3720] - Designate's pid attribute is optional and not mandatory
-    * [FELIX-3730] - AD.validate of string attributes must validate the string length
-    * [FELIX-3732] - service.pid properties of ManagedServiceFactory services must be used as factory PIDs
-    * [FELIX-3734] - MetaType: NPE in ServiceTracker for fragment bundle
+	* [FELIX-2094] - AttributeDefinition with an empty default value must attribute must result in a single (empty string) entry string array
+	* [FELIX-2097] - DefaultMetaTypeProvider.getLocales() must not reuturn an empty string entry
+	* [FELIX-2860] - getLocales() in DefaultMetaTypeProvider needs to check return of findEntries
+	* [FELIX-2867] - getIcon() in LocalizedObjectClassDefinition keyset iteration incorrect
+	* [FELIX-2868] - Icon only works if absolute path specified, but specification allows for relative urls
+	* [FELIX-3183] - Attribute requirement is not validated
+	* [FELIX-3364] - MetaDataReader exposes a private exception class on the public API
+	* [FELIX-3720] - Designate's pid attribute is optional and not mandatory
+	* [FELIX-3730] - AD.validate of string attributes must validate the string length
+	* [FELIX-3732] - service.pid properties of ManagedServiceFactory services must be used as factory PIDs
+	* [FELIX-3734] - MetaType: NPE in ServiceTracker for fragment bundle
 
 ** Improvement
-    * [FELIX-3167] - Add support for new PASSWORD attribute type
-    * [FELIX-3338] - Add support for optional attributes in the MetaDataReader as defined in the XML schema for metatype
-    * [FELIX-3736] - Add support for MetaTypeProvider service modifications
-    * [FELIX-3740] - Maintain the MetaTypeProvider service tracker on the MetaTypeService
+	* [FELIX-3167] - Add support for new PASSWORD attribute type
+	* [FELIX-3338] - Add support for optional attributes in the MetaDataReader as defined in the XML schema for metatype
+	* [FELIX-3736] - Add support for MetaTypeProvider service modifications
+	* [FELIX-3740] - Maintain the MetaTypeProvider service tracker on the MetaTypeService
 
 ** New Feature
-    * [FELIX-2719] - Add name space support to the meta type implementation
+	* [FELIX-2719] - Add name space support to the meta type implementation
 
 ** Task
-    * [FELIX-2096] - Check MetaTypeProvider.getObjectClassDefinition(String, String) specification compliance
-    * [FELIX-3182] - Update to use parent POM 2.1
-    * [FELIX-3184] - Add support for metatype extension by MetatypeProvider services
-    * [FELIX-3731] - Multi-Value service.pid service properties must be supported
-    * [FELIX-3733] - Clarify icon location
+	* [FELIX-2096] - Check MetaTypeProvider.getObjectClassDefinition(String, String) specification compliance
+	* [FELIX-3182] - Update to use parent POM 2.1
+	* [FELIX-3184] - Add support for metatype extension by MetatypeProvider services
+	* [FELIX-3731] - Multi-Value service.pid service properties must be supported
+	* [FELIX-3733] - Clarify icon location
 
 
 Changes from 1.0.2 to 1.0.4
 ---------------------------
 ** Bug
-    * [FELIX-1226] - The MetaType service should ignore the pid attribute of Designate elements if factoryPid is set.
+	* [FELIX-1226] - The MetaType service should ignore the pid attribute of Designate elements if factoryPid is set.
 
 ** Improvement
-    * [FELIX-718] - Update NOTICE file to new format
-    * [FELIX-1227] - Project Descriptor Enhancement
-    * [FELIX-1434] - Include service tracker in bundle instead of importing it
+	* [FELIX-718] - Update NOTICE file to new format
+	* [FELIX-1227] - Project Descriptor Enhancement
+	* [FELIX-1434] - Include service tracker in bundle instead of importing it
 
 
 Changes from 1.0.0 to 1.0.2
 ---------------------------
 
 ** Bug
-    * [FELIX-520] - MetaDataReader - ad.setMax
-    * [FELIX-521] - MetaType - optionValues check
-    * [FELIX-597] - Meta type service incorrectly parses attribute element content when the content is specified in value child tags
-    * [FELIX-607] - Meta type localization incorrectly resolved in the meta type folder
+	* [FELIX-520] - MetaDataReader - ad.setMax
+	* [FELIX-521] - MetaType - optionValues check
+	* [FELIX-597] - Meta type service incorrectly parses attribute element content when the content is specified in value child tags
+	* [FELIX-607] - Meta type localization incorrectly resolved in the meta type folder
 
 ** Improvement
-    * [FELIX-666] - Metatype OBR description
+	* [FELIX-666] - Metatype OBR description
 
 
 Initial Release 1.0.0
 ---------------------
 
 ** New Feature
-    * [FELIX-20] - Implement Metatype Service
+	* [FELIX-20] - Implement Metatype Service

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/DefaultMetaTypeProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/DefaultMetaTypeProvider.java?rev=1660612&r1=1660611&r2=1660612&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/DefaultMetaTypeProvider.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/DefaultMetaTypeProvider.java Wed Feb 18 12:39:54 2015
@@ -20,9 +20,11 @@ package org.apache.felix.metatype;
 
 
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.TreeSet;
 
@@ -52,8 +54,8 @@ public class DefaultMetaTypeProvider imp
     private final Bundle bundle;
     private final String localePrefix;
 
-    private Map objectClassDefinitions;
-    private Map designates;
+    private Map /* <String, OCD> */ objectClassDefinitions;
+    private List /* <Designate> */ designates;
     private String[] locales;
 
 
@@ -73,12 +75,12 @@ public class DefaultMetaTypeProvider imp
         }
         if ( metadata.getDesignates() == null )
         {
-            designates = Collections.EMPTY_MAP;
+            designates = Collections.EMPTY_LIST;
         }
         else
         {
-            Map copy = new HashMap( metadata.getDesignates() );
-            designates = Collections.unmodifiableMap( copy );
+            List copy = new ArrayList( metadata.getDesignates() );
+            designates = Collections.unmodifiableList( copy );
         }
 
         String metaDataLocalePrefix = metadata.getLocalePrefix();
@@ -175,22 +177,32 @@ public class DefaultMetaTypeProvider imp
         return new LocalizedObjectClassDefinition( bundle, ocd, resources );
     }
 
-
-    public Designate getDesignate( String pid )
+    public Designate getDesignate(String pid)
     {
-        return ( Designate ) designates.get( pid );
+        int size = this.designates.size();
+        for (int i = 0; i < size; i++)
+        {
+            Designate designate = (Designate) this.designates.get(i);
+            String factoryPid = designate.getFactoryPid();
+            if (factoryPid != null && pid.equals(factoryPid))
+            {
+                return designate;
+            }
+            else if (factoryPid == null && pid.equals(designate.getPid()))
+            {
+                return designate;
+            }
+        }
+        return null;
     }
 
-
-    protected Map getObjectClassDefinitions()
+    protected Map /* <String, OCD> */ getObjectClassDefinitions()
     {
         return objectClassDefinitions;
     }
 
-
-    protected Map getDesignates()
+    protected List /* <Designate> */ getDesignates()
     {
         return designates;
     }
-
 }

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaData.java?rev=1660612&r1=1660611&r2=1660612&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaData.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/MetaData.java Wed Feb 18 12:39:54 2015
@@ -19,8 +19,9 @@
 package org.apache.felix.metatype;
 
 import java.net.URL;
-import java.util.HashMap;
+import java.util.ArrayList;
 import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -33,8 +34,8 @@ public class MetaData extends OptionalAt
 {
     private String namespace;
     private String localePrefix;
-    private Map objectClassDefinitions;
-    private Map designates;
+    private Map /* String -> OCD */ objectClassDefinitions;
+    private List /* Designate */ designates;
     private URL source;
 
     public String getLocalePrefix()
@@ -47,7 +48,7 @@ public class MetaData extends OptionalAt
         this.localePrefix = localePrefix;
     }
 
-    public Map getObjectClassDefinitions()
+    public Map /* <String, OCD> */ getObjectClassDefinitions()
     {
         return objectClassDefinitions;
     }
@@ -66,7 +67,7 @@ public class MetaData extends OptionalAt
         }
     }
 
-    public Map getDesignates()
+    public List /* <Designate> */ getDesignates()
     {
         return designates;
     }
@@ -77,17 +78,10 @@ public class MetaData extends OptionalAt
         {
             if (designates == null)
             {
-                designates = new HashMap();
+                designates = new ArrayList();
             }
 
-            if (designate.getFactoryPid() != null)
-            {
-                designates.put(designate.getFactoryPid(), designate);
-            }
-            else
-            {
-                designates.put(designate.getPid(), designate);
-            }
+            designates.add(designate);
         }
     }
 

Modified: felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java?rev=1660612&r1=1660611&r2=1660612&view=diff
==============================================================================
--- felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java (original)
+++ felix/trunk/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java Wed Feb 18 12:39:54 2015
@@ -18,7 +18,6 @@
  */
 package org.apache.felix.metatype.internal;
 
-
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -37,7 +36,6 @@ import org.osgi.service.metatype.MetaTyp
 import org.osgi.service.metatype.MetaTypeProvider;
 import org.osgi.service.metatype.ObjectClassDefinition;
 
-
 /**
  * The <code>MetaTypeInformationImpl</code> class implements the
  * <code>MetaTypeInformation</code> interface returned from the
@@ -47,19 +45,14 @@ import org.osgi.service.metatype.ObjectC
  */
 public class MetaTypeInformationImpl implements MetaTypeInformation
 {
-
     private final Bundle bundle;
-
     private final Set pids;
-
     private final Set factoryPids;
-
     private final Map metaTypeProviders;
 
     private Set locales;
 
-
-    protected MetaTypeInformationImpl( Bundle bundle )
+    protected MetaTypeInformationImpl(Bundle bundle)
     {
         this.bundle = bundle;
         this.pids = new HashSet();
@@ -67,7 +60,6 @@ public class MetaTypeInformationImpl imp
         this.metaTypeProviders = new HashMap();
     }
 
-
     void dispose()
     {
         this.pids.clear();
@@ -76,7 +68,6 @@ public class MetaTypeInformationImpl imp
         this.metaTypeProviders.clear();
     }
 
-
     /*
      * (non-Javadoc)
      *
@@ -87,7 +78,6 @@ public class MetaTypeInformationImpl imp
         return this.bundle;
     }
 
-
     /*
      * (non-Javadoc)
      *
@@ -95,10 +85,9 @@ public class MetaTypeInformationImpl imp
      */
     public String[] getFactoryPids()
     {
-        return ( String[] ) this.factoryPids.toArray( new String[this.factoryPids.size()] );
+        return (String[]) this.factoryPids.toArray(new String[this.factoryPids.size()]);
     }
 
-
     /*
      * (non-Javadoc)
      *
@@ -106,10 +95,9 @@ public class MetaTypeInformationImpl imp
      */
     public String[] getPids()
     {
-        return ( String[] ) this.pids.toArray( new String[this.pids.size()] );
+        return (String[]) this.pids.toArray(new String[this.pids.size()]);
     }
 
-
     /*
      * (non-Javadoc)
      *
@@ -117,48 +105,47 @@ public class MetaTypeInformationImpl imp
      */
     public String[] getLocales()
     {
-        if ( this.locales == null )
+        if (this.locales == null)
         {
-            synchronized ( this )
+            synchronized (this)
             {
                 Set newLocales = new HashSet();
-                for ( Iterator mi = this.metaTypeProviders.values().iterator(); mi.hasNext(); )
+                for (Iterator mi = this.metaTypeProviders.values().iterator(); mi.hasNext();)
                 {
-                    MetaTypeProvider mtp = ( MetaTypeProvider ) mi.next();
-                    this.addValues( newLocales, mtp.getLocales() );
+                    MetaTypeProvider mtp = (MetaTypeProvider) mi.next();
+                    this.addValues(newLocales, mtp.getLocales());
                 }
                 this.locales = newLocales;
             }
         }
 
-        return ( String[] ) this.locales.toArray( new String[this.locales.size()] );
+        return (String[]) this.locales.toArray(new String[this.locales.size()]);
     }
 
-
     /*
      * (non-Javadoc)
      *
      * @see org.osgi.service.metatype.MetaTypeProvider#getObjectClassDefinition(java.lang.String,
      *      java.lang.String)
      */
-    public ObjectClassDefinition getObjectClassDefinition( String id, String locale )
+    public ObjectClassDefinition getObjectClassDefinition(String id, String locale)
     {
 
-        if ( id == null || id.length() == 0 )
+        if (id == null || id.length() == 0)
         {
-            throw new IllegalArgumentException( "ObjectClassDefinition ID must not be null or empty" );
+            throw new IllegalArgumentException("ObjectClassDefinition ID must not be null or empty");
         }
 
-        MetaTypeProvider mtp = ( MetaTypeProvider ) this.metaTypeProviders.get( id );
-        if ( mtp == null )
+        MetaTypeProvider mtp = (MetaTypeProvider) this.metaTypeProviders.get(id);
+        if (mtp == null)
         {
-            throw new IllegalArgumentException( "No ObjectClassDefinition for id=" + id );
+            throw new IllegalArgumentException("No ObjectClassDefinition for id=" + id);
         }
 
-        ObjectClassDefinition ocd = mtp.getObjectClassDefinition( id, locale );
-        if ( ocd == null )
+        ObjectClassDefinition ocd = mtp.getObjectClassDefinition(id, locale);
+        if (ocd == null)
         {
-            throw new IllegalArgumentException( "No localized ObjectClassDefinition for id=" + id );
+            throw new IllegalArgumentException("No localized ObjectClassDefinition for id=" + id);
         }
 
         return ocd;
@@ -181,130 +168,121 @@ public class MetaTypeInformationImpl imp
 
     // ---------- setters to fill the values -----------------------------------
 
-    protected void addMetaData( MetaData md )
+    protected void addMetaData(MetaData md)
     {
-        if ( md.getDesignates() != null )
+        if (md.getDesignates() != null)
         {
             // meta type provide to register by PID
-            DefaultMetaTypeProvider dmtp = new DefaultMetaTypeProvider( this.bundle, md );
+            DefaultMetaTypeProvider dmtp = new DefaultMetaTypeProvider(this.bundle, md);
 
-            Iterator designates = md.getDesignates().values().iterator();
-            while ( designates.hasNext() )
+            Iterator designates = md.getDesignates().iterator();
+            while (designates.hasNext())
             {
-                Designate designate = ( Designate ) designates.next();
+                Designate designate = (Designate) designates.next();
 
                 // get the OCD reference, ignore the designate if none
                 DesignateObject object = designate.getObject();
-                String ocdRef = ( object == null ) ? null : object.getOcdRef();
-                if ( ocdRef == null )
+                String ocdRef = (object == null) ? null : object.getOcdRef();
+                if (ocdRef == null)
                 {
                     continue;
                 }
 
                 // get ocd for the reference, ignore designate if none
-                OCD ocd = ( OCD ) md.getObjectClassDefinitions().get( ocdRef );
-                if ( ocd == null )
+                OCD ocd = (OCD) md.getObjectClassDefinitions().get(ocdRef);
+                if (ocd == null)
                 {
                     continue;
                 }
 
                 // gather pids and factory pids and register provider
-                if ( designate.getFactoryPid() != null )
+                if (designate.getFactoryPid() != null)
                 {
-                    this.factoryPids.add( designate.getFactoryPid() );
-                    this.addMetaTypeProvider( designate.getFactoryPid(), dmtp );
+                    this.factoryPids.add(designate.getFactoryPid());
+                    this.addMetaTypeProvider(designate.getFactoryPid(), dmtp);
                 }
                 else
                 {
-                    this.pids.add( designate.getPid() );
-                    this.addMetaTypeProvider( designate.getPid(), dmtp );
+                    this.pids.add(designate.getPid());
+                    this.addMetaTypeProvider(designate.getPid(), dmtp);
                 }
             }
         }
     }
 
-
-    protected void addMetaTypeProvider( String key, MetaTypeProvider mtp )
+    protected void addMetaTypeProvider(String key, MetaTypeProvider mtp)
     {
-        if ( key != null && mtp != null )
+        if (key != null && mtp != null)
         {
-            this.metaTypeProviders.put( key, mtp );
+            this.metaTypeProviders.put(key, mtp);
             this.locales = null;
         }
     }
 
-
-    protected MetaTypeProvider removeMetaTypeProvider( String key )
+    protected MetaTypeProvider removeMetaTypeProvider(String key)
     {
-        if ( key != null )
+        if (key != null)
         {
             this.locales = null;
-            return ( MetaTypeProvider ) this.metaTypeProviders.remove( key );
+            return (MetaTypeProvider) this.metaTypeProviders.remove(key);
         }
 
         return null;
     }
 
-
-    protected void addSingletonMetaTypeProvider( String[] pids, MetaTypeProvider mtp )
+    protected void addSingletonMetaTypeProvider(String[] pids, MetaTypeProvider mtp)
     {
-        this.addValues( this.pids, pids );
-        for ( int i = 0; i < pids.length; i++ )
+        this.addValues(this.pids, pids);
+        for (int i = 0; i < pids.length; i++)
         {
-            addMetaTypeProvider( pids[i], mtp );
+            addMetaTypeProvider(pids[i], mtp);
         }
     }
 
-
-    protected void addFactoryMetaTypeProvider( String[] factoryPids, MetaTypeProvider mtp )
+    protected void addFactoryMetaTypeProvider(String[] factoryPids, MetaTypeProvider mtp)
     {
-        this.addValues( this.factoryPids, factoryPids );
-        for ( int i = 0; i < factoryPids.length; i++ )
+        this.addValues(this.factoryPids, factoryPids);
+        for (int i = 0; i < factoryPids.length; i++)
         {
-            addMetaTypeProvider( factoryPids[i], mtp );
+            addMetaTypeProvider(factoryPids[i], mtp);
         }
     }
 
-
-    protected boolean removeSingletonMetaTypeProvider( String[] pids )
+    protected boolean removeSingletonMetaTypeProvider(String[] pids)
     {
         boolean wasRegistered = false;
-        for ( int i = 0; i < pids.length; i++ )
+        for (int i = 0; i < pids.length; i++)
         {
-            wasRegistered |= ( removeMetaTypeProvider( pids[i] ) != null );
-            this.pids.remove( pids[i] );
+            wasRegistered |= (removeMetaTypeProvider(pids[i]) != null);
+            this.pids.remove(pids[i]);
         }
         return wasRegistered;
     }
 
-
-    protected boolean removeFactoryMetaTypeProvider( String[] factoryPids )
+    protected boolean removeFactoryMetaTypeProvider(String[] factoryPids)
     {
         boolean wasRegistered = false;
-        for ( int i = 0; i < factoryPids.length; i++ )
+        for (int i = 0; i < factoryPids.length; i++)
         {
-            wasRegistered |= ( removeMetaTypeProvider( factoryPids[i] ) != null );
-            this.factoryPids.remove( factoryPids[i] );
+            wasRegistered |= (removeMetaTypeProvider(factoryPids[i]) != null);
+            this.factoryPids.remove(factoryPids[i]);
         }
         return wasRegistered;
     }
 
-
-    protected void addService( String[] pids, boolean isSingleton, boolean isFactory, final MetaTypeProvider mtp )
+    protected void addService(String[] pids, boolean isSingleton, boolean isFactory, final MetaTypeProvider mtp)
     {
     }
 
-
-    protected void removeService( String[] pids, boolean isSingleton, boolean isFactory )
+    protected void removeService(String[] pids, boolean isSingleton, boolean isFactory)
     {
     }
 
-
-    private void addValues( Collection dest, Object[] values )
+    private void addValues(Collection dest, Object[] values)
     {
-        if ( values != null && values.length > 0 )
+        if (values != null && values.length > 0)
         {
-            dest.addAll( Arrays.asList( values ) );
+            dest.addAll(Arrays.asList(values));
         }
     }
 }

Modified: felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java?rev=1660612&r1=1660611&r2=1660612&view=diff
==============================================================================
--- felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java (original)
+++ felix/trunk/metatype/src/test/java/org/apache/felix/metatype/MetaDataReaderTest.java Wed Feb 18 12:39:54 2015
@@ -22,7 +22,7 @@ import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Arrays;
-import java.util.Map;
+import java.util.List;
 
 import junit.framework.TestCase;
 
@@ -317,10 +317,10 @@ public class MetaDataReaderTest extends
 
         assertNotNull(ocd.getAttributeDefinitions());
 
-        Map designates = ocd.getMetadata().getDesignates();
+        List designates = ocd.getMetadata().getDesignates();
         assertEquals(1, designates.size());
 
-        Designate designate = (Designate) designates.get(pid);
+        Designate designate = (Designate) designates.get(0);
         assertEquals(pid, designate.getPid());
         assertNotNull(designate.getObject());
     }
@@ -349,6 +349,38 @@ public class MetaDataReaderTest extends
         }
     }
 
+    /**
+     * FELIX-4799 - tests that we can have multiple designates for the same factory PID in one MetaData configuration. 
+     */
+    public void testMultipleFactoryDesignatesWithSamePidOk() throws IOException, XmlPullParserException
+    {
+        String xml = "<MetaData><OCD id=\"ocd\" name=\"ocd\"><AD id=\"attr\" type=\"String\" required=\"false\" /></OCD>"
+            + "<Designate factoryPid=\"factoryA\" pid=\"A\" bundle=\"*\"><Object ocdref=\"ocd\"><Attribute adref=\"attr\" value=\"foo\" /></Object></Designate>"
+            + "<Designate factoryPid=\"factoryA\" pid=\"B\" bundle=\"*\"><Object ocdref=\"ocd\"><Attribute adref=\"attr\" value=\"bar\" /></Object></Designate>" + "</MetaData>";
+
+        MetaData metadata = read(xml);
+        assertNotNull(metadata);
+
+        assertEquals(1, metadata.getObjectClassDefinitions().size());
+        assertEquals(2, metadata.getDesignates().size());
+    }
+
+    /**
+     * FELIX-4799 - tests that we can have multiple designates for the same factory PID in one MetaData configuration. 
+     */
+    public void testMultipleFactoryDesignatesWithDifferentPidsOk() throws IOException, XmlPullParserException
+    {
+        String xml = "<MetaData><OCD id=\"ocd\" name=\"ocd\"><AD id=\"attr\" type=\"String\" required=\"false\" /></OCD>"
+            + "<Designate factoryPid=\"factoryA\" pid=\"A\" bundle=\"*\"><Object ocdref=\"ocd\"><Attribute adref=\"attr\" value=\"foo\" /></Object></Designate>"
+            + "<Designate factoryPid=\"factoryB\" pid=\"A\" bundle=\"*\"><Object ocdref=\"ocd\"><Attribute adref=\"attr\" value=\"bar\" /></Object></Designate>" + "</MetaData>";
+
+        MetaData metadata = read(xml);
+        assertNotNull(metadata);
+
+        assertEquals(1, metadata.getObjectClassDefinitions().size());
+        assertEquals(2, metadata.getDesignates().size());
+    }
+
     public void testSingleOCDSingleRequiredAttr() throws IOException, XmlPullParserException
     {
         testSingleOCDSingleRequiredAttr("String", AttributeDefinition.STRING, MetaDataReader.NAMESPACE_1_0);