net.jakubholy.jeeutils.jsfelcheck.validator
Class ValidatingJsfElResolver

java.lang.Object
  extended by net.jakubholy.jeeutils.jsfelcheck.validator.ValidatingJsfElResolver
All Implemented Interfaces:
JsfElValidator

public class ValidatingJsfElResolver
extends Object
implements JsfElValidator

A "fake" resolver of JSF EL expression which only checks the validity of the expressions using a custom Variable and Property resolver without requiring real values for the variables being referenced in the expressions. The variable resolver resolvers against a pre-defined list of known variables, the property resolver doesn't actually invoke any getter but just returns a Mock of the appropriate type (so that evaluation of the expression can proceed, which wouldn't be possible if we used real objects and they returned null).

See Also:
declareVariable(String, Object), definePropertyTypeOverride(String, Class)

Constructor Summary
ValidatingJsfElResolver()
           
 
Method Summary
 void addElExpressionFilter(ElExpressionFilter elExpressionFilter)
          Throw ExpressionRejectedByFilterException for any expression not accepted by the supplied filter.
 JsfElValidator declareVariable(String name, Object value)
           
 JsfElValidator definePropertyTypeOverride(String elExpression, Class<?> newType)
          Specify the type of a 'property' in a JSF EL expression, usually a component of a collection etc.
 boolean isIncludeKnownVariablesInException()
           
 void setIncludeKnownVariablesInException(boolean includeKnownVariablesInException)
          List known variables in VariableNotFoundException?
 void setUnknownVariableResolver(ElVariableResolver unknownVariableResolver)
           
 ValidationResult validateMethodElExpression(String elExpression)
           
 ValidationResult validateValueElExpression(String elExpression)
          Validates that JSF EL is valid and returns its value, which is either a predefined variable or a mock of the class expected to be returned by a property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValidatingJsfElResolver

public ValidatingJsfElResolver()
Method Detail

setUnknownVariableResolver

public void setUnknownVariableResolver(ElVariableResolver unknownVariableResolver)

validateMethodElExpression

public ValidationResult validateMethodElExpression(String elExpression)
Specified by:
validateMethodElExpression in interface JsfElValidator

validateValueElExpression

public ValidationResult validateValueElExpression(String elExpression)
Description copied from interface: JsfElValidator
Validates that JSF EL is valid and returns its value, which is either a predefined variable or a mock of the class expected to be returned by a property. (So the value isn't really interesting as it isn't determined based on real objects, it's only important to verify that it is not null or that it is an instance of the expected type.)

Specified by:
validateValueElExpression in interface JsfElValidator
Parameters:
elExpression - (required) Ex.: #{aBean}, #{aBean.aProperty}, #{aBean['key'].property}

declareVariable

public JsfElValidator declareVariable(String name,
                                      Object value)
Specified by:
declareVariable in interface JsfElValidator

definePropertyTypeOverride

public JsfElValidator definePropertyTypeOverride(String elExpression,
                                                 Class<?> newType)
Description copied from interface: JsfElValidator
Specify the type of a 'property' in a JSF EL expression, usually a component of a collection etc. If you have #{myBean.myMap['anyKey'].whatever} you may declare the type returned from the myMap by specifying override for 'myBean.myMap.*' to be e.g. WhateverType.class.

There are two types of overrides: (1) property overrides: pass in the complete property, ex: bean.property1.property2 (2) collection component type overrides: for all sub-properties of a variable/property (unless there is also a property override for it), used for arrays etc. Ex: bean.mapProperty.* => bean.mapProperty['someKey'] and bean.mapProperty.anotherProperty will be both affected by the override

Specified by:
definePropertyTypeOverride in interface JsfElValidator
Parameters:
elExpression - The expression where to override the guessed type with only names and dots, perhaps plus .*; i.e. 'var.prop['key']' becomes var.prop

setIncludeKnownVariablesInException

public void setIncludeKnownVariablesInException(boolean includeKnownVariablesInException)
List known variables in VariableNotFoundException?


addElExpressionFilter

public void addElExpressionFilter(ElExpressionFilter elExpressionFilter)
Throw ExpressionRejectedByFilterException for any expression not accepted by the supplied filter.

Parameters:
elExpressionFilter - (required)

isIncludeKnownVariablesInException

public boolean isIncludeKnownVariablesInException()


Copyright © 2011. All Rights Reserved.