public abstract class Session extends Object
Serializers and parsers use session objects to retrieve config properties and to use it as a scratchpad during serialize and parse actions.
Modifier | Constructor and Description |
---|---|
protected |
Session(Context ctx,
SessionArgs args)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addToCache(Map<String,Object> cacheObjects)
Adds arbitrary objects to this session's cache.
|
void |
addToCache(String key,
Object val)
Adds an arbitrary object to this session's cache.
|
void |
addWarning(String msg,
Object... args)
Logs a warning message.
|
void |
checkForWarnings()
Throws a
BeanRuntimeException if any warnings occurred in this session. |
<T> Class<? extends T> |
getClassProperty(String key,
Class<T> type,
Class<? extends T> def)
Returns the session class property with the specified name.
|
<T> T |
getFromCache(Class<T> c,
String key)
Returns an object stored in the session cache.
|
<T> T[] |
getInstanceArrayProperty(String key,
Class<T> type,
T[] def)
Returns the specified property as an array of instantiated objects.
|
<T> T |
getInstanceProperty(String key,
Class<T> type,
Object def)
Returns an instantiation of the specified class property.
|
Locale |
getLocale()
Configuration property: Locale.
|
MediaType |
getMediaType()
Configuration property: Media type.
|
protected OMap |
getProperties()
Returns the session properties.
|
Object |
getProperty(String key)
Returns the session property with the specified key.
|
<T> T |
getProperty(String key,
Class<T> type,
T... def)
Same as
getProperty(String, Class, Object) but allows for more than one default value. |
<T> T |
getProperty(String key,
Class<T> type,
T def)
Returns the session property with the specified key and type.
|
Set<String> |
getPropertyKeys()
Returns the session property keys.
|
TimeZone |
getTimeZone()
Configuration property: Time zone.
|
ZoneId |
getTimeZoneId()
Configuration property: Time zone.
|
List<String> |
getWarnings()
Returns the warnings that occurred in this session.
|
boolean |
hasProperty(String key)
Returns
|
boolean |
hasWarnings()
Returns
|
boolean |
isDebug()
Configuration property: Debug mode.
|
OMap |
toMap()
Returns the properties defined on this bean context as a simple map for debugging purposes.
|
String |
toString() |
protected Session(Context ctx, SessionArgs args)
ctx
- The context object.args
- Runtime arguments.public final boolean hasProperty(String key)
key
- The property key.public final Object getProperty(String key)
The returned type is the raw value of the property.
key
- The property key.public final <T> T getProperty(String key, Class<T> type, T def)
key
- The property key.type
- The type to convert the property to.def
- The default value if the session property does not exist or is @SafeVarargs public final <T> T getProperty(String key, Class<T> type, T... def)
getProperty(String, Class, Object)
but allows for more than one default value.key
- The property key.type
- The type to convert the property to.def
- The default values if the session property does not exist or is 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 <T> T getInstanceProperty(String key, Class<T> type, Object def)
key
- The property name.type
- The class type of the property.def
- The default instance or class to instantiate if the property doesn't exist.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.protected OMap getProperties()
public Set<String> getPropertyKeys()
public final void addToCache(String key, Object val)
Can be used to store objects for reuse during a session.
key
- The key. Can be any string.val
- The cached object.public final void addToCache(Map<String,Object> cacheObjects)
Can be used to store objects for reuse during a session.
cacheObjects
- The objects to add to this session's cache.
No-op if public final <T> T getFromCache(Class<T> c, String key)
c
- The class type of the object.key
- The session object key.public void addWarning(String msg, Object... args)
msg
- The warning message.args
- Optional MessageFormat
-style arguments.public final boolean hasWarnings()
public final List<String> getWarnings()
public void checkForWarnings()
BeanRuntimeException
if any warnings occurred in this session.public boolean isDebug()
Context.CONTEXT_debug
public Locale getLocale()
The locale is determined in the following order:
Context.CONTEXT_locale
entry in parameter passed in through constructor.
Context.CONTEXT_locale
setting on bean context.
Locale.getDefault()
.
Context.CONTEXT_locale
public final MediaType getMediaType()
For example,
Context.CONTEXT_mediaType
public final TimeZone getTimeZone()
The timezone is determined in the following order:
Context.CONTEXT_timeZone
entry in parameter passed in through constructor.
Context.CONTEXT_timeZone
setting on bean context.
Context.CONTEXT_timeZone
public final ZoneId getTimeZoneId()
The timezone is determined in the following order:
Context.CONTEXT_timeZone
entry in parameter passed in through constructor.
Context.CONTEXT_timeZone
setting on bean context.
Context.CONTEXT_timeZone
public OMap toMap()
Copyright © 2016–2020 The Apache Software Foundation. All rights reserved.