Package ognl.enhance

Interface OgnlExpressionCompiler

All Known Implementing Classes:
ExpressionCompiler

public interface OgnlExpressionCompiler
Core interface implemented by expression compiler instances.
  • Field Details

  • Method Details

    • compileExpression

      void compileExpression(OgnlContext context, Node expression, Object root) throws Exception
      The core method executed to compile a specific expression. It is expected that this expression always return a 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.
      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:
      Exception - If an error occurs compiling the expression and no strategy has been implemented to handle incremental expression compilation for incomplete expression members.
    • getClassName

      String getClassName(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

      Class getInterfaceClass(Class clazz)
      Used in places where the preferred 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.
      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

      Class getSuperOrInterfaceClass(Method m, Class clazz)
      For the given Method 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

      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

      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.

      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

      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. 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.