Package org.apache.juneau.svl
Class VarResolverSession
java.lang.Object
org.apache.juneau.svl.VarResolverSession
A var resolver session that combines a
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(BeanStore)
methods.
Notes:
- This class is not guaranteed to be thread safe.
See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdds a bean to this session.<T> Optional<T>
Returns the bean from the registered bean store.protected Var
Returns theVar
with the specified name.Resolve all variables in the specified string.String[]
Resolves the specified strings in the string array.<T> T
resolve
(T o) Convenience method for resolving variables in arbitrary objects.Resolves variables in the specified string and sends the output to the specified writer.toString()
-
Constructor Details
-
VarResolverSession
Constructor.- Parameters:
context
- TheVarResolver
context object that contains theVars
and context objects associated with that resolver.beanStore
- The bean store to use for resolving beans needed by vars.
-
-
Method Details
-
resolve
Resolve all variables in the specified string.- Parameters:
s
- The string to resolve variables in.- Returns:
- The new string with all variables resolved, or the same string if no variables were found.
Returnsnull if the input wasnull .
-
resolve
Convenience method for resolving variables in arbitrary objects.Supports resolving variables in the following object types:
CharSequence
- Arrays containing values of type
CharSequence
. - Collections containing values of type
CharSequence
.
Collection class must have a no-arg constructor. - Maps containing values of type
CharSequence
.
Map class must have a no-arg constructor.
- Type Parameters:
T
- The value type.- Parameters:
o
- The object.- Returns:
- The same object if no resolution was needed, otherwise a new object or data structure if resolution was needed.
-
resolveTo
Resolves variables in the specified string and sends the output to the specified writer.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.
- Parameters:
s
- The string to resolve variables in.out
- The writer to write to.- Returns:
- The same writer.
- Throws:
IOException
- Thrown by underlying stream.
-
getBean
Returns the bean from the registered bean store.- Type Parameters:
T
- The value type.- Parameters:
c
- The bean type.- Returns:
- The bean.
Nevernull .
-
getVar
Returns theVar
with the specified name.- Parameters:
name
- The var name (e.g."S" ).- Returns:
- The
Var
instance, ornull if noVar is associated with the specified name.
-
resolve
Resolves the specified strings in the string array.- Parameters:
in
- The string array containing variables to resolve.- Returns:
- An array with resolved strings.
-
bean
Adds a bean to this session.- Type Parameters:
T
- The bean type.- Parameters:
c
- The bean type.value
- The bean.- Returns:
- This object.
-
toString
-