Class ConfigVar


public class ConfigVar extends DefaultingVar
Config file variable resolver.

The format for this var is "$C{key[,defaultValue]}". See Config.get(String) for the format of the key.

This variable resolver requires that a Config bean be available in the resolver session bean factory.

Example:

// Create a config object. Config config = Config.create().name("MyConfig.cfg").build(); // Create a variable resolver that resolves config file entries (e.g. "$C{MySection/myKey}") VarResolver resolver = VarResolver .create() .vars(ConfigVar.class) .bean(Config.class, config) .build(); // Use it! System.out.println(resolver.resolve("Value for myKey in section MySection is $C{MySection/myKey}"));

Since this is a SimpleVar, any variables contained in the result will be recursively resolved. Likewise, if the arguments contain any variables, those will be resolved before they are passed to this var.

See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • resolve

      public String resolve(VarResolverSession session, String key)
      Description copied from class: Var
      The interface that needs to be implemented for subclasses of SimpleVar.
      Specified by:
      resolve in class Var
      Parameters:
      session - The session object used for a single instance of a var resolution.
      key - The inside argument of the variable.
      Returns:
      The resolved value.
    • canResolve

      public boolean canResolve(VarResolverSession session)
      Description copied from class: Var
      Returns true if this variable can be resolved in the specified session.

      For example, some variable cannot resolve unless specific context or session objects are available.

      Overrides:
      canResolve in class Var
      Parameters:
      session - The current session.
      Returns:
      true if this variable can be resolved in the specified session.