Class Context.Builder
- Direct Known Subclasses:
- BeanContext.Builder,- BeanContextable.Builder,- Config.Builder,- ConfigStore.Builder,- RestContext.Builder,- RestOpContext.Builder
- Enclosing class:
- Context
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedBuilder()Constructor.protectedCopy constructor.protectedBuilder(Context.Builder copyFrom) Copy constructor.
- 
Method SummaryModifier and TypeMethodDescriptionannotations(Annotation... values) Defines annotations to apply to specific classes and methods.annotations(List<Annotation> values) Same asannotations(Annotation...)but uses a list as input.<T extends Context.Builder>
 Context.BuilderApply a consumer to this builder.apply(AnnotationWorkList work) Applies a set of applied to this builder.applyAnnotations(Class<?>... from) Same asapplyAnnotations(Object...)but explicitly specifies a class varargs to avoid compilation warnings.applyAnnotations(Object... from) Applies any of the various@XConfig annotations on the specified classes or methods to this context.build()Build the object.final <T extends Context>
 TConvenience method for callingbuild()while avoiding a cast.Specifies a cache to use for hashkey-based caching.booleancanApply(AnnotationWorkList work) Returnstrue if any of the annotations/appliers can be applied to this builder.abstract Context.Buildercopy()Copy creator.debug()Context configuration property: Debug mode.debug(boolean value) Same asdebug()but allows you to explicitly specify the value.Returns all the annotations that have been applied to this builder.getType()Returns the context class that this builder should create.hashKey()Returns the hashkey of this builder.Specifies a pre-instantiated bean for thebuild()method to return.booleanisDebug()Returnstrue if debug is enabled.protected voidregisterBuilders(Object... builders) Registers the specified secondary builders with this context builder.Associates a context class with this builder.
- 
Constructor Details- 
Builderprotected Builder()Constructor. Default settings.
- 
BuilderCopy constructor.- Parameters:
- copyFrom- The bean to copy from.
 
- 
BuilderCopy constructor.- Parameters:
- copyFrom- The builder to copy from.
 
 
- 
- 
Method Details- 
copyCopy creator.- Returns:
- A new mutable copy of this builder.
 
- 
buildBuild the object.- Returns:
- The built object.
 
- 
hashKeyReturns the hashkey of this builder.Used to return previously instantiated context beans that have matching hashkeys. The HashKeyobject is suitable for use as a hashmap key of a map of context beans. A context bean is considered equivalent if theHashKey.equals(Object)method is the same.- Returns:
- The hashkey of this builder.
 
- 
cacheSpecifies a cache to use for hashkey-based caching.- Parameters:
- value- The cache.
- Returns:
- This object.
 
- 
buildConvenience method for callingbuild()while avoiding a cast.- Type Parameters:
- T- The type to cast the built object to.
- Parameters:
- c- The type to cast the built object to.
- Returns:
- The built context bean.
 
- 
applyApply a consumer to this builder.- Type Parameters:
- T- The builder subtype that this consumer can be applied to.
- Parameters:
- subtype- The builder subtype that this consumer can be applied to.
- consumer- The consumer.
- Returns:
- This object.
 
- 
typeAssociates a context class with this builder.This is the type of object that this builder creates when the build()method is called.By default, it's the outer class of where the builder class is defined. - Parameters:
- value- The context class that this builder should create.
- Returns:
- This object.
 
- 
getTypeReturns the context class that this builder should create.- Returns:
- The context class if it was specified.
 
- 
implSpecifies a pre-instantiated bean for thebuild()method to return.- Parameters:
- value- The value for this setting.
- Returns:
- This object.
 
- 
canApplyReturnstrue if any of the annotations/appliers can be applied to this builder.- Parameters:
- work- The work to check.
- Returns:
- true if any of the annotations/appliers can be applied to this builder.
 
