Ejemplo n.º 1
0
  protected void writeLinkInline(
      XMLWriter2 writer,
      OLink linkToInline,
      String href,
      String baseUri,
      String updated,
      boolean isResponse) {

    writer.startElement(new QName2(m, "inline", "m"));
    if (linkToInline instanceof ORelatedEntitiesLinkInline) {
      ORelatedEntitiesLinkInline relLink = ((ORelatedEntitiesLinkInline) linkToInline);
      List<OEntity> entities = relLink.getRelatedEntities();

      if (entities != null && !entities.isEmpty()) {
        writer.startElement(new QName2("feed"));
        writeElement(writer, "title", linkToInline.getTitle(), "type", "text");

        writeElement(writer, "id", baseUri + href);
        writeElement(writer, "updated", updated);
        writeElement(
            writer, "link", null, "rel", "self", "title", linkToInline.getTitle(), "href", href);

        for (OEntity entity : ((ORelatedEntitiesLinkInline) linkToInline).getRelatedEntities()) {
          writer.startElement("entry");
          writeEntry(
              writer,
              entity,
              entity.getProperties(),
              entity.getLinks(),
              entity.getEntitySet().name,
              baseUri,
              updated,
              entity.getEntitySet(),
              isResponse);

          writer.endElement("entry");
        }
        writer.endElement("feed");
      }
    } else if (linkToInline instanceof ORelatedEntityLinkInline) {
      OEntity entity = ((ORelatedEntityLinkInline) linkToInline).getRelatedEntity();
      if (entity != null) {
        writer.startElement("entry");
        writeEntry(
            writer,
            entity,
            entity.getProperties(),
            entity.getLinks(),
            entity.getEntitySet().name,
            baseUri,
            updated,
            entity.getEntitySet(),
            isResponse);

        writer.endElement("entry");
      }
    } else throw new RuntimeException("Unknown OLink type " + linkToInline.getClass());
    writer.endElement("inline");
  }
Ejemplo n.º 2
0
 /*
  * Using the supplied EntityResource, add the embedded resources
  * from the OEntity embedded resources.  NB - only an OEntity can
  * carry OLinks.
  */
 public void addExpandedLinks(EntityResource<OEntity> entityResource) {
   RequestContext requestContext = RequestContext.getRequestContext();
   Collection<Link> links = entityResource.getLinks();
   if (links != null) {
     OEntity oentity = entityResource.getEntity();
     List<OLink> olinks = oentity.getLinks();
     for (OLink olink : olinks) {
       if (olink.isInline()) {
         String relid = InternalUtil.getEntityRelId(oentity);
         String href = relid + "/" + olink.getTitle();
         for (Link link : links) {
           String linkHref = link.getHref();
           if (requestContext != null) {
             // Extract the transition fragment from the URI path
             linkHref = link.getRelativeHref(getBaseUri(serviceDocument, uriInfo));
           }
           if (href.equals(linkHref)) {
             if (entityResource.getEmbedded() == null) {
               entityResource.setEmbedded(new HashMap<Transition, RESTResource>());
             }
             if (olink.isCollection()) {
               List<OEntity> oentities = olink.getRelatedEntities();
               Collection<EntityResource<OEntity>> entityResources =
                   new ArrayList<EntityResource<OEntity>>();
               for (OEntity oe : oentities) {
                 entityResources.add(new EntityResource<OEntity>(oe));
               }
               entityResource
                   .getEmbedded()
                   .put(link.getTransition(), new CollectionResource<OEntity>(entityResources));
             } else {
               // replace the OLink's on the current entity
               OEntity inlineOentity = olink.getRelatedEntity();
               List<OLink> inlineResourceOlinks =
                   formOLinks(new EntityResource<OEntity>(inlineOentity));
               OEntity newInlineOentity =
                   OEntities.create(
                       inlineOentity.getEntitySet(),
                       inlineOentity.getEntityKey(),
                       inlineOentity.getProperties(),
                       inlineResourceOlinks);
               entityResource
                   .getEmbedded()
                   .put(link.getTransition(), new EntityResource<OEntity>(newInlineOentity));
             }
           }
         }
       }
     }
   }
 }