|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.ognl.enhance.ExpressionCompiler
public class ExpressionCompiler
Responsible for managing/providing functionality related to compiling generated java source expressions via bytecode enhancements for a given ognl expression.
Field Summary | |
---|---|
protected int |
classCounter
|
protected Map<ClassResolver,EnhancedClassLoader> |
loaders
ClassLoader instances. |
protected javassist.ClassPool |
pool
Javassist class definition poool. |
static String |
PRE_CAST
Key used to store any java source string casting statements in the OgnlContext during class compilation. |
Fields inherited from interface org.apache.commons.ognl.enhance.OgnlExpressionCompiler |
---|
ROOT_TYPE |
Constructor Summary | |
---|---|
ExpressionCompiler()
|
Method Summary | |
---|---|
static void |
addCastString(OgnlContext context,
String cast)
Used by castExpression(org.apache.commons.ognl.OgnlContext, org.apache.commons.ognl.Node, String) to
store the cast java source string in to the current OgnlContext . |
String |
castExpression(OgnlContext context,
Node expression,
String body)
Used primarily by AST types like ASTChain where foo.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,
Object root)
The core method executed to compile a specific expression. |
boolean |
containsMethod(Method m,
Class<?> clazz)
Helper utility method used by compiler to help resolve class->method mappings during method calls to OgnlExpressionCompiler.getSuperOrInterfaceClass(java.lang.reflect.Method, Class) . |
String |
createLocalReference(OgnlContext context,
String expression,
Class<?> type)
Method is used for expressions where multiple inner parameter method calls in generated java source strings cause javassit failures. |
protected String |
generateGetter(OgnlContext context,
javassist.CtClass newClass,
javassist.CtClass objClass,
javassist.ClassPool classPool,
javassist.CtMethod valueGetter,
Node expression,
Object root)
|
protected String |
generateOgnlGetter(javassist.CtClass clazz,
javassist.CtMethod valueGetter,
javassist.CtField node)
Fail safe getter creation when normal compilation fails. |
protected String |
generateOgnlSetter(javassist.CtClass clazz,
javassist.CtMethod valueSetter,
javassist.CtField node)
Fail safe setter creation when normal compilation fails. |
protected String |
generateSetter(OgnlContext context,
javassist.CtClass newClass,
javassist.CtClass objClass,
javassist.ClassPool classPool,
javassist.CtMethod valueSetter,
Node expression,
Object root)
|
static String |
getCastString(Class<?> type)
Returns the appropriate casting expression (minus parens) for the specified class type. |
protected EnhancedClassLoader |
getClassLoader(OgnlContext context)
Creates a ClassLoader instance compatible with the javassist classloader and normal OGNL class resolving
semantics. |
String |
getClassName(Class<?> clazz)
Gets a javassist safe class string for the given class instance. |
protected javassist.ClassPool |
getClassPool(OgnlContext context,
EnhancedClassLoader loader)
Gets either a new or existing ClassPool for use in compiling javassist classes. |
protected javassist.CtClass |
getCtClass(Class<?> searchClass)
Loads a new class definition via javassist for the specified class. |
Class<?> |
getInterfaceClass(Class<?> clazz)
Used in places where the preferred OgnlExpressionCompiler.getSuperOrInterfaceClass(java.lang.reflect.Method, Class) isn't
possible because the method isn't known for a class. |
static String |
getRootExpression(Node expression,
Object root,
OgnlContext context)
Convenience method called by many different property/method resolving AST types to get a root expression resolving string for the given node. |
Class<?> |
getRootExpressionClass(Node rootNode,
OgnlContext context)
For a given root object type returns the base class type to be used in root referenced expressions. |
Class<?> |
getSuperOrInterfaceClass(Method m,
Class<?> clazz)
For the given Method and class finds the highest level interface class this combination can be cast to. |
static boolean |
shouldCast(Node expression)
Used by getRootExpression(org.apache.commons.ognl.Node, Object, org.apache.commons.ognl.OgnlContext) to
determine if the expression needs to be cast at all. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String PRE_CAST
OgnlContext
during class compilation.
protected Map<ClassResolver,EnhancedClassLoader> loaders
ClassLoader
instances.
protected javassist.ClassPool pool
protected int classCounter
Constructor Detail |
---|
public ExpressionCompiler()
Method Detail |
---|
public static void addCastString(OgnlContext context, String cast)
castExpression(org.apache.commons.ognl.OgnlContext, org.apache.commons.ognl.Node, String)
to
store the cast java source string in to the current OgnlContext
. This will either
add to the existing string present if it already exists or create a new instance and store it using the static
key of PRE_CAST
.
context
- The current execution context.cast
- The java source string to store in to the context.public static String getCastString(Class<?> type)
Integer
object the string "java.lang.Integer"
would be returned.
For an array of primitive ints "int[]"
and so on..
type
- The class to cast a string expression for.
public static String getRootExpression(Node expression, Object root, OgnlContext context)
expression
- The node to check and generate a root expression to if necessary.root
- The root object for this execution.context
- The current execution context.
Node
.public static boolean shouldCast(Node expression)
getRootExpression(org.apache.commons.ognl.Node, Object, org.apache.commons.ognl.OgnlContext)
to
determine if the expression needs to be cast at all.
expression
- The node to check against.
public String castExpression(OgnlContext context, Node expression, String body)
ASTChain
where foo.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.
castExpression
in interface OgnlExpressionCompiler
context
- The current execution context.expression
- The node being checked for casting.body
- The java source string generated by the given node.
public String getClassName(Class<?> clazz)
getClassName
in interface OgnlExpressionCompiler
clazz
- The class to get a string equivalent javassist compatible string reference for.
public Class<?> getSuperOrInterfaceClass(Method m, Class<?> clazz)
Method
and class finds the highest level interface class this combination can be cast to.
getSuperOrInterfaceClass
in interface OgnlExpressionCompiler
m
- The method the class must implement.clazz
- The current class being worked with.
Method
is declared in.public boolean containsMethod(Method m, Class<?> clazz)
OgnlExpressionCompiler.getSuperOrInterfaceClass(java.lang.reflect.Method, Class)
.
m
- The method to check for existance of.clazz
- The class to check for the existance of a matching method definition to the method passed in.
public Class<?> getInterfaceClass(Class<?> clazz)
OgnlExpressionCompiler.getSuperOrInterfaceClass(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.
getInterfaceClass
in interface OgnlExpressionCompiler
clazz
- The class to attempt to find a compatible interface for.
public Class<?> getRootExpressionClass(Node rootNode, OgnlContext context)
getRootExpressionClass
in interface OgnlExpressionCompiler
rootNode
- The root expression node.context
- The current execution context.
public void compileExpression(OgnlContext context, Node expression, Object root) throws Exception
Node
with a non null Node.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.
compileExpression
in interface OgnlExpressionCompiler
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
Exception
- If an error occurs compiling the expression and no strategy has been implemented to handle
incremental expression compilation for incomplete expression members.protected String generateGetter(OgnlContext context, javassist.CtClass newClass, javassist.CtClass objClass, javassist.ClassPool classPool, javassist.CtMethod valueGetter, Node expression, Object root) throws Exception
Exception
public String createLocalReference(OgnlContext context, String expression, Class<?> type)
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.
createLocalReference
in interface OgnlExpressionCompiler
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.
protected String generateSetter(OgnlContext context, javassist.CtClass newClass, javassist.CtClass objClass, javassist.ClassPool classPool, javassist.CtMethod valueSetter, Node expression, Object root) throws Exception
Exception
protected String generateOgnlGetter(javassist.CtClass clazz, javassist.CtMethod valueGetter, javassist.CtField node) throws Exception
clazz
- The javassist class the new method should be attached to.valueGetter
- The method definition the generated code will be contained within.node
- The root expression node.
Exception
- If a javassist error occurs.protected String generateOgnlSetter(javassist.CtClass clazz, javassist.CtMethod valueSetter, javassist.CtField node) throws Exception
clazz
- The javassist class the new method should be attached to.valueSetter
- The method definition the generated code will be contained within.node
- The root expression node.
Exception
- If a javassist error occurs.protected EnhancedClassLoader getClassLoader(OgnlContext context)
ClassLoader
instance compatible with the javassist classloader and normal OGNL class resolving
semantics.
context
- The current execution context.
ClassLoader
instance.protected javassist.CtClass getCtClass(Class<?> searchClass) throws javassist.NotFoundException
searchClass
- The class to load.
javassist.NotFoundException
- When the class definition can't be found.protected javassist.ClassPool getClassPool(OgnlContext context, EnhancedClassLoader loader)
ClassPool
for use in compiling javassist classes. A new class path object
is inserted in to the returned ClassPool
using the passed in loader
instance if a new pool
needs to be created.
context
- The current execution context.loader
- The ClassLoader
instance to use - as returned by
getClassLoader(org.apache.commons.ognl.OgnlContext)
.
ClassPool
instance.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |