code: public void registerDeclaration(T declaration) {
          synchronized (declarationsRegistered) {
              if (declarationsRegistered.containsKey(declaration)) {
                  throw new IllegalStateException("The given Declaration has already been registered.");
              }
  
              Dictionary<String, Object> props = new Hashtable<String, Object>();
              if(declaration.getMetadata().get("id") != null){
                  props.put("importer.id",declaration.getMetadata().get("id").toString());
  
              }
              String[] clazzes = new String[]{klass.getName()};
              ServiceRegistration registration;
              registration = bundleContext.registerService(clazzes, declaration, props);
  
              declarationsRegistered.put(declaration, registration);
          }
      }
docs: Utility method to register an Declaration has a Service in OSGi.
  If you use it make sure to use unregisterDeclaration(...) to unregister the Declaration
  
  @param declaration the Declaration to register