You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Overview

This document is meant as a development/integration guide for anyone wanting to use the new OGNL 2.7 features for doing byte code runtime enhancements on OGNL statements.  This is not meant for general user reference as it covers what are mostly internal API development concerns.

 Basic Usage

By default there isn't much you have to do to use the new compilation abilities in OGNL.  Following is an example of compiling a simple property expression and invoking it.

SimpleObject root = new SimpleObject();
OgnlContext context =  (OgnlContext) Ognl.createDefaultContext(null);

Node node =  (Node) Ognl.compileExpression(context, root, "user.name");
String userName = node.getAccessor().get(context, root);

You'll notice that this example references the new ognl.enhance.ExpressionAccessor class. This is the interface used to create the enhanced expression versions of any given expression via javassist and should be used to set/get expression values from the compiled versions of the code. Although the old Ognl.getValue(node, context, root) method of getting/setting values will correctly detect a compiled expression and use the accessor directly as well, it's not going to be as fast as you doing it directly.

 ognl.enhance.OgnlExpressionCompiler

The core class involved in doing the management of these expression compilations by default is ognl.enhance.ExpressionCompiler, which implements ognl.enhance.OgnlExpressionCompiler. Although you can in theory use this default implementation it is not recommended for more robust integration points - such as being incorporated within a web framework. The majority of examples here are going to be based around the strategy that Tapestry has used to integrate these new features.

 Tapestry OGNL Integration

There are only small handful of classes/services involved in the Tapestry implementation of these features, so hopefully using them as a reference will help anyone trying to get started with this:

  • No labels