Annotation Type FactoryArgument


  • @Documented
    @Retention(RUNTIME)
    @Target({METHOD,ANNOTATION_TYPE})
    public @interface FactoryArgument
    When FluentAssembler DSL needs to create an aggregate (i.e. when the fromFactory() method is used), this annotation allows to specify a matching between a DTO getter and an argument of an aggregate factory method by position.

    Example 1: single aggregate

     public class CustomerDto {
        @FactoryArgument(index = 0)
         public String getName() {...}
    
        @FactoryArgument(index = 1)
         public Date getBirthDate() {...}
    
         // No need for annotation here as the address is not part of the factory method
         public Address getAddress() {...}
     }
    
     @Factory
      public class CustomerFactory {
          public Customer createCustomer(String name, Date birthDate);
      }
     

    Example 2: tuple of aggregates

     public class RecipeDto {
        @FactoryArgument(aggregateIndex = 0, index = 0)
         public String getCustomerName() {...}
    
        @FactoryArgument(aggregateIndex = 0, index = 1)
         public Date getCustomerBirthDate() {...}
    
        @FactoryArgument(aggregateIndex = 1, index = 0)
         public int getOrderId() {...}
     }
    
     @Factory
      public class CustomerFactory {
          Customer createCustomer(String name, Date birthDate);
      }
    
     @Factory
      public class OrderFactory {
          Customer createOrder(int orderId);
      }
     
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      int aggregateIndex
      Only used when assembling a tuple of aggregates.
      int index
      Specifies the position of the aggregate factory method argument the getter will match.
    • Element Detail

      • aggregateIndex

        int aggregateIndex
        Only used when assembling a tuple of aggregates. This specifies which aggregate in the tuple (by position) is concerned by the index() value.
        Returns:
        the concerned aggregate index in the tuple.
        Default:
        -1
      • index

        int index
        Specifies the position of the aggregate factory method argument the getter will match. The return value of the getter will be used as the value of the corresponding factory method argument.
        Returns:
        the index of the argument to match in the factory method.
        Default:
        -1