Class ContextAwareSingleEntryUpcaster<T,C>

java.lang.Object
org.axonframework.serialization.upcasting.ContextAwareSingleEntryUpcaster<T,C>
Type Parameters:
T - the type of entry to be upcasted as T
C - the type of context used as C
All Implemented Interfaces:
Upcaster<T>
Direct Known Subclasses:
ContextAwareSingleEventUpcaster

public abstract class ContextAwareSingleEntryUpcaster<T,C> extends Object implements Upcaster<T>
Abstract implementation of an Upcaster that eases the common process of upcasting one intermediate representation to another representation by applying a simple mapping function to the input stream of intermediate representations. Additionally, it's a context aware implementation, which enables it to store and reuse context information from one entry to another during upcasting.
Since:
3.1
Author:
Steven van Beelen
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract C
    Builds a context of generic type C to be used when processing the stream of intermediate object representations T.
    protected abstract boolean
    canUpcast(T intermediateRepresentation, C context)
    Checks if this upcaster can upcast the given intermediateRepresentation.
    protected abstract T
    doUpcast(T intermediateRepresentation, C context)
    Upcasts the given intermediateRepresentation.
    upcast(Stream<T> intermediateRepresentations)
    Apply this upcaster to a stream of intermediateRepresentations and return the altered stream.

    Methods inherited from class java.lang.Object

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

    • ContextAwareSingleEntryUpcaster

      public ContextAwareSingleEntryUpcaster()
  • Method Details

    • upcast

      public Stream<T> upcast(Stream<T> intermediateRepresentations)
      Description copied from interface: Upcaster
      Apply this upcaster to a stream of intermediateRepresentations and return the altered stream.

      To upcast an object an upcaster should apply a mapping function to the input stream (Stream.map(java.util.function.Function)). To remove an object from the stream the upcaster should filter the input stream (Stream.filter(java.util.function.Predicate)). To split an input object into more than one objects use Stream.flatMap(java.util.function.Function).

      In some cases the upcasting result of an Upcaster may depend on more than one input object. In that case an Upcaster may store state in the method during upcasting or even read ahead in the stream.

      Specified by:
      upcast in interface Upcaster<T>
      Parameters:
      intermediateRepresentations - The input stream of representations of objects
      Returns:
      the output stream of representations after applying the upcast function
    • canUpcast

      protected abstract boolean canUpcast(T intermediateRepresentation, C context)
      Checks if this upcaster can upcast the given intermediateRepresentation. If the upcaster cannot upcast the representation the doUpcast(Object, Object) is not invoked. The context can be used to store or retrieve entry specific information required to make the canUpcast(Object, Object) check.
      Parameters:
      intermediateRepresentation - the intermediate object representation to upcast as T
      context - the context for this upcaster as C
      Returns:
      true if the representation can be upcast, false otherwise
    • doUpcast

      protected abstract T doUpcast(T intermediateRepresentation, C context)
      Upcasts the given intermediateRepresentation. This method is only invoked if canUpcast(Object, Object) returned true for the given representation. The context can be used to store or retrieve entry specific information required to perform the upcasting process.

      Note that the returned representation should not be null. To remove an intermediateRepresentation add a filter to the input stream.

      Parameters:
      intermediateRepresentation - the representation of the object to upcast as T
      context - the context for this upcaster as C
      Returns:
      the upcasted representation
    • buildContext

      protected abstract C buildContext()
      Builds a context of generic type C to be used when processing the stream of intermediate object representations T.
      Returns:
      a context of generic type C