Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.jexl3
Class JexlBuilder

    java.lang.Object
      org.apache.commons.jexl3.JexlBuilder

    public class JexlBuilder

extends Object

Configure and builds a JexlEngine.

The `setSilent` and `setStrict` methods allow to fine-tune an engine instance behavior according to various error control needs. The strict flag tells the engine when and if null as operand is considered an error, the silent flag tells the engine what to do with the error (log as warning or throw exception).

- When "silent" & "not-strict":

  0 & null should be indicators of "default" values so that even in an case of error, something meaningful can still be inferred; may be convenient for configurations.

- When "silent" & "strict":

  One should probably consider using null as an error case - ie, every object manipulated by JEXL should be valued; the ternary operator, especially the '?:' form can be used to workaround exceptional cases. Use case could be configuration with no implicit values or defaults.

- When "not-silent" & "not-strict":

  The error control grain is roughly on par with JEXL 1.0

- When "not-silent" & "strict":

  The finest error control grain is obtained; it is the closest to Java code - still augmented by "script" capabilities regarding automated conversions and type matching.

Field Summary
`protected static int` | `CACHE_THRESHOLD` The default maximum expression length to hit the expression cache.

Constructor Summary
`JexlBuilder()`

Method Summary
`JexlArithmetic` | `arithmetic()`
`JexlBuilder` | `arithmetic(JexlArithmetic a)` Sets the JexlArithmetic instance the engine will use.
`int` | `cache()`
`JexlBuilder` | `cache(int size)` Sets the expression cache size the engine will use.
`int` | `cacheThreshold()`
`JexlBuilder` | `cacheThreshold(int length)` Sets the maximum length for an expression to be cached.
`Boolean` | `cancellable()`
`JexlBuilder` | `cancellable(boolean flag)` Sets the engine behavior upon interruption: throw an JexlException.Cancel or terminates the current evaluation and return null.
`Charset` | `charset()`
`JexlBuilder` | `charset(Charset arg)` Sets the charset to use.
`JexlEngine` | `create()`
`Boolean` | `debug()`
`JexlBuilder` | `debug(boolean flag)` Sets whether the engine will report debugging information when error occurs.
`ClassLoader` | `loader()`
`JexlBuilder` | `loader(Charset arg)` Deprecated. since 3.1 use `charset(Charset)` instead
`JexlBuilder` | `loader(ClassLoader l)` Sets the class loader to use.
`org.apache.commons.logging.Log` | `logger()`
`JexlBuilder` | `logger(org.apache.commons.logging.Log l)` Sets the o.a.c.Log instance to use.
`Map<String,Object>` | `namespaces()`
`JexlBuilder` | `namespaces(Map<String,Object> ns)` Sets the default namespaces map the engine will use.
`JexlSandbox` | `sandbox()`
`JexlBuilder` | `sandbox(JexlSandbox box)` Sets the sandbox the engine will use.
`Boolean` | `silent()`
`JexlBuilder` | `silent(boolean flag)` Sets whether the engine will throw JexlException during evaluation when an error is triggered.
`JexlUberspect.ResolverStrategy` | `strategy()`
`JexlBuilder` | `strategy(JexlUberspect.ResolverStrategy rs)` Sets the JexlUberspect strategy strategy the engine will use.
`Boolean` | `strict()`
`JexlBuilder` | `strict(boolean flag)` Sets whether the engine considers unknown variables, methods, functions and constructors as errors or evaluates them as null.
`JexlUberspect` | `uberspect()`
`JexlBuilder` | `uberspect(JexlUberspect u)` Sets the JexlUberspect instance the engine will use.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### CACHE_THRESHOLD

    protected static final int CACHE_THRESHOLD

  The default maximum expression length to hit the expression cache.

  See Also:
    Constant Field Values

Constructor Detail

### JexlBuilder

    public JexlBuilder()

Method Detail

### uberspect

    public JexlBuilder uberspect(JexlUberspect u)

  Sets the JexlUberspect instance the engine will use.

  Parameters:
    `u` - the uberspect
  Returns:
    this builder

### uberspect

    public JexlUberspect uberspect()

  Returns:
    the uberspect

### strategy

    public JexlBuilder strategy(JexlUberspect.ResolverStrategy rs)

  Sets the JexlUberspect strategy strategy the engine will use.

  This is ignored if the uberspect has been set.

  Parameters:
    `rs` - the strategy
  Returns:
    this builder

### strategy

    public JexlUberspect.ResolverStrategy strategy()

  Returns:
    the strategy strategy

### arithmetic

    public JexlBuilder arithmetic(JexlArithmetic a)

  Sets the JexlArithmetic instance the engine will use.

  Parameters:
    `a` - the arithmetic
  Returns:
    this builder

### arithmetic

    public JexlArithmetic arithmetic()

  Returns:
    the arithmetic

