Class ResourceConversions

java.lang.Object
io.wcm.caravan.rhyme.api.server.ResourceConversions

public final class ResourceConversions extends Object
Contains utility methods to perform conversions between resources that are semantically identical, but need some tweaks for the framework to properly handle them
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    asEmbeddedResource(T linkableResource)
    Create a proxy of a resource that also implements EmbeddableResource.
    static <T> T
    asEmbeddedResourceWithoutLink(T linkableResource)
    Create a proxy of a resource that also implements EmbeddableResource, with EmbeddableResource.isLinkedWhenEmbedded() returning false.
    static <T> T
    asLinkableResource(io.wcm.caravan.hal.resource.Link link, Class<T> halApiInterface)
    Create a proxy for the given interface that can only be used to create links to that resource.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • asEmbeddedResource

      public static <T> T asEmbeddedResource(T linkableResource)
      Create a proxy of a resource that also implements EmbeddableResource. This can be useful if you have fetched some resources from an upstream server, and want to embed them in your own output (and include links to the original resources).
      Type Parameters:
      T - the interface with the HalApiInterface annotation
      Parameters:
      linkableResource - a resource fetched with the HalApiClient, or a server-side resource implementation that does not implement EmbeddableResource
      Returns:
      a proxy instance that implements EmbeddableResource and all interfaces the given object implements
    • asEmbeddedResourceWithoutLink

      public static <T> T asEmbeddedResourceWithoutLink(T linkableResource)
      Create a proxy of a resource that also implements EmbeddableResource, with EmbeddableResource.isLinkedWhenEmbedded() returning false. This can be useful if you have fetched some resources from an upstream server, and want to embed them in your own output (but not include any links to those embedded resources).
      Type Parameters:
      T - the interface with the HalApiInterface annotation
      Parameters:
      linkableResource - a resource fetched with the HalApiClient, or a server-side resource implementation that does not implement EmbeddableResource
      Returns:
      a proxy instance that implements EmbeddableResource and all interfaces the given object implements
    • asLinkableResource

      public static <T> T asLinkableResource(io.wcm.caravan.hal.resource.Link link, Class<T> halApiInterface)
      Create a proxy for the given interface that can only be used to create links to that resource. This can be returned from server-side implementations of Related methods if it's not feasible to create a complete resource implementation, but you do have a Link pointing to a URI where a resource of the given interface can be retrieved.

      Note that calling any other method than LinkableResource.createLink() on the proxy will fail.

      Parameters:
      link - to be returned by LinkableResource.createLink()
      halApiInterface - the interface that should be implemented
      Returns:
      a proxy instance implementing LinkableResource on which you can only call LinkableResource.createLink()