return;
String getBody = null;
String setBody;
ClassFab classFab = _classFactory.newClass(ClassFabUtils.generateClassName(expression.getClass()), Object.class);
classFab.addInterface(ExpressionAccessor.class);
MethodSignature valueGetter = new MethodSignature(Object.class, "get", new Class[]{OgnlContext.class, Object.class}, null);
MethodSignature valueSetter = new MethodSignature(void.class, "set", new Class[]{OgnlContext.class, Object.class, Object.class}, null);
MethodSignature expressionSetter = new MethodSignature(void.class, "setExpression", new Class[]{Node.class}, null);
// must evaluate expression value at least once if object isn't null
if (root != null)
Ognl.getValue(expression, context, root);
try {
getBody = generateGetter(context, classFab, valueGetter, expression, root);
} catch (UnsupportedCompilationException uc) {
// uc.printStackTrace();
// The target object may not fully resolve yet because of a partial tree with a null somewhere, we
// don't want to bail out forever because it might be enhancable on another pass eventually
return;
} catch (javassist.CannotCompileException e) {
_log.error("Error generating OGNL getter for expression " + expression + " with root " + root + " and body:\n" + getBody, e);
e.printStackTrace();
generateFailSafe(context, expression, root);
return;
}
try {
classFab.addMethod(Modifier.PUBLIC, valueGetter, getBody);
} catch (Throwable t) {
_log.error("Error generating OGNL getter for expression " + expression + " with root " + root + " and body:\n" + getBody, t);
t.printStackTrace();
generateFailSafe(context, expression, root);
return;
}
try {
setBody = generateSetter(context, classFab, valueSetter, expression, root);
} catch (UnsupportedCompilationException uc) {
//_log.warn("Unsupported setter compilation caught: " + uc.getMessage() + " for expression: " + expression.toString(), uc);
setBody = generateOgnlSetter(classFab, valueSetter);
if (!classFab.containsMethod(expressionSetter)) {
classFab.addField("_node", Node.class);
classFab.addMethod(Modifier.PUBLIC, expressionSetter, "{ _node = $1; }");
}
}
try {
if (setBody == null) {
setBody = generateOgnlSetter(classFab, valueSetter);
if (!classFab.containsMethod(expressionSetter)) {
classFab.addField("_node", Node.class);
classFab.addMethod(Modifier.PUBLIC, expressionSetter, "{ _node = $1; }");
}
}
if (setBody != null)
classFab.addMethod(Modifier.PUBLIC, valueSetter, setBody);
classFab.addConstructor(new Class[0], new Class[0], "{}");
Class clazz = ((AbstractFab) classFab).createClass(true);
expression.setAccessor((ExpressionAccessor) clazz.newInstance());
} catch (Throwable t) {
_log.error("Error generating OGNL statements for expression " + expression + " with root " + root, t);
t.printStackTrace();
generateFailSafe(context, expression, root);
return;
}
// need to set expression on node if the field was just defined.
if (classFab.containsMethod(expressionSetter)) {
expression.getAccessor().setExpression(expression);
}
}