Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-3720

Designate's pid attribute is optional and not mandatory

    XMLWordPrintableJSON

Details

    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 )

      { missingAttribute("pid or factoryPid"); }

      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 = new HashMap(); }

      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 )

      { designates.put( designate.getPid(), designate ); }

      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)

      { this.factoryPids.add( designate.getFactoryPid() ); this.addMetaTypeProvider(designate.getFactoryPid(), dmtp); }

      else

      { this.pids.add(designate.getPid()); this.addMetaTypeProvider(designate.getPid(), dmtp); }

      Attachments

        1. metatype.diff
          3 kB
          Alexander Berger

        Activity

          People

            fmeschbe Felix Meschberger
            alexberger Alexander Berger
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: