/**
  * 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);
 }
 private void serializeValue(
     JsonSerializationContext context, JsonObject o, Collection<AttributeExp> values) {
   checkArgument(values != null && !values.isEmpty(), "Attribute value is mandatory.");
   AttributeExp firstValue = Iterables.getFirst(values, null);
   o.addProperty(DATA_TYPE_PROPERTY, firstValue.getType().getShortDataTypeId());
   Optional<TypeToGSon> toGson = TypeToGSon.Types.getIndex().get(firstValue.getType());
   checkState(toGson.isPresent());
   if (values.size() == 1) {
     o.add(VALUE_PROPERTY, toGson.get().toJson(firstValue, context));
     return;
   }
   JsonArray array = new JsonArray();
   for (AttributeExp a : values) {
     checkArgument(firstValue.getType().equals(a.getType()));
     array.add(toGson.get().toJson(a, context));
   }
   o.add(VALUE_PROPERTY, array);
 }