Class DefaultEntityHelper
java.lang.Object
io.fluxzero.sdk.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 classDecorates aDeserializingMessagewith an associated entity.protected static classWraps 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@Applyand wraps it to preserve apply context flags.<E extends Exception>
voidassertLegal(Object value, Entity<?> entity) Performs a validation check using@AssertLegalhandlers 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 AggregategetRootAnnotation(Class<?> type) Returns the cached or default @Aggregate annotation for a given type.Stream<?> Intercepts the given value using@InterceptApplymethods defined on the entity.booleanConvenience method that returnstrueifcheckLegality(Object, Entity)yields no error.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface 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
-
intercept
Intercepts the given value using@InterceptApplymethods defined on the entity. Interceptors may transform or replace the original message.- Specified by:
interceptin 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@Applyand wraps it to preserve apply context flags.- Specified by:
applyInvokerin 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@AssertLegalhandlers for the provided payload. This method is called both before and after the handler completes, depending on the annotation's settings.- Specified by:
assertLegalin 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:
checkLegalityin 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 returnstrueifcheckLegality(Object, Entity)yields no error.- Specified by:
isLegalin interfaceEntityHelper- Parameters:
value- the value to checkentity- the entity context- Returns:
- true if legal, false otherwise
-