public abstract class Context extends Object
Session
objects.
Contexts are created through the ContextBuilder.build()
method (and subclasses of ContextBuilder
).
Subclasses MUST implement the following constructor:
Besides that restriction, a context object can do anything you desire.
However, it MUST be thread-safe and all fields should be declared final to prevent modification.
It should NOT be used for storing temporary or state information.
PropertyStore
Constructor and Description |
---|
Context(PropertyStore ps)
Constructor for this class.
|
Modifier and Type | Method and Description |
---|---|
ObjectMap |
asMap()
Returns the properties defined on this bean context as a simple map for debugging purposes.
|
ContextBuilder |
builder()
Creates a builder from this context object.
|
abstract SessionArgs |
createDefaultSessionArgs()
Defines default session arguments used when calling the
createSession() method. |
Session |
createSession()
Create a new bean session based on the properties defined on this context.
|
abstract Session |
createSession(SessionArgs args)
Create a new session based on the properties defined on this context combined with the specified
runtime args.
|
boolean |
equals(Object o) |
<T> T[] |
getArrayProperty(String key,
Class<T> eType)
Returns the array property value with the specified name.
|
<T> T[] |
getArrayProperty(String key,
Class<T> eType,
T[] def)
Returns the array property value with the specified name.
|
Boolean |
getBooleanProperty(String key,
Boolean def)
Shortcut for calling
getProperty(key, Boolean. . |
Class<?>[] |
getClassArrayProperty(String key)
Returns the class array property with the specified name.
|
Class<?>[] |
getClassArrayProperty(String key,
Class<?>[] def)
Returns the class array property with the specified name.
|
<T> Class<T>[] |
getClassArrayProperty(String key,
Class<T> eType)
Returns the class array property with the specified name.
|
List<Class<?>> |
getClassListProperty(String key)
Returns the class list property with the specified name.
|
<T> List<Class<T>> |
getClassListProperty(String key,
Class<T> eType)
Returns the class list property with the specified name.
|
Map<String,Class<?>> |
getClassMapProperty(String key)
Returns the class map property with the specified name.
|
<T> Map<String,Class<T>> |
getClassMapProperty(String key,
Class<T> eType)
Returns the class map property with the specified name.
|
<T> Class<? extends T> |
getClassProperty(String key,
Class<T> type,
Class<? extends T> def)
Returns the class property with the specified name.
|
Set<Class<?>> |
getClassSetProperty(String key)
Returns the class set property with the specified name.
|
<T> Set<Class<T>> |
getClassSetProperty(String key,
Class<T> eType)
Returns the class set property with the specified name.
|
<T> T[] |
getInstanceArrayProperty(String key,
Class<T> type,
T[] def)
Returns the specified property as an array of instantiated objects.
|
<T> T[] |
getInstanceArrayProperty(String key,
Class<T> type,
T[] def,
boolean fuzzyArgs,
Object... args)
Returns the specified property as an array of instantiated objects.
|
<T> T[] |
getInstanceArrayProperty(String key,
Object outer,
Class<T> type,
T[] def,
boolean fuzzyArgs,
Object... args)
Returns the specified property as an array of instantiated objects.
|
<T> T |
getInstanceProperty(String key,
Class<T> type,
Object def)
Returns an instance of the specified class, string, or object property.
|
<T> T |
getInstanceProperty(String key,
Class<T> type,
Object def,
boolean fuzzyArgs,
Object... args)
Returns an instance of the specified class, string, or object property.
|
<T> T |
getInstanceProperty(String key,
Object outer,
Class<T> type,
Object def,
boolean fuzzyArgs,
Object... args)
Returns an instance of the specified class, string, or object property.
|
Integer |
getIntegerProperty(String key,
Integer def)
Shortcut for calling
getProperty(key, Integer. . |
<T> List<T> |
getListProperty(String key,
Class<T> eType)
Returns the list property with the specified name.
|
<T> List<T> |
getListProperty(String key,
Class<T> eType,
List<T> def)
Returns the list property with the specified name.
|
Long |
getLongProperty(String key,
Long def)
Shortcut for calling
getProperty(key, Long. . |
<T> Map<String,T> |
getMapProperty(String key,
Class<T> eType)
Returns the map property with the specified name.
|
Object |
getProperty(String key)
Returns the raw property value with the specified name.
|
<T> T |
getProperty(String key,
Class<T> c,
T def)
Returns the property value with the specified name.
|
Set<String> |
getPropertyKeys(String group)
Returns the keys found in the specified property group.
|
PropertyStore |
getPropertyStore()
Returns the property store associated with this context.
|
<T> Set<T> |
getSetProperty(String key,
Class<T> eType)
Returns the set property with the specified name.
|
<T> Set<T> |
getSetProperty(String key,
Class<T> eType,
Set<T> def)
Returns the set property with the specified name.
|
String |
getStringProperty(String key,
String def)
Shortcut for calling
getProperty(key, String. . |
int |
hashCode() |
String |
toString() |
public Context(PropertyStore ps)
Subclasses MUST implement the same public constructor.
ps
- The read-only configuration for this context object.public Object getProperty(String key)
key
- The property name.public final <T> T getProperty(String key, Class<T> c, T def)
key
- The property name.c
- The class to cast or convert the value to.def
- The default value.public final Boolean getBooleanProperty(String key, Boolean def)
getProperty(key, Boolean.class , def)
.key
- The property name.def
- The default value.public final Integer getIntegerProperty(String key, Integer def)
getProperty(key, Integer.class , def)
.key
- The property name.def
- The default value.public final Long getLongProperty(String key, Long def)
getProperty(key, Long.class , def)
.key
- The property name.def
- The default value.public final String getStringProperty(String key, String def)
getProperty(key, String.class , def)
.key
- The property name.def
- The default value.public final <T> Class<? extends T> getClassProperty(String key, Class<T> type, Class<? extends T> def)
key
- The property name.type
- The class type of the property.def
- The default value.public final <T> T[] getArrayProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.public final <T> T[] getArrayProperty(String key, Class<T> eType, T[] def)
key
- The property name.eType
- The class type of the elements in the property.def
- The default value.public final Class<?>[] getClassArrayProperty(String key)
key
- The property name.public final Class<?>[] getClassArrayProperty(String key, Class<?>[] def)
key
- The property name.def
- The default value.public final <T> Class<T>[] getClassArrayProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.public final <T> Set<T> getSetProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashSet
, or an empty set if it doesn't exist.public final <T> Set<T> getSetProperty(String key, Class<T> eType, Set<T> def)
key
- The property name.eType
- The class type of the elements in the property.def
- The default value if the property doesn't exist or is empty.LinkedHashSet
, or the default value if it doesn't exist or is empty.public final Set<Class<?>> getClassSetProperty(String key)
key
- The property name.LinkedHashSet
, or an empty set if it doesn't exist.public final <T> Set<Class<T>> getClassSetProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashSet
, or an empty set if it doesn't exist.public final <T> List<T> getListProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.ArrayList
, or an empty list if it doesn't exist.public final <T> List<T> getListProperty(String key, Class<T> eType, List<T> def)
key
- The property name.eType
- The class type of the elements in the property.def
- The default value if the property doesn't exist or is empty.ArrayList
, or the default value if it doesn't exist or is empty.public final List<Class<?>> getClassListProperty(String key)
key
- The property name.ArrayList
, or an empty list if it doesn't exist.public final <T> List<Class<T>> getClassListProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.ArrayList
, or an empty list if it doesn't exist.public final <T> Map<String,T> getMapProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashMap
, or an empty map if it doesn't exist.public final Map<String,Class<?>> getClassMapProperty(String key)
key
- The property name.LinkedHashMap
, or an empty map if it doesn't exist.public final <T> Map<String,Class<T>> getClassMapProperty(String key, Class<T> eType)
key
- The property name.eType
- The class type of the elements in the property.LinkedHashMap
, or an empty map if it doesn't exist.public <T> T getInstanceProperty(String key, Class<T> type, Object def)
If instantiating a class, assumes the class has a no-arg constructor. Otherwise, throws a runtime exception.
key
- The property name.type
- The class type of the property.def
- The default value if the property doesn't exist.
T
, or a Class<? extends T>
, or public <T> T getInstanceProperty(String key, Class<T> type, Object def, boolean fuzzyArgs, Object... args)
key
- The property name.type
- The class type of the property.def
- The default value if the property doesn't exist.
T
, or a Class<? extends T>
.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public <T> T getInstanceProperty(String key, Object outer, Class<T> type, Object def, boolean fuzzyArgs, Object... args)
key
- The property name.outer
- The outer object if the class we're instantiating is an inner class.type
- The class type of the property.def
- The default value if the property doesn't exist.
T
, or a Class<? extends T>
.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public <T> T[] getInstanceArrayProperty(String key, Class<T> type, T[] def)
key
- The property name.type
- The class type of the property.def
- The default object to return if the property doesn't exist.public <T> T[] getInstanceArrayProperty(String key, Class<T> type, T[] def, boolean fuzzyArgs, Object... args)
key
- The property name.type
- The class type of the property.def
- The default object to return if the property doesn't exist.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public <T> T[] getInstanceArrayProperty(String key, Object outer, Class<T> type, T[] def, boolean fuzzyArgs, Object... args)
key
- The property name.outer
- The outer object if the class we're instantiating is an inner class.type
- The class type of the property.def
- The default object to return if the property doesn't exist.fuzzyArgs
- Use fuzzy constructor arg matching.
args
- Arguments to pass to the constructor.
Constructors matching the arguments are always used before no-arg constructors.public Set<String> getPropertyKeys(String group)
The keys are NOT prefixed with group names.
group
- The group name.@BeanIgnore public final PropertyStore getPropertyStore()
public ContextBuilder builder()
Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
public Session createSession()
Use this method for creating sessions if you don't need to override any properties or locale/timezone currently set on this context.
public abstract Session createSession(SessionArgs args)
Use this method for creating sessions if you don't need to override any properties or locale/timezone currently set on this context.
args
- The session arguments.public abstract SessionArgs createDefaultSessionArgs()
createSession()
method.@BeanIgnore public ObjectMap asMap()
Copyright © 2018 Apache. All rights reserved.