Class Expression


  • public final class Expression
    extends Object
    A compiled property-expansion expression string. An expression string is a mix of plain strings and expression segments, which are wrapped by the sequence "${ ... }".
    • Method Detail

      • getReferencedStrings

        public Set<String> getReferencedStrings()
        Get the immutable set of string keys that are referenced by expressions in this compiled expression. If there are no expansions in this expression, the set is empty. Note that this will not include any string keys that themselves contain expressions, in the case that Expression.Flag.NO_RECURSE_KEY was not specified.
        Returns:
        the immutable set of strings (not null)
      • evaluateException

        public <E extends ExceptionString evaluateException​(ExceptionBiConsumer<ResolveContext<E>,​StringBuilder,​E> expandFunction)
                                                       throws E extends Exception
        Evaluate the expression with the given expansion function, which may throw a checked exception. The given "function" is a predicate which returns true if the expansion succeeded or false if it failed (in which case a default value may be used). If expansion succeeds, the expansion function should append the result to the given StringBuilder.
        Type Parameters:
        E - the exception type thrown by the expansion function
        Parameters:
        expandFunction - the expansion function to apply (must not be null)
        Returns:
        the expanded string
        Throws:
        E - if the expansion function throws an exception
        E extends Exception
      • evaluate

        public String evaluate​(BiConsumer<ResolveContext<RuntimeException>,​StringBuilder> expandFunction)
        Evaluate the expression with the given expansion function. The given "function" is a predicate which returns true if the expansion succeeded or false if it failed (in which case a default value may be used). If expansion succeeds, the expansion function should append the result to the given StringBuilder.
        Parameters:
        expandFunction - the expansion function to apply (must not be null)
        Returns:
        the expanded string
      • evaluateWithPropertiesAndEnvironment

        public String evaluateWithPropertiesAndEnvironment​(boolean failOnNoDefault)
        Evaluate the expression using a default expansion function that evaluates system and environment properties in the JBoss style (i.e. using the prefix "env." to designate an environment property). The caller must have all required security manager permissions.
        Parameters:
        failOnNoDefault - true to throw an IllegalArgumentException if an unresolvable key has no default value; false to expand such keys to an empty string
        Returns:
        the expanded string
      • evaluateWithProperties

        public String evaluateWithProperties​(boolean failOnNoDefault)
        Evaluate the expression using a default expansion function that evaluates system properties. The caller must have all required security manager permissions.
        Parameters:
        failOnNoDefault - true to throw an IllegalArgumentException if an unresolvable key has no default value; false to expand such keys to an empty string
        Returns:
        the expanded string
      • evaluateWithEnvironment

        public String evaluateWithEnvironment​(boolean failOnNoDefault)
        Evaluate the expression using a default expansion function that evaluates environment properties. The caller must have all required security manager permissions.
        Parameters:
        failOnNoDefault - true to throw an IllegalArgumentException if an unresolvable key has no default value; false to expand such keys to an empty string
        Returns:
        the expanded string
      • compile

        public static Expression compile​(String string,
                                         Expression.Flag... flags)
        Compile an expression string.
        Parameters:
        string - the expression string (must not be null)
        flags - optional flags to apply which affect the compilation
        Returns:
        the compiled expression (not null)
      • compile

        public static Expression compile​(String string,
                                         EnumSet<Expression.Flag> flags)
        Compile an expression string.
        Parameters:
        string - the expression string (must not be null)
        flags - optional flags to apply which affect the compilation (must not be null)
        Returns:
        the compiled expression (not null)