Class AbstractEntityChildModelDefinition
java.lang.Object
org.axonframework.modelling.entity.annotation.AbstractEntityChildModelDefinition
- All Implemented Interfaces:
EntityChildModelDefinition
- Direct Known Subclasses:
ListEntityChildModelDefinition,SingleEntityChildModelDefinition
@Internal
public abstract class AbstractEntityChildModelDefinition
extends Object
implements EntityChildModelDefinition
Abstract implementation of the
EntityChildModelDefinition interface that makes concrete implementations
easier to maintain. It constructs the necessary definitions from the EntityMember annotation, determines the
field name based on the member and calls the
doCreate(Class, EntityMetamodel, String, EventTargetMatcher, CommandTargetResolver) method to
create the actual EntityChildMetamodel.
Implementors define what kind of fields they support by implementing the isMemberTypeSupported(Class)
method. If this method returns true, the getChildTypeFromMember(Member) will be called to determine
the child type (which may be a generic argument, such as when using a List as a field type). Then, the
doCreate(Class, EntityMetamodel, String, EventTargetMatcher, CommandTargetResolver) methods will be
called with all information needed to create the child metamodel.
Before version 5.0.0, this class was known as the
org.axonframework.modelling.command.inspection.AbstractChildEntityDefinition.
- Since:
- 3.1.0
- Author:
- Steven van Beelen, Mitchell Herrijgers
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<C,P> Optional <EntityChildMetamodel<C, P>> createChildDefinition(Class<P> parentClass, AnnotatedEntityMetamodelFactory metamodelFactory, Member member) Inspect the givenmember, which is declared on the givenparentClassfor the presence of a child entity according to this definition.protected abstract <C,P> EntityChildMetamodel <C, P> doCreate(Class<P> parentClass, EntityMetamodel<C> entityMetamodel, String fieldName, EventTargetMatcher<C> eventTargetMatcher, CommandTargetResolver<C> commandTargetResolver) Creates a newEntityChildMetamodelfor the given parent class and child metamodel.protected abstract Class<?> getChildTypeFromMember(Member member) Returns the actual child type.protected abstract booleanisMemberTypeSupported(Class<?> memberType) Check if the given member type supports this definition.
-
Constructor Details
-
AbstractEntityChildModelDefinition
public AbstractEntityChildModelDefinition()
-
-
Method Details
-
createChildDefinition
@Nonnull public <C,P> Optional<EntityChildMetamodel<C,P>> createChildDefinition(@Nonnull Class<P> parentClass, @Nonnull AnnotatedEntityMetamodelFactory metamodelFactory, @Nonnull Member member) Description copied from interface:EntityChildModelDefinitionInspect the givenmember, which is declared on the givenparentClassfor the presence of a child entity according to this definition. If a child entity is found, anEntityChildMetamodelis returned. This metamodel can use the givenmetamodelFactoryto create the childEntityMetamodelbased on the class.- Specified by:
createChildDefinitionin interfaceEntityChildModelDefinition- Type Parameters:
C- The type of the child entity.P- The type of the parent entity.- Parameters:
parentClass- The class of the parent entity.metamodelFactory- A factory to create the childEntityMetamodelbased on the class.member- The member to inspect for a child entity.- Returns:
- An
Optionalthat resolves to anEntityChildMetamodelif the field represents a child entity, or an empty optional if no child entity is found.
-
isMemberTypeSupported
Check if the given member type supports this definition. Returningtruefrom this method implies that thegetChildTypeFromMember(Member)anddoCreate(Class, EntityMetamodel, String, EventTargetMatcher, CommandTargetResolver)methods will be called.- Parameters:
memberType- The type of the member to check.- Returns:
- Should return
trueif the member type is supported,falseotherwise.
-
getChildTypeFromMember
Returns the actual child type. If it needs to be retrieved from a generic, this method should do so. This is used to construct the childEntityMetamodelusing theAnnotatedEntityMetamodelFactorysupplied by the parent entity metamodel.- Parameters:
member- The member to retrieve the child type from.- Returns:
- The child type.
-
doCreate
@Nonnull protected abstract <C,P> EntityChildMetamodel<C,P> doCreate(@Nonnull Class<P> parentClass, @Nonnull EntityMetamodel<C> entityMetamodel, @Nonnull String fieldName, @Nonnull EventTargetMatcher<C> eventTargetMatcher, @Nonnull CommandTargetResolver<C> commandTargetResolver) Creates a newEntityChildMetamodelfor the given parent class and child metamodel. This method will be called if theisMemberTypeSupported(Class)returnstruefor the given member type.- Type Parameters:
C- The type of the child entity.P- The type of the parent entity.- Parameters:
parentClass- The class of the parent entity.entityMetamodel- TheEntityMetamodelto use for the child entity.fieldName- The name of the field to use for the child entity. If the member is a field, this will be the field name. If it is a method, the supposed field name will be the method name without the "get", "set" or "is" prefix and starting with a lowercase character.eventTargetMatcher- TheEventTargetMatcherto use for the child entity.commandTargetResolver- TheCommandTargetResolverto use for the child entity.- Returns:
- A new
EntityChildMetamodelfor the given parent class and child metamodel.
-