Class BuilderSwap<T,B>

java.lang.Object
org.apache.juneau.swap.BuilderSwap<T,B>
Type Parameters:
T - The bean class.
B - The builder class.

public class BuilderSwap<T,B> extends Object
Specialized transform for builder classes.
See Also:
  • Constructor Details

    • BuilderSwap

      protected BuilderSwap(Class<T> objectClass, Class<B> builderClass, Constructor<T> objectConstructor, Constructor<B> builderConstructor, MethodInfo createBuilderMethod, MethodInfo createObjectMethod)
      Constructor.
      Parameters:
      objectClass - The object class created by the builder class.
      builderClass - The builder class.
      objectConstructor - The object constructor that takes in a builder as a parameter.
      builderConstructor - The builder no-arg constructor.
      createBuilderMethod - The static create() method on the object class.
      createObjectMethod - The build() method on the builder class.
  • Method Details

    • getObjectClass

      public Class<T> getObjectClass()
      The object class.
      Returns:
      The object class.
    • getBuilderClass

      public Class<B> getBuilderClass()
      The builder class.
      Returns:
      The builder class.
    • getBuilderClassMeta

      Returns the ClassMeta of the transformed class type.

      This value is cached for quick lookup.

      Parameters:
      session - The bean context to use to get the class meta. This is always going to be the same bean context that created this swap.
      Returns:
      The ClassMeta of the transformed class type.
    • create

      public B create(BeanSession session, ClassMeta<?> hint) throws ExecutableException
      Creates a new builder object.
      Parameters:
      session - The current bean session.
      hint - A hint about the class type.
      Returns:
      A new object.
      Throws:
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • build

      public T build(BeanSession session, B builder, ClassMeta<?> hint) throws ExecutableException
      Creates a new object from the specified builder.
      Parameters:
      session - The current bean session.
      builder - The object builder.
      hint - A hint about the class type.
      Returns:
      A new object.
      Throws:
      ExecutableException - Exception occurred on invoked constructor/method/field.
    • findSwapFromBuilderClass

      public static BuilderSwap<?,?> findSwapFromBuilderClass(Class<?> builderClass, Visibility cVis, Visibility mVis)
      Creates a BuilderSwap from the specified builder class if it qualifies as one.
      Parameters:
      builderClass - The potential builder class.
      cVis - Minimum constructor visibility.
      mVis - Minimum method visibility.
      Returns:
      A new swap instance, or null if class wasn't a builder class.
    • findSwapFromObjectClass

      public static BuilderSwap<?,?> findSwapFromObjectClass(BeanContext bc, Class<?> objectClass, Visibility cVis, Visibility mVis)
      Creates a BuilderSwap from the specified object class if it has one.
      Parameters:
      bc - The bean context to use to look up annotations.
      objectClass - The object class to check.
      cVis - Minimum constructor visibility.
      mVis - Minimum method visibility.
      Returns:
      A new swap instance, or null if class didn't have a builder class.