Klasse HalWrapper<HalWrapperT extends HalWrapper<? extends HalWrapperT>>

java.lang.Object
de.kamillionlabs.hateoflux.model.hal.HalWrapper<HalWrapperT>
Typparameter:
HalWrapperT - the implementation that is extending HalWrapper
Bekannte direkte Unterklassen:
HalEmbeddedWrapper, HalListWrapper, HalResourceWrapper

public abstract class HalWrapper<HalWrapperT extends HalWrapper<? extends HalWrapperT>> extends Object
Abstract base class for HAL wrappers, providing essential functionality for managing hypermedia links according to HAL (Hypertext Application Language) standards. This class facilitates the inclusion and handling of hypermedia links, crucial for API navigability.

HalWrapper includes utility functions to manage hypermedia links. These functions allow subclasses to add, and retrieve links, supporting structured implementation of HAL responses.

Subclasses are responsible for specific data implementations (e.g., resources, lists, pagination), using this class's link management capabilities.

  • Felddetails

  • Konstruktordetails

    • HalWrapper

      protected HalWrapper()
      Creates empty HalWrapper
  • Methodendetails

    • getLinks

      public List<Link> getLinks()
      Get the list of links of the wrapped resource(s).
      Gibt zurück:
      the list of links of the wrapped resource(s).
    • getLink

      public Optional<Link> getLink(IanaRelation relation)
      Get a specific link of the links of the wrapped resource(s).
      Parameter:
      relation - Relation with which the link to retrieve is identified
      Gibt zurück:
      Found link
    • getLink

      public Optional<Link> getLink(String relation)
      Get a specific link of the links of the wrapped resource(s).
      Parameter:
      relation - Relation with which the link to retrieve is identified
      Gibt zurück:
      Found link
    • getRequiredLink

      public Link getRequiredLink(IanaRelation relation)
      Get a specific link of the links of the wrapped resource(s). In contrast to getLink(IanaRelation), this method assumes, that the link with the provided relation exists. Otherwise, an exception is thrown.
      Parameter:
      relation - Relation with which the link to retrieve is identified
      Gibt zurück:
      Found link
    • getRequiredLink

      public Link getRequiredLink(String relation)
      Get a specific link of the links of the wrapped resource(s). In contrast to getLink(IanaRelation), this method assumes, that the link with the provided relation exists. Otherwise, an exception is thrown.
      Parameter:
      relation - Relation with which the link to retrieve is identified
      Gibt zurück:
      Found link
    • withLinks

      public HalWrapperT withLinks(@Nullable Link... links)
      Adds Links to the currently wrapped resource.
      Parameter:
      links - links to add
      Gibt zurück:
      New wrapper with the added links
    • withLinks

      public HalWrapperT withLinks(@Nullable Iterable<Link> links)
      Adds Links to the currently wrapped resource.
      Parameter:
      links - links to add
      Gibt zurück:
      New wrapper with the added links
    • add

      protected void add(@NonNull Iterable<Link> links)
      Adds links to the HalWrapper. The list is not allowed to be null. The links in it must be fully specified with a href and a relation.
      Parameter:
      links - links to add
      Löst aus:
      IllegalArgumentException - if:
      • list is null
      • Containing links that
      • Containing links that are null or empty
      • Containing links that have no href
      • Containing links that have no link relation
    • add

      protected void add(@NonNull Link link)
      Adds links to the HalWrapper. The list is not allowed to be null. The links in it must be fully specified with a href and a relation.
      Parameter:
      link - link to add
      Löst aus:
      IllegalArgumentException - if:
      • link is null or empty
      • link has no href
      • link has no link relation
    • determineCollectionRelationName

      protected static String determineCollectionRelationName(Class<?> clazz)
      Determines the collection name based on Relation annotation or using a default naming strategy.
      Parameter:
      clazz - the resource class
      Gibt zurück:
      the name to use for the collection
    • determineResourceRelationName

      protected static String determineResourceRelationName(Class<?> clazz)
      Determines the resource name based on Relation annotation or using a default naming strategy.
      Parameter:
      clazz - the resource class
      Gibt zurück:
      the name to use for the resource
    • determineRelationNameForObject

      protected static String determineRelationNameForObject(Object object)
      Determines the appropriate relation name for a given object based on its type. This method classifies the object as either a collection or a single resource. If the object is an instance of Iterable, it is treated as a collection, otherwise, it is treated as a single resource. The relation name is derived based on the Relation annotation if present, or through a default naming convention otherwise.

      The method returns a name that is used to represent the relationship of the object in hypermedia-driven outputs:

      • For collections: The pluralized form of the class name in camelCase or name in Relation.
      • For single a resource: The class name in camelCase or name in Relation.
      Parameter:
      object - The object for which to determine the relation name, must not be null (collections also not empty).
      Gibt zurück:
      The relation name for the object, suitable for use in generating hypermedia links.
      Löst aus:
      IllegalArgumentException - If the object is null or empty.
    • isScalar

      protected static boolean isScalar(Class<?> clazz)