Class VarResolverSession

java.lang.Object
org.apache.juneau.svl.VarResolverSession

public class VarResolverSession extends Object
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 Details

    • VarResolverSession

      public VarResolverSession(VarResolver context, BeanStore beanStore)
      Constructor.
      Parameters:
      context - The VarResolver context object that contains the Vars and context objects associated with that resolver.
      beanStore - The bean store to use for resolving beans needed by vars.
  • Method Details

    • resolve

      public String resolve(String s)
      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.
      Returns null if the input was null.
    • resolve

      public <T> T resolve(T o)
      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

      public Writer resolveTo(String s, Writer out) throws IOException
      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

      public <T> Optional<T> getBean(Class<T> c)
      Returns the bean from the registered bean store.
      Type Parameters:
      T - The value type.
      Parameters:
      c - The bean type.
      Returns:
      The bean.
      Never null.
    • getVar

      protected Var getVar(String name)
      Returns the Var with the specified name.
      Parameters:
      name - The var name (e.g. "S").
      Returns:
      The Var instance, or null if no Var is associated with the specified name.
    • resolve

      public String[] resolve(String[] in)
      Resolves the specified strings in the string array.
      Parameters:
      in - The string array containing variables to resolve.
      Returns:
      An array with resolved strings.
    • bean

      public <T> VarResolverSession bean(Class<T> c, T value)
      Adds a bean to this session.
      Type Parameters:
      T - The bean type.
      Parameters:
      c - The bean type.
      value - The bean.
      Returns:
      This object.
    • toString

      public String toString()
      Overrides:
      toString in class Object