Class BuilderSwap<T,B>

java.lang.Object
org.apache.juneau.marshall.swap.spi.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. Can be null if the object is created via createObjectMethod instead.
      builderConstructor - The builder no-arg constructor. Can be null if the builder is created via createBuilderMethod instead.
      createBuilderMethod - The static create() method on the object class. Can be null if the builder is created via builderConstructor instead.
      createObjectMethod - The build() method on the builder class. Can be null if the object is created via objectConstructor instead.
  • Method Details

    • 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. Must not be null.
      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(MarshallingContext 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. Must not be null.
      objectClass - The object class to check. Must not be null.
      cVis - Minimum constructor visibility.
      mVis - Minimum method visibility.
      Returns:
      A new swap instance, or null if class didn't have a builder class.
    • build

      public T build(MarshallingSession 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.
    • create

      public B create(MarshallingSession 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.
    • 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. Must not be null on the first (uncached) call.
      Returns:
      The ClassMeta of the transformed class type.
    • getObjectClass

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