### sandbox

    public JexlBuilder sandbox(JexlSandbox box)

  Sets the sandbox the engine will use.

  Parameters:
    `box` - the sandbox
  Returns:
    this builder

### sandbox

    public JexlSandbox sandbox()

  Returns:
    the sandbox

### logger

    public JexlBuilder logger(org.apache.commons.logging.Log l)

  Sets the o.a.c.Log instance to use.

  Parameters:
    `l` - the logger
  Returns:
    this builder

### logger

    public org.apache.commons.logging.Log logger()

  Returns:
    the logger

### loader

    public JexlBuilder loader(ClassLoader l)

  Sets the class loader to use.

  Parameters:
    `l` - the class loader
  Returns:
    this builder

### loader

    public ClassLoader loader()

  Returns:
    the class loader

### loader

    @Deprecated
    public JexlBuilder loader(Charset arg)

  Deprecated. since 3.1 use `charset(Charset)` instead

  Sets the charset to use.

  Parameters:
    `arg` - the charset
  Returns:
    this builder

### charset

    public JexlBuilder charset(Charset arg)

  Sets the charset to use.

  Parameters:
    `arg` - the charset
  Returns:
    this builder
  Since:
    3.1

### charset

    public Charset charset()

  Returns:
    the charset

### silent

    public JexlBuilder silent(boolean flag)

  Sets whether the engine will throw JexlException during evaluation when an error is triggered.

  Parameters:
    `flag` - true means no JexlException will occur, false allows them
  Returns:
    this builder

### silent

    public Boolean silent()

  Returns:
    the silent error handling flag

### strict

    public JexlBuilder strict(boolean flag)

  Sets whether the engine considers unknown variables, methods, functions and constructors as errors or evaluates them as null.

  Parameters:
    `flag` - true means strict error reporting, false allows them to be evaluated as null
  Returns:
    this builder

### strict

    public Boolean strict()

  Returns:
    true if strict, false otherwise

### debug

    public JexlBuilder debug(boolean flag)

  Sets whether the engine will report debugging information when error occurs.

  Parameters:
    `flag` - true implies debug is on, false implies debug is off.
  Returns:
    this builder

### debug

    public Boolean debug()

  Returns:
    the debugging information flag

### cancellable

    public JexlBuilder cancellable(boolean flag)

  Sets the engine behavior upon interruption: throw an JexlException.Cancel or terminates the current evaluation and return null.

  Parameters:
    `flag` - true implies the engine throws the exception, false makes the engine return null.
  Returns:
    this builder
  Since:
    3.1

### cancellable

    public Boolean cancellable()

  Returns:
    the cancellable information flag
  Since:
    3.1

### namespaces

    public JexlBuilder namespaces(Map<String,Object> ns)

  Sets the default namespaces map the engine will use.

  Each entry key is used as a prefix, each entry value used as a bean implementing methods; an expression like 'nsx:method(123)' will thus be solved by looking at a registered bean named 'nsx' that implements method 'method' in that map. If all methods are static, you may use the bean class instead of an instance as value.

  If the entry value is a class that has one contructor taking a JexlContext as argument, an instance of the namespace will be created at evaluation time. It might be a good idea to derive a JexlContext to carry the information used by the namespace to avoid variable space pollution and strongly type the constructor with this specialized JexlContext.

  The key or prefix allows to retrieve the bean that plays the role of the namespace. If the prefix is null, the namespace is the top-level namespace allowing to define top-level user defined namespaces ( ie: myfunc(...) )

  Note that the JexlContext is also used to try to solve top-level namespaces. This allows ObjectContext derived instances to call methods on the wrapped object.

  Parameters:
    `ns` - the map of namespaces
  Returns:
    this builder

### namespaces

    public Map<String,Object> namespaces()

  Returns:
    the map of namespaces.

### cache

    public JexlBuilder cache(int size)

  Sets the expression cache size the engine will use.

  The cache will contain at most `size` expressions of at most `cacheThreshold` length. Note that all JEXL caches are held through SoftReferences and may be garbage-collected.

  Parameters:
    `size` - if not strictly positive, no cache is used.
  Returns:
    this builder

### cache

    public int cache()

  Returns:
    the cache size

### cacheThreshold

    public JexlBuilder cacheThreshold(int length)

  Sets the maximum length for an expression to be cached.

  Expression whose length is greater than this expression cache length threshold will bypass the cache.

  It is expected that a "long" script will be parsed once and its reference kept around in user-space structures; the jexl expression cache has no added-value in this case.

  Parameters:
    `length` - if not strictly positive, the value is silently replaced by the default value (64).
  Returns:
    this builder

### cacheThreshold

    public int cacheThreshold()

  Returns:
    the cache threshold

### create

    public JexlEngine create()

  Returns:
    a `JexlEngine` instance

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001–2017 The Apache Software Foundation. All rights reserved.