FELIX-3720 Apply slightly modified patch by Alexander Berger (thanks alot)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1399617 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/metatype/src/main/java/org/apache/felix/metatype/MetaData.java b/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
index e7d69d4..9abf244 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/MetaData.java
@@ -87,7 +87,14 @@
designates = new HashMap();
}
- designates.put( designate.getPid(), designate );
+ if ( designate.getFactoryPid() != null )
+ {
+ designates.put( designate.getFactoryPid(), designate );
+ }
+ else
+ {
+ designates.put( designate.getPid(), designate );
+ }
}
}
diff --git a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
index b3ce2b6..482529d 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/MetaDataReader.java
@@ -84,7 +84,7 @@
private final Set DESIGNATEOBJECT_ATTRIBUTES = new HashSet(Arrays.asList(new String[] { "ocdref" }));
private final Set METADATA_ATTRIBUTES = new HashSet(Arrays.asList(new String[] { "localization" }));
private final Set OCD_ATTRIBUTES = new HashSet(Arrays.asList(new String[] { "name", "description", "id" }));
-
+
/**
* Parses the XML document provided by the <code>url</code>. The XML document
@@ -196,7 +196,7 @@
return mti;
}
-
+
private void readOptionalAttributes(OptionalAttributes entity, Set attributes) {
int count = this.parser.getAttributeCount();
for (int i = 0; i < count; i++)
@@ -209,13 +209,13 @@
}
}
}
-
+
private MetaData readMetaData() throws IOException, XmlPullParserException
{
MetaData mti = this.createMetaData();
mti.setLocalePrefix( this.getOptionalAttribute( "localization" ) );
-
+
readOptionalAttributes(mti, METADATA_ATTRIBUTES);
int eventType = this.parser.next();
@@ -258,7 +258,7 @@
ocd.setId( this.getRequiredAttribute( "id" ) );
ocd.setName( this.getRequiredAttribute( "name" ) );
ocd.setDescription( this.getOptionalAttribute( "description" ) );
-
+
readOptionalAttributes(ocd, OCD_ATTRIBUTES);
int eventType = this.parser.next();
@@ -310,13 +310,20 @@
private Designate readDesignate() throws IOException, XmlPullParserException
{
+ final String pid = this.getOptionalAttribute( "pid" );
+ final String factoryPid = this.getOptionalAttribute( "factoryPid" );
+ if ( pid == null && factoryPid == null )
+ {
+ missingAttribute( "pid or factoryPid" );
+ }
+
Designate designate = this.createDesignate();
- designate.setPid( this.getRequiredAttribute( "pid" ) );
- designate.setFactoryPid( this.getOptionalAttribute( "factoryPid" ) );
+ designate.setPid( pid );
+ designate.setFactoryPid( factoryPid );
designate.setBundleLocation( this.getOptionalAttribute( "bundle" ) );
designate.setOptional( this.getOptionalAttribute( "optional", false ) );
designate.setMerge( this.getOptionalAttribute( "merge", false ) );
-
+
readOptionalAttributes(designate, DESIGNATE_ATTRIBUTES);
int eventType = this.parser.next();
@@ -363,7 +370,7 @@
ad.setRequired( this.getOptionalAttribute( "required", true ) );
readOptionalAttributes(ad, AD_ATTRIBUTES);
-
+
Map options = new LinkedHashMap();
int eventType = this.parser.next();
while ( eventType != XmlPullParser.END_DOCUMENT )
@@ -405,7 +412,7 @@
{
DesignateObject oh = this.createDesignateObject();
oh.setOcdRef( this.getRequiredAttribute( "ocdref" ) );
-
+
readOptionalAttributes(oh, DESIGNATEOBJECT_ATTRIBUTES);
int eventType = this.parser.next();
diff --git a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
index f1fd44c..dbf3772 100644
--- a/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
+++ b/metatype/src/main/java/org/apache/felix/metatype/internal/MetaTypeInformationImpl.java
@@ -179,15 +179,17 @@
continue;
}
- // gather pids and factory pids
- if (designate.getFactoryPid() != null) {
+ // gather pids and factory pids and register provider
+ if ( designate.getFactoryPid() != null )
+ {
this.factoryPids.add( designate.getFactoryPid() );
- } else {
- this.pids.add(designate.getPid());
+ this.addMetaTypeProvider( designate.getFactoryPid(), dmtp );
}
-
- // register a metatype provider for the pid
- this.addMetaTypeProvider(designate.getPid(), dmtp);
+ else
+ {
+ this.pids.add( designate.getPid() );
+ this.addMetaTypeProvider( designate.getPid(), dmtp );
+ }
}
}
}