private static String createEntryKey(
      final EntityInfoAggregator entityInfo, final Map<String, Object> data)
      throws EntityProviderException {
    final List<EntityPropertyInfo> keyPropertyInfos = entityInfo.getKeyPropertyInfos();

    StringBuilder keys = new StringBuilder();
    for (final EntityPropertyInfo keyPropertyInfo : keyPropertyInfos) {
      if (keys.length() > 0) {
        keys.append(',');
      }

      final String name = keyPropertyInfo.getName();
      if (keyPropertyInfos.size() > 1) {
        keys.append(Encoder.encode(name)).append('=');
      }

      final EdmSimpleType type = (EdmSimpleType) keyPropertyInfo.getType();
      try {
        keys.append(
            Encoder.encode(
                type.valueToString(
                    data.get(name), EdmLiteralKind.URI, keyPropertyInfo.getFacets())));
      } catch (final EdmSimpleTypeException e) {
        throw new EntityProviderException(EntityProviderException.COMMON, e);
      }
    }

    return keys.toString();
  }
  private void appendAtomMandatoryParts(
      final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data)
      throws EntityProviderException {
    try {
      writer.writeStartElement(FormatXml.ATOM_ID);
      location = properties.getServiceRoot().toASCIIString() + createSelfLink(eia, data, null);
      writer.writeCharacters(location);
      writer.writeEndElement();

      writer.writeStartElement(FormatXml.ATOM_TITLE);
      writer.writeAttribute(FormatXml.ATOM_TYPE, FormatXml.ATOM_TEXT);
      EntityPropertyInfo titleInfo = eia.getTargetPathInfo(EdmTargetPath.SYNDICATION_TITLE);
      if (titleInfo != null) {
        EdmSimpleType st = (EdmSimpleType) titleInfo.getType();
        Object object = data.get(titleInfo.getName());
        String title = st.valueToString(object, EdmLiteralKind.DEFAULT, titleInfo.getFacets());
        if (title != null) {
          writer.writeCharacters(title);
        }
      } else {
        writer.writeCharacters(eia.getEntitySetName());
      }
      writer.writeEndElement();

      writer.writeStartElement(FormatXml.ATOM_UPDATED);

      writer.writeCharacters(getUpdatedString(eia, data));

      writer.writeEndElement();
    } catch (XMLStreamException e) {
      throw new EntityProviderException(EntityProviderException.COMMON, e);
    } catch (EdmSimpleTypeException e) {
      throw new EntityProviderException(EntityProviderException.COMMON, e);
    }
  }
 protected static void appendPropertyValue(
     final JsonStreamWriter jsonStreamWriter,
     final EntityPropertyInfo propertyInfo,
     final Object value)
     throws IOException, EdmException, EntityProviderException {
   if (propertyInfo.isComplex()) {
     if (value == null || value instanceof Map<?, ?>) {
       jsonStreamWriter.beginObject();
       appendPropertyMetadata(jsonStreamWriter, propertyInfo.getType());
       for (final EntityPropertyInfo childPropertyInfo :
           ((EntityComplexPropertyInfo) propertyInfo).getPropertyInfos()) {
         jsonStreamWriter.separator();
         final String name = childPropertyInfo.getName();
         jsonStreamWriter.name(name);
         appendPropertyValue(
             jsonStreamWriter,
             childPropertyInfo,
             value == null ? null : ((Map<?, ?>) value).get(name));
       }
       jsonStreamWriter.endObject();
     } else {
       throw new EntityProviderException(
           EntityProviderException.ILLEGAL_ARGUMENT.addContent(
               "A complex property must have a Map as data"));
     }
   } else {
     final EdmSimpleType type = (EdmSimpleType) propertyInfo.getType();
     final Object contentValue =
         value instanceof Map ? ((Map<?, ?>) value).get(propertyInfo.getName()) : value;
     final String valueAsString =
         type.valueToString(contentValue, EdmLiteralKind.JSON, propertyInfo.getFacets());
     switch (EdmSimpleTypeKind.valueOf(type.getName())) {
       case String:
         jsonStreamWriter.stringValue(valueAsString);
         break;
       case Boolean:
       case Byte:
       case SByte:
       case Int16:
       case Int32:
         jsonStreamWriter.unquotedValue(valueAsString);
         break;
       case DateTime:
       case DateTimeOffset:
         // Although JSON escaping is (and should be) done in the JSON
         // serializer, we backslash-escape the forward slash here explicitly
         // because it is not required to escape it in JSON but in OData.
         jsonStreamWriter.stringValueRaw(
             valueAsString == null ? null : valueAsString.replace("/", "\\/"));
         break;
       default:
         jsonStreamWriter.stringValueRaw(valueAsString);
         break;
     }
   }
 }
 private String getTargetPathValue(
     final EntityInfoAggregator eia, final String targetPath, final Map<String, Object> data)
     throws EntityProviderException {
   try {
     EntityPropertyInfo info = eia.getTargetPathInfo(targetPath);
     if (info != null) {
       EdmSimpleType type = (EdmSimpleType) info.getType();
       Object value = data.get(info.getName());
       return type.valueToString(value, EdmLiteralKind.DEFAULT, info.getFacets());
     }
     return null;
   } catch (EdmSimpleTypeException e) {
     throw new EntityProviderException(EntityProviderException.COMMON, e);
   }
 }
  protected static String createETag(final EntityInfoAggregator eia, final Map<String, Object> data)
      throws EntityProviderException {
    try {
      String etag = null;

      Collection<EntityPropertyInfo> propertyInfos = eia.getETagPropertyInfos();
      for (EntityPropertyInfo propertyInfo : propertyInfos) {
        EdmType edmType = propertyInfo.getType();
        if (edmType instanceof EdmSimpleType) {
          EdmSimpleType edmSimpleType = (EdmSimpleType) edmType;
          if (etag == null) {
            etag =
                edmSimpleType.valueToString(
                    data.get(propertyInfo.getName()),
                    EdmLiteralKind.DEFAULT,
                    propertyInfo.getFacets());
          } else {
            etag =
                etag
                    + Edm.DELIMITER
                    + edmSimpleType.valueToString(
                        data.get(propertyInfo.getName()),
                        EdmLiteralKind.DEFAULT,
                        propertyInfo.getFacets());
          }
        }
      }

      if (etag != null) {
        etag = "W/\"" + etag + "\"";
      }

      return etag;
    } catch (EdmSimpleTypeException e) {
      throw new EntityProviderException(EntityProviderException.COMMON, e);
    }
  }