Interface TemplateSet

All Known Subinterfaces:
ByteBufTemplateSet, LoginView.BytebufTemplateSet, LoginView.BytesTemplateSet, LoginView.StringTemplateSet, PublisherTemplateSet<T>
All Known Implementing Classes:
AbstractByteBufPublisherTemplateSet, AbstractByteBufTemplateSet, AbstractCompositeByteBufTemplateSet, AbstractStreamTemplateSet, AbstractStringPublisherTemplateSet, AbstractStringTemplateSet, AbstractTemplateSet

public interface TemplateSet

Template set definition which specifies the methods used in a generated template set implementation to render objects in a procedural or reactive way.

This interface is intended to be implemented by a template compiler generating an implementation based on a template set file following an appropriate grammar.

Such implementation must define template methods accepting zero or more parameters and returning a CompletableFuture which completes once input arguments are fully rendered to the output which is done using the generic methods specified in this interface.

As a result, depending on the implementation, data can be rendered in different ways as a string, an output stream or a stream of data which emits events each time new rendered data are generated.

Since:
1.2
Author:
Jeremy Kuhn
See Also:
  • Field Details

    • COMPLETED_FUTURE

      static final CompletableFuture<Void> COMPLETED_FUTURE
      An empty completed future which returns immediately.
  • Method Details

    • render

      CompletableFuture<Void> render(Object value)

      Renders an object to the output.

      This method might invoke specialized methods based on the actual type of the object. If no specific method is found the string representation of the object must be rendered.

      Parameters:
      value - the object to render
      Returns:
      a future which completes once the value is rendered
    • render

      CompletableFuture<Void> render(String value)

      Renders a string to the output.

      Parameters:
      value - the string to render
      Returns:
      a future which completes once the value is rendered
    • render

      CompletableFuture<Void> render(byte[] value)

      Renders a byte array to the output.

      Parameters:
      value - The byte array to render
      Returns:
      a future which completes once the value is rendered
    • applyTemplate

      <T> TemplateSet.Renderable<T> applyTemplate(T value)

      Invokes a template defined in the template set implementation on the specified object.

      Type Parameters:
      T - the type of the object
      Parameters:
      value - the value onto which template should be applied
      Returns:
      a renderable object which can invoke the template method matching the object type
    • applyTemplate

      <T> TemplateSet.IndexableRenderable<T> applyTemplate(T[] array)

      Invokes a template defined in the template set implementation on each element of the specified array.

      Elements are guaranteed to be rendered in sequence.

      Type Parameters:
      T - the type of the object
      Parameters:
      array - the array of elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type
    • applyTemplate

      <T> TemplateSet.IndexableRenderable<T> applyTemplate(Iterable<T> iterable)

      Invokes a template defined in the template set implementation on each element of the specified iterable.

      Elements are guaranteed to be rendered in sequence.

      Type Parameters:
      T - the type of the object
      Parameters:
      iterable - the iterable providing the elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type
    • applyTemplate

      <T> TemplateSet.IndexableRenderable<T> applyTemplate(Stream<T> stream)

      Invokes a template defined in the template set implementation on each element of the specified stream.

      Elements are guaranteed to be rendered in sequence.

      Type Parameters:
      T - the type of the object
      Parameters:
      stream - the stream of elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type
    • applyTemplate

      <T> TemplateSet.IndexableRenderable<T> applyTemplate(Publisher<T> publisher)

      Invokes a template defined in the template set implementation on each element emitted in the specified publisher until the publisher completes.

      Elements are guaranteed to be rendered in sequence.

      Type Parameters:
      T - the type of the object
      Parameters:
      publisher - the stream of elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type
    • template

      default CompletableFuture<Void> template(Object value)

      The root template method which basically invokes the render(Object) method.

      Parameters:
      value - the value onto which the template is applied
      Returns:
      a future which completes once the value is rendered