/**
  * Tries to locate resource id attribute
  *
  * @param result an evaluation result
  * @return a resource id attribute
  */
 private String getResourceId(Result result) {
   if (log.isDebugEnabled()) {
     log.debug("Mapping result=\"{}\" to resourceId", result);
   }
   Category resource = result.getAttribute(Categories.RESOURCE);
   if (resource == null) {
     return null;
   }
   Collection<Attribute> attrs = resource.getEntity().getAttributes(RESOURCE_ID);
   if (attrs.size() == 1) {
     Attribute resourceId = Iterables.getOnlyElement(attrs);
     AttributeExp v = Iterables.getOnlyElement(resourceId.getValues());
     Optional<TypeToString> toString = TypeToString.Types.getIndex().get(v.getType());
     Preconditions.checkState(toString.isPresent());
     return toString.get().toString(v);
   }
   Collection<AttributeExp> values =
       resource.getEntity().getAttributeValues(CONTENT_SELECTOR, XacmlTypes.XPATH);
   if (values.isEmpty() || values.size() > 1) {
     return null;
   }
   AttributeExp v = Iterables.getOnlyElement(values);
   Optional<TypeToString> toString = TypeToString.Types.getIndex().get(v.getType());
   Preconditions.checkState(toString.isPresent());
   return toString.get().toString(v);
 }
 @Override
 public JsonElement serialize(Attribute src, Type typeOfSrc, JsonSerializationContext context) {
   JsonObject o = new JsonObject();
   o.addProperty(ATTRIBUTE_ID_PROPERTY, src.getAttributeId());
   if (src.getIssuer() != null) {
     o.addProperty(ISSUER_PROPERTY, src.getIssuer());
   }
   Collection<AttributeExp> values = src.getValues();
   serializeValue(context, o, values);
   // OMIT property if value is "false"
   if (src.isIncludeInResult()) {
     o.addProperty(INCLUDE_IN_RESULT_PROPERTY, src.isIncludeInResult());
   }
   return o;
 }