public abstract class ContextBuilder extends Object
Modifier | Constructor and Description |
---|---|
|
ContextBuilder()
Constructor.
|
|
ContextBuilder(PropertyStore ps)
Constructor that takes in an initial set of configuration properties.
|
protected |
ContextBuilder(PropertyStoreBuilder psb)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
ContextBuilder |
add(Map<String,Object> properties)
Adds multiple free-form configuration properties on this object without first clearing out any previous values.
|
ContextBuilder |
addTo(String name,
Object value)
Adds a free-form value to a SET property.
|
ContextBuilder |
appendTo(String name,
Object value)
Adds a free-form value to the end of a LIST property.
|
ContextBuilder |
apply(PropertyStore copyFrom)
Copies the settings from the specified property store into this builder.
|
ContextBuilder |
applyAnnotations(AnnotationList al,
VarResolverSession r)
Applies a set of annotations to this property store.
|
ContextBuilder |
applyAnnotations(Class<?>... fromClasses)
Applies any of the various
|
ContextBuilder |
applyAnnotations(Method... fromMethods)
Applies any of the various
|
abstract Context |
build()
Build the object.
|
<T extends Context> |
build(Class<T> c)
Build a new instance of the specified object.
|
ContextBuilder |
debug()
|
PropertyStore |
getPropertyStore()
Returns a read-only snapshot of the current property store on this builder.
|
protected PropertyStoreBuilder |
getPropertyStoreBuilder()
Returns access to the inner property store builder.
|
ContextBuilder |
locale(Locale value)
|
ContextBuilder |
mediaType(MediaType value)
|
<T> T |
peek(Class<T> c,
String key)
Peeks at a configuration property on this object.
|
Object |
peek(String key)
Peeks at a free-form configuration property on this object.
|
ContextBuilder |
prependTo(String name,
Object value)
Adds a free-form value to the beginning of a LIST property.
|
ContextBuilder |
putAllTo(String name,
Object value)
Adds or overwrites multiple free-form entries in a MAP property.
|
ContextBuilder |
putTo(String name,
String key,
Object value)
Adds or overwrites a free-form entry in a MAP property.
|
ContextBuilder |
removeFrom(String name,
Object value)
Removes a free-form value from a SET, LIST, or MAP property.
|
ContextBuilder |
set(Map<String,Object> properties)
Sets multiple free-form configuration properties on this object replacing all previous values.
|
ContextBuilder |
set(String name,
Object value)
Sets a free-form configuration property on this object.
|
ContextBuilder |
timeZone(TimeZone value)
|
public ContextBuilder()
public ContextBuilder(PropertyStore ps)
ps
- The initial configuration settings for this builder.protected ContextBuilder(PropertyStoreBuilder psb)
Used in cases where multiple context builder are sharing the same property store builder.
(e.g.
psb
- The property store builder to use.protected PropertyStoreBuilder getPropertyStoreBuilder()
Used in conjunction with ContextBuilder(PropertyStoreBuilder)
when builders share property store builders.
public abstract Context build()
public ContextBuilder apply(PropertyStore copyFrom)
copyFrom
- The property store whose settings are being copied.public ContextBuilder applyAnnotations(AnnotationList al, VarResolverSession r)
The AnnotationList
object is an ordered list of annotations and the classes/methods/packages they were found on.
al
- The list of all annotations annotated with PropertyStoreApply
.r
- The string resolver for resolving variables in annotation values.public ContextBuilder applyAnnotations(Class<?>... fromClasses)
Any annotations found that themselves are annotated with PropertyStoreApply
will be resolved and
applied as properties to this builder. These annotations include:
BeanConfig
CsvConfig
HtmlConfig
HtmlDocConfig
JsoConfig
JsonConfig
JsonSchemaConfig
MsgPackConfig
OpenApiConfig
ParserConfig
PlainTextConfig
SerializerConfig
SoapXmlConfig
UonConfig
UrlEncodingConfig
XmlConfig
Annotations on classes are appended in the following order:
The default var resolver VarResolver.DEFAULT
is used to resolve any variables in annotation field values.
fromClasses
- The classes on which the annotations are defined.public ContextBuilder applyAnnotations(Method... fromMethods)
Any annotations found that themselves are annotated with PropertyStoreApply
will be resolved and
applied as properties to this builder. These annotations include:
BeanConfig
CsvConfig
HtmlConfig
HtmlDocConfig
JsoConfig
JsonConfig
JsonSchemaConfig
MsgPackConfig
OpenApiConfig
ParserConfig
PlainTextConfig
SerializerConfig
SoapXmlConfig
UonConfig
UrlEncodingConfig
XmlConfig
Annotations on methods are appended in the following order:
The default var resolver VarResolver.DEFAULT
is used to resolve any variables in annotation field values.
fromMethods
- The methods on which the annotations are defined.public <T extends Context> T build(Class<T> c)
Creates a new instance of the specified context-based class, or an existing instance if one with the equivalent property store was already created.
c
- The subclass of Context
to instantiate.public PropertyStore getPropertyStore()
public ContextBuilder debug()
Enables the following additional information during serialization:
BeanTraverseContext.BEANTRAVERSE_detectRecursions
.
Enables the following additional information during parsing:
public ContextBuilder locale(Locale value)
Specifies the default locale for serializer and parser sessions when not specified via SessionArgs.locale(Locale)
.
Typically used for POJO swaps that need to deal with locales such as swaps that convert PojoSwap.swap(BeanSession, Object)
and
PojoSwap.unswap(BeanSession, Object, ClassMeta, String)
methods.
value
- The new value for this property.public ContextBuilder mediaType(MediaType value)
Specifies the default media type for serializer and parser sessions when not specified via SessionArgs.mediaType(MediaType)
.
Typically used for POJO swaps that need to serialize the same POJO classes differently depending on
the specific requested media type. For example, a swap could handle a request for media types
value
- The new value for this property.public ContextBuilder timeZone(TimeZone value)
Specifies the default time zone for serializer and parser sessions when not specified via SessionArgs.timeZone(TimeZone)
.
Typically used for POJO swaps that need to deal with timezones such as swaps that convert PojoSwap.swap(BeanSession, Object)
and
PojoSwap.unswap(BeanSession, Object, ClassMeta, String)
methods.
value
- The new value for this property.public ContextBuilder set(String name, Object value)
Provides the ability to specify configuration property values in a generic fashion.
Property names must have the following format that identify their datatype...
...where the parts consist of the following...
For example,
Property values get 'normalized' when they get set.
For example, calling PropertyStore
class to be comparable
and useful in determining whether a cached instance of a context object can be returned.
As a general rule, builders don't typically have "unsetter" methods. For example, once you've set strict
mode on the
name
- The property name.value
- The property value.
public Object peek(String key)
Allows you to look at the raw value of a configuration property while it's still in the builder.
key
- The property name.public <T> T peek(Class<T> c, String key)
Allows you to look at the raw value of a configuration property while it's still in the builder.
Converts the value from the current raw form into the specified data type.
T
- The type to convert to.c
- The type to convert to.key
- The property name.public ContextBuilder set(Map<String,Object> properties)
Identical in function to set(String, Object)
but allows you to specify multiple values at once.
properties
- The properties to set on this class.
public ContextBuilder add(Map<String,Object> properties)
Identical in function to set(String, Object)
but allows you to specify multiple values at once.
properties
- The properties to set on this class.
public ContextBuilder addTo(String name, Object value)
SET properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_notBeanClasses
property which has the value
name
- The property name.value
- The new value to add to the SET property.
ConfigException
- If property is not a SET property.public ContextBuilder appendTo(String name, Object value)
LIST properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_swaps
property which has the value
name
- The property name.value
- The new value to add to the LIST property.
ConfigException
- If property is not a LIST property.public ContextBuilder prependTo(String name, Object value)
LIST properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_swaps
property which has the value
name
- The property name.value
- The new value to add to the LIST property.
ConfigException
- If property is not a LIST property.public ContextBuilder putTo(String name, String key, Object value)
MAP properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_implClasses
property which has the value
name
- The property name.key
- The property value map key.value
- The property value map value.
ConfigException
- If property is not a MAP property.public ContextBuilder putAllTo(String name, Object value)
MAP properties are those properties with one of the following type parts:
For example, the BeanContext.BEAN_implClasses
property which has the value
name
- The property name.value
- Either a JSON Object string or a Map
whose valid value types depend on the property type:
ConfigException
- If property is not a MAP property.public ContextBuilder removeFrom(String name, Object value)
name
- The property name.value
- The property value in the SET/LIST/MAP property.ConfigException
- If property is not a SET/LIST/MAP property.Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.