- 
applyApplies a set of applied to this builder.An AnnotationWorkconsists of a single pair ofAnnotationInfothat represents an annotation instance, andAnnotationApplierwhich represents the code used to apply the values in that annotation to a specific builder.Example:// A class annotated with a config annotation. @BeanConfig (sortProperties="$S{sortProperties,false}" )public class MyClass {...}// Find all annotations that themselves are annotated with @ContextPropertiesApply. AnnotationListannotations = ClassInfo.of (MyClass.class ).getAnnotationList(CONTEXT_APPLY_FILTER ); VarResolverSessionvrs = VarResolver.DEFAULT .createSession(); AnnotationWorkListwork = AnnotationWorkList.of(vrs ,annotations );// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .apply(work ) .build();- Parameters:
- work- The list of annotations and appliers to apply to this builder.
- Returns:
- This object.
 
- 
getAppliedReturns all the annotations that have been applied to this builder.- Returns:
- All the annotations that have been applied to this builder.
 
- 
registerBuildersRegisters the specified secondary builders with this context builder.When apply(AnnotationWorkList)is called, it gets called on all registered builders.- Parameters:
- builders- The builders to add to the list of builders.
 
- 
applyAnnotationsApplies any of the various@XConfig annotations on the specified classes or methods to this context.Any annotations found that themselves are annotated with ContextApplywill be resolved and applied as properties to this builder. These annotations include:- BeanConfig
- CsvConfig
- HtmlConfig
- HtmlDocConfig
- JsonConfig
- JsonSchemaConfig
- MsgPackConfig
- OpenApiConfig
- ParserConfig
- PlainTextConfig
- SerializerConfig
- SoapXmlConfig
- UonConfig
- UrlEncodingConfig
- XmlConfig
- RdfConfig 
 Annotations on classes are appended in the following order: - On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
 Annotations on methods are appended in the following order: - On the package of the method class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On the method class.
- On this method and matching methods ordered parent-to-child.
 The default var resolver VarResolver.DEFAULTis used to resolve any variables in annotation field values.Example:// A class annotated with a config annotation. @BeanConfig (sortProperties="$S{sortProperties,false}" )public class MyClass {...}// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .applyAnnotations(MyClass.class ) .build();// A method annotated with a config annotation. public class MyClass {@BeanConfig (sortProperties="$S{sortProperties,false}" )public void myMethod() {...} }// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .applyAnnotations(MyClass.class .getMethod("myMethod" )) .build();- Parameters:
- from- The classes or methods on which the annotations are defined. Can be any of the following types:- Class
- ClassInfo
- Method
- MethodInfo
- A collection/stream/array of anything on this list.
 
- Returns:
- This object.
 
- 
applyAnnotationsSame asapplyAnnotations(Object...)but explicitly specifies a class varargs to avoid compilation warnings.- Parameters:
- from- The classes or methods on which the annotations are defined.
- Returns:
- This object.
 
- 
annotationsDefines annotations to apply to specific classes and methods.Allows you to dynamically apply Juneau annotations typically applied directly to classes and methods. Useful in cases where you want to use the functionality of the annotation on beans and bean properties but do not have access to the code to do so. As a rule, any Juneau annotation with an on() method can be used with this setting.The following example shows the equivalent methods for applying the @Beanannotation:// Class with explicit annotation. @Bean (properties="street,city,state" )public class A {...}// Class with annotation applied via @BeanConfig public class B {...}// Java REST method with @BeanConfig annotation. @RestGet (...)@Bean (on="B" , properties="street,city,state" )public void doFoo() {...}In general, the underlying framework uses this method when it finds dynamically applied annotations on config annotations. However, concrete implementations of annotations are also provided that can be passed directly into builder classes like so: // Create a concrete @Bean annotation. Bean annotation = BeanAnnotation.create (B.class ).properties("street,city,state" ).build();// Apply it to a serializer. WriterSerializerserializer = JsonSerializer.create ().annotations(annotation ).build();// Serialize a bean with the dynamically applied annotation. Stringjson =serializer .serialize(new B());The following is the list of annotations builders provided that can be constructed and passed into the builder class: - BeanAnnotation
- BeancAnnotation
- BeanIgnoreAnnotation
- BeanpAnnotation
- ExampleAnnotation
- NamePropertyAnnotation
- ParentPropertyAnnotation
- SwapAnnotation
- UriAnnotation
- CsvAnnotation
- HtmlAnnotation
- JsonAnnotation
- SchemaAnnotation
- MsgPackAnnotation
- OpenApiAnnotation
- PlainTextAnnotation
- SoapXmlAnnotation
- UonAnnotation
- UrlEncodingAnnotation
- XmlAnnotation
 The syntax for the on() pattern match parameter depends on whether it applies to a class, method, field, or constructor. The valid pattern matches are:- Classes:
      - Fully qualified:
            - "com.foo.MyClass" 
 
