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 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: EntityChildModelDefinition
      Inspect the given member, which is declared on the given parentClass for the presence of a child entity according to this definition. If a child entity is found, an EntityChildMetamodel is returned. This metamodel can use the given metamodelFactory to create the child EntityMetamodel based on the class.
      Specified by:
      createChildDefinition in interface EntityChildModelDefinition
      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 child EntityMetamodel based on the class.
      member - The member to inspect for a child entity.
      Returns:
      An Optional that resolves to an EntityChildMetamodel if the field represents a child entity, or an empty optional if no child entity is found.
    • isMemberTypeSupported

      protected abstract boolean isMemberTypeSupported(@Nonnull Class<?> memberType)
      Check if the given member type supports this definition. Returning true from this method implies that the getChildTypeFromMember(Member) and doCreate(Class, EntityMetamodel, String, EventTargetMatcher, CommandTargetResolver) methods will be called.
      Parameters:
      memberType - The type of the member to check.
      Returns:
      Should return true if the member type is supported, false otherwise.
    • getChildTypeFromMember

      protected abstract Class<?> getChildTypeFromMember(@Nonnull Member member)
      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 child EntityMetamodel using the AnnotatedEntityMetamodelFactory supplied 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 new EntityChildMetamodel for the given parent class and child metamodel. This method will be called if the isMemberTypeSupported(Class) returns true for 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 - The EntityMetamodel to 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 - The EventTargetMatcher to use for the child entity.
      commandTargetResolver - The CommandTargetResolver to use for the child entity.
      Returns:
      A new EntityChildMetamodel for the given parent class and child metamodel.