public class VarResolverSession extends Object
VarResolver
with one or more session objects.
Instances of this class are considered light-weight and fast to construct, use, and discard.
This class contains the workhorse code for var resolution.
Instances of this class are created through the VarResolver.createSession()
and
VarResolver.createSession(Map)
methods.
Instances of this class are NOT guaranteed to be thread safe.
Constructor and Description |
---|
VarResolverSession(VarResolverContext context,
Map<String,Object> sessionObjects)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
getSessionObject(Class<T> c,
String name)
Returns the session object with the specified name.
|
protected Var |
getVar(String name)
Returns the
Var with the specified name. |
String |
resolve(String s)
Resolve all variables in the specified string.
|
<T> T |
resolve(T o)
Convenience method for resolving variables in arbitrary objects.
|
Writer |
resolveTo(String s,
Writer out)
Resolves variables in the specified string and sends the output to the specified writer.
|
VarResolverSession |
sessionObject(String name,
Object o)
Adds a session object to this session.
|
public VarResolverSession(VarResolverContext context, Map<String,Object> sessionObjects)
context
- The VarResolver
context object that contains the Vars
and context objects associated with
that resolver.sessionObjects
- The session objects.public VarResolverSession sessionObject(String name, Object o)
name
- The name of the session object.o
- The session object.public String resolve(String s)
s
- The string to resolve variables in.public <T> T resolve(T o)
Supports resolving variables in the following object types:
CharSequence
CharSequence
.
CharSequence
.
CharSequence
.
o
- The object.public Writer resolveTo(String s, Writer out) throws IOException
More efficient than first parsing to a string and then serializing to the writer since this method doesn't need to construct a large string.
s
- The string to resolve variables in.out
- The writer to write to.IOException
public <T> T getSessionObject(Class<T> c, String name)
Casts it to the specified class type for you.
c
- The class type to cast to.name
- The name of the session object.RuntimeException
- If session object with specified name does not exist.Copyright © 2018 Apache. All rights reserved.