- Fully qualified inner class:
            - "com.foo.MyClass$Inner1$Inner2" 
 
- Simple:
            - "MyClass" 
 
- Simple inner:
            - "MyClass$Inner1$Inner2" 
- "Inner1$Inner2" 
- "Inner2" 
 
 
- Fully qualified:
            
- Methods:
      - Fully qualified with args:
            - "com.foo.MyClass.myMethod(String,int)" 
- "com.foo.MyClass.myMethod(java.lang.String,int)" 
- "com.foo.MyClass.myMethod()" 
 
- Fully qualified:
            - "com.foo.MyClass.myMethod" 
 
- Simple with args:
            - "MyClass.myMethod(String,int)" 
- "MyClass.myMethod(java.lang.String,int)" 
- "MyClass.myMethod()" 
 
- Simple:
            - "MyClass.myMethod" 
 
- Simple inner class:
            - "MyClass$Inner1$Inner2.myMethod" 
- "Inner1$Inner2.myMethod" 
- "Inner2.myMethod" 
 
 
- Fully qualified with args:
            
- Fields:
      - Fully qualified:
            - "com.foo.MyClass.myField" 
 
- Simple:
            - "MyClass.myField" 
 
- Simple inner class:
            - "MyClass$Inner1$Inner2.myField" 
- "Inner1$Inner2.myField" 
- "Inner2.myField" 
 
 
- Fully qualified:
            
- Constructors:
      - Fully qualified with args:
            - "com.foo.MyClass(String,int)" 
- "com.foo.MyClass(java.lang.String,int)" 
- "com.foo.MyClass()" 
 
- Simple with args:
            - "MyClass(String,int)" 
- "MyClass(java.lang.String,int)" 
- "MyClass()" 
 
- Simple inner class:
            - "MyClass$Inner1$Inner2()" 
- "Inner1$Inner2()" 
- "Inner2()" 
 
 
- Fully qualified with args:
            
- A comma-delimited list of anything on this list.
 See Also:- Parameters:
- values- The annotations to register with the context.
- Returns:
- This object.
 
- 
annotationsSame asannotations(Annotation...)but uses a list as input.- Parameters:
- values- The annotations to register with the context.
- Returns:
- This object.
 
- 
debugContext configuration property: Debug mode.Enables the following additional information during serialization: - When bean getters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
- 
      Enables BeanTraverseContext.Builder.detectRecursions().
 Enables the following additional information during parsing: - When bean setters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
 Example:// Create a serializer with debug enabled. WriterSerializerserializer = JsonSerializer .create () .debug() .build();// Create a POJO model with a recursive loop. public class MyBean {public Objectf ; } MyBeanbean =new MyBean();bean .f =bean ;// Throws a SerializeException and not a StackOverflowError Stringjson =serializer .serialize(bean );See Also:- Returns:
- This object.
 
- 
debugSame asdebug()but allows you to explicitly specify the value.- Parameters:
- value- The value for this setting.
- Returns:
- This object.
 
- 
isDebugReturnstrue if debug is enabled.- Returns:
- true if debug is enabled.
 
 
-