class CapabilityDrivenAttributeMapTransformer extends AbstractAttributeMapTransformer {

   @SuppressWarnings({ "unchecked", "rawtypes" })
   @Override
   public AttributeMap transformToAttributeMap(Map<String, Object> attributes) {
      if(attributes == null) {
         return null;
      }

      AttributeMap attributeMap = AttributeMap.newMap();

      attributes.entrySet().forEach((entry) -> {
         NamespacedKey name = NamespacedKey.parse(entry.getKey());
         String attrName = name.getNamedRepresentation(); 
         Object attrValue = entry.getValue();

         CapabilityDefinition capability = getCapabilityDefinition(name);
         if(capability != null) {
            AttributeDefinition attrDef = capability.getAttributes().get(name.getNamedRepresentation());
            if(attrDef != null) {
               AttributeKey key = attrDef.getKey();
               try {
                  if(name.isInstanced()) {
                     attributeMap.set(key.instance(name.getInstance()), attrDef.getAttributeType().coerce(attrValue));
                  }
                  else {
                     attributeMap.set(key, attrDef.getAttributeType().coerce(attrValue));
                  }
               }
               catch(Exception e) {
                  throw new IllegalArgumentException("Invalid value: " +attrValue + " for attribute: " + key, e );
               }
            } else {
               LOGGER.warn("Dropping attribute {} = {} tranforming to an AttributeMap because no attribute is defined for it.", attrName, attrValue);
            }
         } else {
            LOGGER.warn("Dropping attribute {} = {} transforming to an AttributeMap because no capability is defined for it.", attrName, attrValue);
         }
      });

      return attributeMap;
   }

   @Inject public  CapabilityDrivenAttributeMapTransformer(CapabilityRegistry registry);

}