in src/main/java/org/apache/commons/ognl/ASTChain.java [267:380]
public String toGetSourceString( OgnlContext context, Object target )
{
String prevChain = (String) context.get( "_currentChain" );
if ( target != null )
{
context.setCurrentObject( target );
context.setCurrentType( target.getClass() );
}
String result = "";
NodeType lastType = null;
boolean ordered = false;
boolean constructor = false;
try
{
if ( ( children != null ) && ( children.length > 0 ) )
{
for ( Node child : children )
{
/*
* System.out.println("astchain child: " + _children[i].getClass().getName() +
* " with current object target " + context.getCurrentObject() + " current type: " +
* context.getCurrentType());
*/
String value = child.toGetSourceString( context, context.getCurrentObject() );
// System.out.println("astchain child returned >> " + value + " <<");
if (child instanceof ASTCtor)
{
constructor = true;
}
if ( child instanceof NodeType && ( (NodeType) child ).getGetterClass() != null )
{
lastType = (NodeType) child;
}
// System.out.println("Astchain i: " + i + " currentobj : " + context.getCurrentObject() +
// " and root: " + context.getRoot());
if ( !(child instanceof ASTVarRef) && !constructor && !(
child instanceof OrderedReturn
&& ( (OrderedReturn) child ).getLastExpression() != null ) && ( parent == null
|| !(parent instanceof ASTSequence)) )
{
value = OgnlRuntime.getCompiler( context ).castExpression( context, child, value );
}
/*
* System.out.println("astchain value now : " + value + " with index " + i + " current type " +
* context.getCurrentType() + " current accessor " + context.getCurrentAccessor() + " prev type " +
* context.getPreviousType() + " prev accessor " + context.getPreviousAccessor());
*/
if ( child instanceof OrderedReturn
&& ( (OrderedReturn) child ).getLastExpression() != null )
{
ordered = true;
OrderedReturn or = (OrderedReturn) child;
if ( or.getCoreExpression() == null || or.getCoreExpression().trim().isEmpty() )
{
result = "";
}
else
{
result += or.getCoreExpression();
}
lastExpression = or.getLastExpression();
if ( context.get( ExpressionCompiler.PRE_CAST ) != null )
{
lastExpression = context.remove( ExpressionCompiler.PRE_CAST ) + lastExpression;
}
}
else if ( child instanceof ASTOr || child instanceof ASTAnd
|| child instanceof ASTCtor || ( child instanceof ASTStaticField
&& parent == null ) )
{
context.put( "_noRoot", "true" );
result = value;
}
else
{
result += value;
}
context.put( "_currentChain", result );
}
}
}
catch ( Throwable t )
{
throw OgnlOps.castToRuntime( t );
}
if ( lastType != null )
{
getterClass = lastType.getGetterClass();
setterClass = lastType.getSetterClass();
}
if ( ordered )
{
coreExpression = result;
}
context.put( "_currentChain", prevChain );
return result;
}