Class DefaultEntityHelper
java.lang.Object
io.fluxcapacitor.javaclient.modeling.DefaultEntityHelper
- All Implemented Interfaces:
EntityHelper
The
DefaultEntityHelper
provides the default implementation of the EntityHelper
interface.
It is responsible for orchestrating the behavior of domain model entities with respect to: - Intercepting messages
using @InterceptApply
handlers - Applying updates or events via @Apply
handlers - Validating updates
and asserting legal state transitions using @AssertLegal
handlers
This helper is heavily used during message handling and event sourcing to delegate message processing and validation logic to methods annotated on the entity class or its nested members.
The class supports efficient handler resolution through memoized lookups, enabling fast, repeatable application of complex domain behaviors.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static class
Decorates aDeserializingMessage
with an associated entity.protected static class
Wraps a message and its corresponding entity for use in interception or handler invocation. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultEntityHelper
(List<ParameterResolver<? super DeserializingMessage>> parameterResolvers, boolean disablePayloadValidation) Creates a new helper using the given parameter resolvers and configuration. -
Method Summary
Modifier and TypeMethodDescriptionapplyInvoker
(DeserializingMessage event, Entity<?> entity, boolean searchChildren) Finds a handler method annotated with@Apply
and wraps it to preserve apply context flags.<E extends Exception>
voidassertLegal
(Object value, Entity<?> entity) Performs a validation check using@AssertLegal
handlers for the provided payload.checkLegality
(Object value, Entity<?> entity) Returns an exception if the value is illegal for the current entity, orOptional.empty()
if legal.protected Optional
<HandlerInvoker> Recursively resolves the best-matching interceptor method, including nested members.static Aggregate
getRootAnnotation
(Class<?> type) Returns the cached or default @Aggregate annotation for a given type.Stream
<?> Intercepts the given value using@InterceptApply
methods defined on the entity.boolean
Convenience method that returnstrue
ifcheckLegality(java.lang.Object, io.fluxcapacitor.javaclient.modeling.Entity<?>)
yields no error.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.javaclient.modeling.EntityHelper
applyInvoker
-
Constructor Details
-
DefaultEntityHelper
public DefaultEntityHelper(List<ParameterResolver<? super DeserializingMessage>> parameterResolvers, boolean disablePayloadValidation) Creates a new helper using the given parameter resolvers and configuration.- Parameters:
parameterResolvers
- Resolvers used to inject values into annotated handler methodsdisablePayloadValidation
- If true, disables bean validation of payloads
-
-
Method Details
-
getRootAnnotation
Returns the cached or default @Aggregate annotation for a given type. -
intercept
Intercepts the given value using@InterceptApply
methods defined on the entity. Interceptors may transform or replace the original message.- Specified by:
intercept
in interfaceEntityHelper
- Parameters:
value
- the value to be intercepted, typically the payload of a messageentity
- the entity receiving the value- Returns:
- a stream of intercepted values or messages to be applied
-
getInterceptInvoker
Recursively resolves the best-matching interceptor method, including nested members. -
applyInvoker
public Optional<HandlerInvoker> applyInvoker(DeserializingMessage event, Entity<?> entity, boolean searchChildren) Finds a handler method annotated with@Apply
and wraps it to preserve apply context flags.- Specified by:
applyInvoker
in interfaceEntityHelper
- Parameters:
event
- the event to applyentity
- the root or intermediate entitysearchChildren
- whether to search nested child entities for applicable handlers- Returns:
- a handler invoker if a suitable method is located
-
assertLegal
Performs a validation check using@AssertLegal
handlers for the provided payload. This method is called both before and after the handler completes, depending on the annotation's settings.- Specified by:
assertLegal
in interfaceEntityHelper
- Type Parameters:
E
- the type of exception that may be thrown- Parameters:
value
- the value to validateentity
- the current entity state- Throws:
E
- if the value is deemed illegal
-
checkLegality
Returns an exception if the value is illegal for the current entity, orOptional.empty()
if legal.- Specified by:
checkLegality
in interfaceEntityHelper
- Type Parameters:
E
- the type of exception- Parameters:
value
- the value to validateentity
- the entity context- Returns:
- an exception if illegal, or an empty Optional if legal
-
isLegal
Convenience method that returnstrue
ifcheckLegality(java.lang.Object, io.fluxcapacitor.javaclient.modeling.Entity<?>)
yields no error.- Specified by:
isLegal
in interfaceEntityHelper
- Parameters:
value
- the value to checkentity
- the entity context- Returns:
- true if legal, false otherwise
-