Package ognl.enhance
Interface OgnlExpressionCompiler
-
- All Known Implementing Classes:
ExpressionCompiler
public interface OgnlExpressionCompiler
Core interface implemented by expression compiler instances.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ROOT_TYPE
Static constant used in conjunction withOgnlContext
to store temporary references.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.String
castExpression(OgnlContext context, Node expression, java.lang.String body)
Used primarily by AST types likeASTChain
wherefoo.bar.id
type references may need to be cast multiple times in order to properly resolve the members in a compiled statement.void
compileExpression(OgnlContext context, Node expression, java.lang.Object root)
The core method executed to compile a specific expression.java.lang.String
createLocalReference(OgnlContext context, java.lang.String expression, java.lang.Class type)
Method is used for expressions where multiple inner parameter method calls in generated java source strings cause javassit failures.java.lang.String
getClassName(java.lang.Class clazz)
Gets a javassist safe class string for the given class instance.java.lang.Class
getInterfaceClass(java.lang.Class clazz)
Used in places where the preferredgetSuperOrInterfaceClass(java.lang.reflect.Method, Class)
isn't possible because the method isn't known for a class.java.lang.Class
getRootExpressionClass(Node rootNode, OgnlContext context)
For a given root object type returns the base class type to be used in root referenced expressions.java.lang.Class
getSuperOrInterfaceClass(java.lang.reflect.Method m, java.lang.Class clazz)
For the givenMethod
and class finds the highest level interface class this combination can be cast to.
-
-
-
Field Detail
-
ROOT_TYPE
static final java.lang.String ROOT_TYPE
Static constant used in conjunction withOgnlContext
to store temporary references.- See Also:
- Constant Field Values
-
-
Method Detail
-
compileExpression
void compileExpression(OgnlContext context, Node expression, java.lang.Object root) throws java.lang.Exception
The core method executed to compile a specific expression. It is expected that this expression always return aNode
with a non nullNode.getAccessor()
instance - unless an exception is thrown by the method or the statement wasn't compilable in this instance because of missing/null objects in the expression. These instances may in some cases continue to call this compilation method until the expression is resolvable.- Parameters:
context
- The context of execution.expression
- The pre-parsed root expression node to compile.root
- The root object for the expression - may be null in many instances so some implementations may exit- Throws:
java.lang.Exception
- If an error occurs compiling the expression and no strategy has been implemented to handle incremental expression compilation for incomplete expression members.
-
getClassName
java.lang.String getClassName(java.lang.Class clazz)
Gets a javassist safe class string for the given class instance. This is especially useful for handling array vs. normal class casting strings.- Parameters:
clazz
- The class to get a string equivalent javassist compatible string reference for.- Returns:
- The string equivalent of the class.
-
getInterfaceClass
java.lang.Class getInterfaceClass(java.lang.Class clazz)
Used in places where the preferredgetSuperOrInterfaceClass(java.lang.reflect.Method, Class)
isn't possible because the method isn't known for a class. Attempts to upcast the given class to the next available non-private accessible class so that compiled expressions can reference the interface class of an instance so as not to be compiled in to overly specific statements.- Parameters:
clazz
- The class to attempt to find a compatible interface for.- Returns:
- The same class if no higher level interface could be matched against or the interface equivalent class.
-
getSuperOrInterfaceClass
java.lang.Class getSuperOrInterfaceClass(java.lang.reflect.Method m, java.lang.Class clazz)
For the givenMethod
and class finds the highest level interface class this combination can be cast to.- Parameters:
m
- The method the class must implement.clazz
- The current class being worked with.- Returns:
- The highest level interface / class that the referenced
Method
is declared in.
-
getRootExpressionClass
java.lang.Class getRootExpressionClass(Node rootNode, OgnlContext context)
For a given root object type returns the base class type to be used in root referenced expressions. This helps in some instances where the root objects themselves are compiled javassist instances that need more generic class equivalents to cast to.- Parameters:
rootNode
- The root expression node.context
- The current execution context.- Returns:
- The root expression class type to cast to for this node.
-
castExpression
java.lang.String castExpression(OgnlContext context, Node expression, java.lang.String body)
Used primarily by AST types likeASTChain
wherefoo.bar.id
type references may need to be cast multiple times in order to properly resolve the members in a compiled statement.This method should be using the various
OgnlContext.getCurrentType()
/OgnlContext.getCurrentAccessor()
methods to inspect the type stack and properly cast to the right classes - but only when necessary.- Parameters:
context
- The current execution context.expression
- The node being checked for casting.body
- The java source string generated by the given node.- Returns:
- The body string parameter plus any additional casting syntax needed to make the expression resolvable.
-
createLocalReference
java.lang.String createLocalReference(OgnlContext context, java.lang.String expression, java.lang.Class type)
Method is used for expressions where multiple inner parameter method calls in generated java source strings cause javassit failures. It is hacky and cumbersome to have to generate expressions this way but it's the only current known way to make javassist happy.Takes an expression block generated by a node and creates a new method on the base object being compiled so that sufficiently complicated sub expression blocks can be broken out in to distinct methods to be referenced by the core accessor / setter methods in the base compiled root object.
- Parameters:
context
- The current execution context.expression
- The java source expression to dump in to a seperate method reference.type
- The return type that should be specified for the new method.- Returns:
- The method name that will be used to reference the sub expression in place of the actual sub expression itself.
-
-