private void writeEntityResource(
      StreamWriter writer,
      EntityResource<Entity> entityResource,
      String baseUri,
      String absoluteId,
      String updated) {
    Entity entity = null;
    try {
      entity = entityResource.getEntity();
    } catch (Exception e) {
      logger.error("Failed to get entity", e);
    }

    writer.startEntry();
    writeEntry(
        writer,
        entityResource.getEntityName(),
        entity,
        entityResource.getLinks(),
        entityResource.getEmbedded(),
        baseUri,
        absoluteId,
        updated);
    writer.endEntry();
  }
  public void write(
      UriInfo uriInfo,
      Writer w,
      String entityName,
      Entity entity,
      Collection<Link> links,
      Map<Transition, RESTResource> embeddedResources) {
    String baseUri = AtomXMLProvider.getBaseUri(serviceDocument, uriInfo);

    String absoluteId = getAbsoluteId(uriInfo, links);

    DateTime utc = new DateTime().withZone(DateTimeZone.UTC);
    String updated = InternalUtil.toString(utc);

    Abdera abdera = new Abdera();
    StreamWriter writer = abdera.newStreamWriter();
    writer.setOutputStream(new WriterOutputStream(w));
    writer.setAutoflush(false);
    writer.setAutoIndent(true);
    writer.startDocument();

    writer.startEntry();
    writer.writeNamespace("d", d);
    writer.writeNamespace("m", m);
    writer.writeAttribute("xml:base", baseUri);
    writeEntry(writer, entityName, entity, links, embeddedResources, baseUri, absoluteId, updated);
    writer.endEntry();
    writer.endDocument();
    writer.flush();
  }
  public void writeEntry(
      StreamWriter writer,
      String entitySetName,
      String entityName,
      Entity entity,
      Collection<Link> entityLinks,
      Map<Transition, RESTResource> embeddedResources,
      UriInfo uriInfo,
      String updated) {
    EntityMetadata entityMetadata = metadata.getEntityMetadata(entityName);
    String baseUri = AtomXMLProvider.getBaseUri(serviceDocument, uriInfo);
    String absoluteId = getAbsoluteId(baseUri, entitySetName, entity, entityMetadata);

    writer.startEntry();
    writeEntry(
        writer, entityName, entity, entityLinks, embeddedResources, baseUri, absoluteId, updated);
    writer.endEntry();
  }