VarResolvers and VarResolverSessions
The main class for performing variable resolution is {@link oaj.svl.VarResolver}.
Two methods are provided for resolving variables:
- {@link oaj.svl.VarResolver}
- {@link oaj.svl.VarResolver#resolve(String) resolve(String)}
- Resolves variables and returns the results as a simple string.
- {@link oaj.svl.VarResolver#resolveTo(String,Writer) resolveTo(String,Writer)}
- Resolves variables and sends results to a writer.
Var resolvers can rely on the existence of other objects.
For example, {@link oaj.config.vars.ConfigVar} relies on the existence of a {@link oaj.config.Config}.
This is accomplished through the following:
- Context-objects - Objects set on the resolver.
- Session-objects - Objects set on the resolver session.
The following two classes are identical in behavior except for which objects they can access:
- {@link oaj.svl.VarResolver} - Has access to context objects only.
- {@link oaj.svl.VarResolverSession} - Has access to context and session objects.
Context and session objects are set through the following methods:
- {@link oaj.svl.VarResolverBuilder#contextObject(String,Object)} - Context objects.
- {@link oaj.svl.VarResolverSession#sessionObject(String,Object)} - Session objects.
- {@link oaj.svl.VarResolver#createSession(Map)} - Session objects.
Both kinds of objects are accessible through the following method:
- {@link oaj.svl.VarResolverSession#getSessionObject(Class, String, boolean)}
Var resolvers can be cloned and extended by using the {@link oaj.svl.VarResolver#builder()} method.
Cloning a resolver will copy it's {@link oaj.svl.Var} class names and context objects.
// Create a resolver that copies the default resolver and adds $C and $A vars.
VarResolver myVarResolver = VarResolver.DEFAULT
.builder()
.vars(ConfigVar.class, ArgsVar.class)
.build();