Package org.apache.juneau.swap
Class BuilderSwap<T,B>
java.lang.Object
org.apache.juneau.swap.BuilderSwap<T,B>
- Type Parameters:
T
- The bean class.B
- The builder class.
Specialized transform for builder classes.
See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
BuilderSwap
(Class<T> objectClass, Class<B> builderClass, Constructor<T> objectConstructor, Constructor<B> builderConstructor, MethodInfo createBuilderMethod, MethodInfo createObjectMethod) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbuild
(BeanSession session, B builder, ClassMeta<?> hint) Creates a new object from the specified builder.create
(BeanSession session, ClassMeta<?> hint) Creates a new builder object.static BuilderSwap<?,
?> findSwapFromBuilderClass
(Class<?> builderClass, Visibility cVis, Visibility mVis) Creates a BuilderSwap from the specified builder class if it qualifies as one.static BuilderSwap<?,
?> findSwapFromObjectClass
(BeanContext bc, Class<?> objectClass, Visibility cVis, Visibility mVis) Creates a BuilderSwap from the specified object class if it has one.The builder class.ClassMeta<?>
getBuilderClassMeta
(BeanSession session) Returns theClassMeta
of the transformed class type.The object class.
-
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
The object class.- Returns:
- The object class.
-
getBuilderClass
The builder class.- Returns:
- The builder class.
-
getBuilderClassMeta
Returns theClassMeta
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
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
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.
-