Class EventTypeUpcaster

All Implemented Interfaces:
EventUpcaster, Upcaster<IntermediateEventRepresentation>

public class EventTypeUpcaster extends SingleEventUpcaster
A SingleEventUpcaster implementation which allows for type upcasting only. This could be used if the event's class name did not follow the desired naming convention or if an event's package name has been adjusted.

Note that this upcaster should not be used to change the semantic meaning of an event. Such a requirement points towards a new event type instead of adjusting an existing one.

Since:
4.3
Author:
Steven van Beelen
  • Constructor Details

    • EventTypeUpcaster

      public EventTypeUpcaster(String expectedPayloadType, String expectedRevision, String upcastedPayloadType, String upcastedRevision)
      Instantiate an EventTypeUpcaster using the given expected and upcasted payload types and revisions. Note that the payload type normally represents the fully qualified class name of the event to upcast.
      Parameters:
      expectedPayloadType - the expected event payload type this upcaster should react on
      expectedRevision - the expected event revision this upcaster should react on
      upcastedPayloadType - the event payload type to upcast towards
      upcastedRevision - the event revision to upcast towards
  • Method Details

    • from

      public static EventTypeUpcaster.Builder from(Class<?> payloadType, String revision)
      Instantiate a EventTypeUpcaster.Builder which should upcast "from" the given payloadType and revision. This method will use the fully qualified class name of the given payloadType as the expectedPayloadType.
      Parameters:
      payloadType - the payload type the upcaster should upcast "from"
      revision - the revision the upcaster should upcast "from"
      Returns:
      the current Builder instance, for fluent interfacing
    • from

      public static EventTypeUpcaster.Builder from(String payloadType, String revision)
      Instantiate a EventTypeUpcaster.Builder which should upcast "from" the given payloadType and revision.
      Parameters:
      payloadType - the payload type the upcaster should upcast "from"
      revision - the revision the upcaster should upcast "from"
      Returns:
      the current Builder instance, for fluent interfacing
    • canUpcast

      protected boolean canUpcast(IntermediateEventRepresentation intermediateRepresentation)
      Description copied from class: SingleEntryUpcaster
      Checks if this upcaster can upcast the given intermediateRepresentation. If the upcaster cannot upcast the representation the SingleEntryUpcaster.doUpcast(Object) is not invoked.
      Specified by:
      canUpcast in class SingleEntryUpcaster<IntermediateEventRepresentation>
      Parameters:
      intermediateRepresentation - the intermediate object representation to upcast
      Returns:
      true if the representation can be upcast, false otherwise
    • isExpectedPayloadType

      protected boolean isExpectedPayloadType(String payloadType)
      Check whether the given payloadType matches the outcome of expectedPayloadType.
      Parameters:
      payloadType - the event payload type received by this upcaster in the canUpcast(IntermediateEventRepresentation) method
      Returns:
      true if the given payloadType matches the result of expectedPayloadType, false otherwise
    • isExpectedRevision

      protected boolean isExpectedRevision(String revision)
      Check whether the given revision matches the outcome of expectedRevision.
      Parameters:
      revision - the event payload type received by this upcaster in the canUpcast(IntermediateEventRepresentation) method
      Returns:
      true if the given revision matches the result of expectedRevision, false otherwise
    • doUpcast

      protected IntermediateEventRepresentation doUpcast(IntermediateEventRepresentation intermediateRepresentation)
      Description copied from class: SingleEntryUpcaster
      Upcasts the given intermediateRepresentation. This method is only invoked if SingleEntryUpcaster.canUpcast(Object) returned true for the given representation.

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

      Specified by:
      doUpcast in class SingleEntryUpcaster<IntermediateEventRepresentation>
      Parameters:
      intermediateRepresentation - the representation of the object to upcast
      Returns:
      the upcasted representation
    • upcastedType

      protected SerializedType upcastedType()
      Retrieve the upcasted event SerializedType. Returns a SimpleSerializedType using upcastedPayloadType and upcastedRevision as constructor inputs
      Returns:
      the event SerializedType to upcast to