Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
metatype-1.0.4
-
None
Description
In class org.apache.felix.metatype.MetaDataReader method readDesignate the "pid" attribute of a "Designate" element is read as required attribute:
designate.setPid( this.getRequiredAttribute( "pid" ) );
designate.setFactoryPid( this.getOptionalAttribute( "factoryPid" ) );
This is wrong as according to the Metatype Service Specification (Version 1.2) the attributes "pid" and "factoryPid" are both optional but at least one of these two must be present (either "pid" or "factoryPid"). Thus the code should be changed to something like this:
final String pid = this.getOptionalAttribute( "pid" );
final String factoryPid = this.getOptionalAttribute( "factoryPid" );
if ( pid == null && factoryPid == null )
designate.setPid( pid );
designate.setFactoryPid( factoryPid );
Also the class MetaData should be fixed, its addDesignate member looks like this:
public void addDesignate( Designate designate )
{
if ( designate != null )
{
if ( designates == null )
designates.put( designate.getPid(), designate );
}
}
but should be implemented something like this:
public void addDesignate( Designate designate )
{
if ( designate != null )
{
if ( designates == null )
{ designates = new HashMap(); }
final String factoryPid = designate.getFactoryPid();
if ( factoryPid == null )
else
{ designates.put( factoryPid, designate ); }
}
}
Additionally the attribute OCD/name should also be treated to be optional (see MetaDataReader's member readOCD).
And last but not least MetaTypeInformationImpl's addMetaData member should be changed like this:
// gather pids and factory pids
if (designate.getFactoryPid() != null)
else
{ this.pids.add(designate.getPid()); this.addMetaTypeProvider(designate.getPid(), dmtp); }