Simple Variable Language
The org.apache.juneau.svl
package defines an API for a language called "Simple Variable Language".
In a nutshell, Simple Variable Language (or SVL) is text that contains variables of the form
Variables can be recursively nested within the varKey (e.g.
The {@link org.apache.juneau.svl.VarResolver} class is used to resolve variables.
The {@link org.apache.juneau.svl.VarResolver#DEFAULT} resolver will resolve
The following shows how variables can be arbitrarily nested...
Variables are defined through the {@link org.apache.juneau.svl.Var} API.
The following shows the class hierarchy of the {@link org.apache.juneau.svl.Var} class and all current predefined implementations.
ConfigFileVar
- Resolves variables from a {@link org.apache.juneau.ini.ConfigFile} object.
The main class for performing variable resolution is {@link org.apache.juneau.svl.VarResolver}. Two methods are provided for resolving variables:
Var resolvers can have zero or more context objects associated with them.
Some {@link org.apache.juneau.svl.Var Vars} rely on the existence of some other object, such as an
{@link org.apache.juneau.utils.Args} object
for {@link org.apache.juneau.svl.vars.ArgsVar} or a {@link org.apache.juneau.ini.ConfigFile} for a
ConfigFileVar
.
These object dependencies are made by setting context objects on the var resolver.
Context objects are set through the {@link org.apache.juneau.svl.VarResolverBuilder #contextObject(String,Object)} method. They can be any class type.
Context objects are used by {@link org.apache.juneau.svl.Var Vars} by calling the {@link org.apache.juneau.svl.VarResolverSession#getSessionObject(Class, String)} method.
In addition to context objects, there are also session objects.
Session objects are considered more ephemeral than context objects.
While a context object is unlikely to ever change, a session object may change on every use of the var
resolver.
For example, the server API defines various Var
objects that use the RestRequest
object as a session object for the duration of a single HTTP request.
Session objects are used by calling the {@link org.apache.juneau.svl.VarResolver#createSession()} or
{@link org.apache.juneau.svl.VarResolver#createSession(Map)} methods to create an instance of a
{@link org.apache.juneau.svl.VarResolverSession} object that contains
{@link org.apache.juneau.svl.VarResolverSession#resolve(String)} and
{@link org.apache.juneau.svl.VarResolverSession#resolveTo(String,Writer)} methods that are identical to
{@link org.apache.juneau.svl.VarResolver#resolve(String)} and
{@link org.apache.juneau.svl.VarResolver#resolveTo(String, Writer)} except that the Var
objects
have access to the session objects through the
{@link org.apache.juneau.svl.VarResolverSession#getSessionObject(Class, String)} method.
Session objects are specified through either the {@link org.apache.juneau.svl.VarResolver#createSession(Map)}
method or the {@link org.apache.juneau.svl.VarResolverSession#sessionObject(String, Object)} methods.
Like Context object, Session objects are used by {@link org.apache.juneau.svl.Var Vars} by calling the {@link org.apache.juneau.svl.VarResolverSession#getSessionObject(Class, String)} method.
Var resolvers can be cloned and extended by using the {@link org.apache.juneau.svl.VarResolver#builder()} method. Cloning a resolver will copy it's {@link org.apache.juneau.svl.Var} class names and context objects.
$ , { }
'MYPROPERTY'
has the value '$E{MYPROPERTY}'
).
So don't do that!
resolver.resolve("foobar" )
) will simply be a no-op and return the same string.