コード例 #1
0
  @Override
  public Entry getEntry(
      final ODataEntity entity, final Class<? extends Entry> reference, final boolean setType) {
    final Entry entry = ResourceFactory.newEntry(reference);
    entry.setType(entity.getName());

    // -------------------------------------------------------------
    // Add edit and self link
    // -------------------------------------------------------------
    final URI editLink = entity.getEditLink();
    if (editLink != null) {
      final LinkImpl entryEditLink = new LinkImpl();
      entryEditLink.setTitle(entity.getName());
      entryEditLink.setHref(editLink.toASCIIString());
      entryEditLink.setRel(Constants.EDIT_LINK_REL);
      entry.setEditLink(entryEditLink);
    }

    if (entity.isReadOnly()) {
      final LinkImpl entrySelfLink = new LinkImpl();
      entrySelfLink.setTitle(entity.getName());
      entrySelfLink.setHref(entity.getLink().toASCIIString());
      entrySelfLink.setRel(Constants.SELF_LINK_REL);
      entry.setSelfLink(entrySelfLink);
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append navigation links (handling inline entry / feed as well)
    // -------------------------------------------------------------
    // handle navigation links
    for (ODataLink link : entity.getNavigationLinks()) {
      // append link
      LOG.debug("Append navigation link\n{}", link);
      entry
          .getNavigationLinks()
          .add(
              getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append edit-media links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getEditMediaLinks()) {
      LOG.debug("Append edit-media link\n{}", link);
      entry
          .getMediaEditLinks()
          .add(
              getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
    }
    // -------------------------------------------------------------

    // -------------------------------------------------------------
    // Append association links
    // -------------------------------------------------------------
    for (ODataLink link : entity.getAssociationLinks()) {
      LOG.debug("Append association link\n{}", link);
      entry
          .getAssociationLinks()
          .add(
              getLink(link, ResourceFactory.formatForEntryClass(reference) == ODataPubFormat.ATOM));
    }
    // -------------------------------------------------------------

    if (entity.isMediaEntity()) {
      entry.setMediaContentSource(entity.getMediaContentSource());
      entry.setMediaContentType(entity.getMediaContentType());
    }

    for (ODataProperty property : entity.getProperties()) {
      entry.getProperties().add(getProperty(property, reference, setType));
    }

    return entry;
  }