org.javalid.core.el
Class ELSupport

java.lang.Object
  extended by org.javalid.core.el.ELSupport

public class ELSupport
extends java.lang.Object

Supportive class to get default resolver for framework and other shared resolver methods.

Since:
1.1
Version:
1.0
Author:
M.Reuvers

Constructor Summary
ELSupport()
           
 
Method Summary
static java.lang.String addExpression(java.lang.String expression)
          Makes an expression for given text.
static javax.el.ELResolver getDefaultELResolver(boolean fieldResolver, boolean readOnly)
           
static java.lang.String getExpressionParent()
           
static java.lang.String getExpressionThis()
           
static java.lang.String getNameParent()
           
static java.lang.String getNameThis()
           
static boolean isExpression(java.lang.String value)
          Checks if given value starts with #{ or ${ and ends with }.
static void registerDefaultExpressionForClassLevelValidation(javax.el.ExpressionFactory factory, javax.el.ELContext ctx, java.lang.Object thisObject)
          Registers the ${me} variables into given context.
static void registerDefaultExpressionsForStandardValidation(javax.el.ExpressionFactory factory, javax.el.ELContext ctx, java.lang.Object thisObject, java.lang.Object parentObject)
          Registers the ${this} and ${parent} variables into given context.
static java.lang.Object resolveSingleExpression(javax.el.ExpressionFactory factory, javax.el.ELContext ctx, java.lang.String expression, boolean allowsNull)
          Resolves a single expression and returns the value that was resolved from it.
static void setParentName(java.lang.String name)
          Allows you to override the default name for registering the parent in EL.
static void setThisName(java.lang.String name)
          Allows you to override the default name for registering the this in EL.
static java.util.List<ELString> splitPossibleExpressionString(java.lang.String value)
          Attempts to split String in parts.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ELSupport

public ELSupport()
Method Detail

isExpression

public static final boolean isExpression(java.lang.String value)
Checks if given value starts with #{ or ${ and ends with }. First trims the value of spaces, then performs the check, also the length must be > 3 (thus actually contain something between the braces).

Note: checks and expects a single expression.

Parameters:
value - The value to check
Returns:
True if it conforms an expression, false otherwise.

addExpression

public static final java.lang.String addExpression(java.lang.String expression)
Makes an expression for given text. If it is not already one. Adds #{} around it. Checks for #{} and ${}.

Parameters:
expression - The text to make an expression from
Returns:
Expression
Since:
1.2

getExpressionParent

public static final java.lang.String getExpressionParent()

getExpressionThis

public static final java.lang.String getExpressionThis()

getNameParent

public static final java.lang.String getNameParent()

getNameThis

public static final java.lang.String getNameThis()

setParentName

public static final void setParentName(java.lang.String name)
Allows you to override the default name for registering the parent in EL.

Parameters:
name - New name (must NOT be an expression, just a normal name)

setThisName

public static final void setThisName(java.lang.String name)
Allows you to override the default name for registering the this in EL.

Parameters:
name - New name (must NOT be an expression, just a normal name)

getDefaultELResolver

public static final javax.el.ELResolver getDefaultELResolver(boolean fieldResolver,
                                                             boolean readOnly)

splitPossibleExpressionString

public static final java.util.List<ELString> splitPossibleExpressionString(java.lang.String value)
Attempts to split String in parts. The String may contain multiple expressions. E.g. "This is #{this.name} calling from #{this.country.name}". Returns a List with split parts, denoting if such a part is an expression string or not. Callers then know what part to resolve and what not. If no expression was found, simply returns a single ELString element in the List telling it is not a expression.

One can ofcourse resolve such a String at once using the ELResolver, however when using the database we must use binding parameters to prevent SQL injection. Specially for such purposes we split the String like this. So the expression parts can be resolved separately.

Parameters:
value - The String value containing possibly 1 or more expressions.
Returns:
List containing ELString parts, if value is null returns an empty list

registerDefaultExpressionsForStandardValidation

public static final void registerDefaultExpressionsForStandardValidation(javax.el.ExpressionFactory factory,
                                                                         javax.el.ELContext ctx,
                                                                         java.lang.Object thisObject,
                                                                         java.lang.Object parentObject)
Registers the ${this} and ${parent} variables into given context. These are the standard available objects for validation. This method should be called by validators that support this type of validation.

Parameters:
factory - The current factory
ctx - The context to register them in
parentObject - The actual class (not the method/field value but instead the instance where thisObject was defined).
thisObject - The this value (the actual object that is under validation on a method / field)
Since:
1.2

registerDefaultExpressionForClassLevelValidation

public static final void registerDefaultExpressionForClassLevelValidation(javax.el.ExpressionFactory factory,
                                                                          javax.el.ELContext ctx,
                                                                          java.lang.Object thisObject)
Registers the ${me} variables into given context. These are the available objects for class validation. This method should be called by validators that support this type of validation.

Parameters:
factory - The current factory
ctx - The context to register them in
thisObject - The class value (the instance under validation, note instance as is on classlevel)
Since:
1.2

resolveSingleExpression

public static final java.lang.Object resolveSingleExpression(javax.el.ExpressionFactory factory,
                                                             javax.el.ELContext ctx,
                                                             java.lang.String expression,
                                                             boolean allowsNull)
Resolves a single expression and returns the value that was resolved from it. If allowsNull = false, and the value resolved is null raises a JavalidException. Otherwise it just returns the value (whether null or not). If a property is not found, a JavalidException is raised as well (containing the propertynotfoundexception).

Parameters:
factory - Expression factory
ctx - The context
expression - The expression to resolve (must be a valid expression), if not: behavior is not defined.
allowsNull - True if you want the method to check if resolved value is null, if so raises an exception. When false simply returns the value (null or not)
Returns:
Object resolved