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,
boolean allowReuse)
Constructor for this class.
|
Modifier and Type | Method and Description |
---|---|
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. . |
String[] |
getCdlProperty(String key,
String def)
Returns a property as a parsed comma-delimited list of strings.
|
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,
ResourceResolver resolver,
Object... args)
Returns the specified property as an array of instantiated objects.
|
<T> T[] |
getInstanceArrayProperty(String key,
Object outer,
Class<T> type,
T[] def,
ResourceResolver resolver,
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,
ResourceResolver resolver,
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,
ResourceResolver resolver,
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. . |
String |
getStringPropertyWithNone(String key,
String def)
Same as
getStringProperty(String, String) but returns a blank instead of the default value if it resolves to |
int |
hashCode() |
int |
identityCode()
Returns a uniqueness identity code for this context.
|
ObjectMap |
toMap()
Returns the properties defined on this bean context as a simple map for debugging purposes.
|
String |
toString() |
public Context(PropertyStore ps, boolean allowReuse)
Subclasses MUST implement the same public constructor.
ps
- The read-only configuration for this context object.allowReuse
- If 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 String[] getCdlProperty(String key, String def)
key
- The property name.def
- The default value.public final String getStringPropertyWithNone(String key, String def)
getStringProperty(String, String)
but returns a blank instead of the default value if it resolves to 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.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.public final Set<Class<?>> getClassSetProperty(String key)
key
- The property name.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.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.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.public final List<Class<?>> getClassListProperty(String key)
key
- The property name.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.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.public final Map<String,Class<?>> getClassMapProperty(String key)
key
- The property name.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.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.
Class<? extends T>
, or public <T> T getInstanceProperty(String key, Class<T> type, Object def, ResourceResolver resolver, Object... args)
key
- The property name.type
- The class type of the property.def
- The default value if the property doesn't exist.
Class<? extends T>
.resolver
- The resolver to use for instantiating objects.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, ResourceResolver resolver, 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.
Class<? extends T>
.resolver
- The resolver to use for instantiating objects.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, ResourceResolver resolver, 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.resolver
- The resolver to use for instantiating objects.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, ResourceResolver resolver, 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.resolver
- The resolver to use for instantiating objects.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.public int identityCode()
Copyright © 2016–2019 The Apache Software Foundation. All rights reserved.