}
public String toGetSourceString(OgnlContext context, Object target)
{
if (target == null)
throw new UnsupportedCompilationException("evaluation resulted in null expression.");
if (_children.length != 3)
throw new UnsupportedCompilationException("Can only compile test expressions with two children." + _children.length);
String result = "";
try {
String first = OgnlRuntime.getChildSource(context, target, _children[0]);
if (!OgnlRuntime.isBoolean(first) && !context.getCurrentType().isPrimitive())
first = OgnlRuntime.getCompiler().createLocalReference(context, first, context.getCurrentType());
if (ExpressionNode.class.isInstance(_children[0]))
{
first = "(" + first + ")";
}
String second = OgnlRuntime.getChildSource(context, target, _children[1]);
Class secondType = context.getCurrentType();
if (!OgnlRuntime.isBoolean(second) && !context.getCurrentType().isPrimitive())
second = OgnlRuntime.getCompiler().createLocalReference(context, second, context.getCurrentType());
if (ExpressionNode.class.isInstance(_children[1]))
{
second = "(" + second + ")";
}
String third = OgnlRuntime.getChildSource(context, target, _children[2]);
Class thirdType = context.getCurrentType();
if (!OgnlRuntime.isBoolean(third) && !context.getCurrentType().isPrimitive())
third = OgnlRuntime.getCompiler().createLocalReference(context, third, context.getCurrentType());
if (ExpressionNode.class.isInstance(_children[2]))
{
third = "(" + third + ")";
}
boolean mismatched = (secondType.isPrimitive() && !thirdType.isPrimitive())
|| (!secondType.isPrimitive() && thirdType.isPrimitive()) ? true : false;
result += "ognl.OgnlOps.booleanValue(" + first + ")";
result += " ? ";
result += (mismatched ? " ($w) " : "") + second;
result += " : ";
result += (mismatched ? " ($w) " : "") + third;
context.setCurrentObject(target);
context.setCurrentType(mismatched ? Object.class : secondType);
return result;
} catch (NullPointerException e) {
// expected to happen in some instances
throw new UnsupportedCompilationException("evaluation resulted in null expression.");
} catch (Throwable t)
{
throw OgnlOps.castToRuntime(t);
}
}