{
String result = "";
Method m = null;
if (context.getCurrentObject() == null)
throw new UnsupportedCompilationException("Current target is null.");
/*System.out.println("astproperty(setter) is indexed? : " + isIndexedAccess() + " child: " + _children[0].getClass().getName()
+ " target: " + target.getClass().getName() + " children length: " + _children.length);*/
try {
if (isIndexedAccess())
{
Object value = _children[0].getValue(context, context.getRoot());
if (value == null)
throw new UnsupportedCompilationException("Value passed as indexed property is null, can't enhance statement to bytecode.");
String srcString = _children[0].toGetSourceString(context, context.getRoot());
srcString = ExpressionCompiler.getRootExpression(_children[0], context.getRoot(), context) + srcString;
if (ASTChain.class.isInstance(_children[0]))
{
String cast = (String)context.remove(ExpressionCompiler.PRE_CAST);
if (cast != null)
srcString = cast + srcString;
}
if (ASTConst.class.isInstance(_children[0]) && String.class.isInstance(context.getCurrentObject()))
{
srcString = "\"" + srcString + "\"";
}
// System.out.println("astproperty setter using indexed value " + value + " and srcString: " + srcString);
if (context.get("_indexedMethod") != null)
{
m = (Method)context.remove("_indexedMethod");
PropertyDescriptor pd = (PropertyDescriptor)context.remove("_indexedDescriptor");
boolean lastChild = lastChild(context);
if (lastChild)
{
m = getIndexedWriteMethod(pd);
if (m == null)
throw new UnsupportedCompilationException("Indexed property has no corresponding write method.");
}
_setterClass = m.getParameterTypes()[0];
Object indexedValue = null;
if (!lastChild)
indexedValue = OgnlRuntime.callMethod(context, target, m.getName(), new Object[]{value});
context.setCurrentType(_setterClass);
context.setCurrentAccessor(OgnlRuntime.getCompiler().getSuperOrInterfaceClass(m, m.getDeclaringClass()));
if (!lastChild)
{
context.setCurrentObject(indexedValue);
return "." + m.getName() + "(" + srcString + ")";
} else {
return "." + m.getName() + "(" + srcString + ", $3)";
}
} else
{
PropertyAccessor p = OgnlRuntime.getPropertyAccessor(target.getClass());
Object currObj = context.getCurrentObject();
Class currType = context.getCurrentType();
Class prevType = context.getPreviousType();
Object indexVal = p.getProperty(context, target, value);
// reset current object for accessor
context.setCurrentObject(currObj);
context.setCurrentType(currType);
context.setPreviousType(prevType);
if (ASTConst.class.isInstance(_children[0]) && Number.class.isInstance(context.getCurrentObject()))
context.setCurrentType(OgnlRuntime.getPrimitiveWrapperClass(context.getCurrentObject().getClass()));
result = lastChild(context) ? p.getSourceSetter(context, target, srcString) : p.getSourceAccessor(context, target, srcString);
/*System.out.println("ASTProperty using propertyaccessor and isLastChild? " + lastChild(context)
+ " generated source of: " + result + " using accessor class: " + p.getClass().getName());*/
//result = p.getSourceAccessor(context, target, srcString);
_getterClass = context.getCurrentType();
context.setCurrentObject(indexVal);
/* PropertyAccessor p = OgnlRuntime.getPropertyAccessor(target.getClass());
if (ASTConst.class.isInstance(_children[0]) && Number.class.isInstance(context.getCurrentObject()))
{
context.setCurrentType(OgnlRuntime.getPrimitiveWrapperClass(context.getCurrentObject().getClass()));
}
result = p.getSourceSetter(context, target, srcString);
context.setCurrentObject(value);
context.setCurrentType(_getterClass);*/
return result;
}
}
String name = ((ASTConst) _children[0]).getValue().toString();
// System.out.println(" astprop(setter) : trying to set " + name + " on object target " + context.getCurrentObject().getClass().getName());
if (!Iterator.class.isAssignableFrom(context.getCurrentObject().getClass())
|| (Iterator.class.isAssignableFrom(context.getCurrentObject().getClass()) && name.indexOf("next") < 0)) {
Object currObj = target;
try {
target = getValue(context, context.getCurrentObject());
} catch (NoSuchPropertyException e) {
try {
target = getValue(context, context.getRoot());
} catch (NoSuchPropertyException ex) { }
} finally {
context.setCurrentObject(currObj);
}
}
PropertyDescriptor pd = OgnlRuntime.getPropertyDescriptor(OgnlRuntime.getCompiler().getInterfaceClass(context.getCurrentObject().getClass()), name);
if (pd != null)
{
Method pdMethod = lastChild(context) ? pd.getWriteMethod() : pd.getReadMethod();
if (pdMethod != null && !context.getMemberAccess().isAccessible(context, context.getCurrentObject(), pdMethod, name))
{
throw new UnsupportedCompilationException("Member access forbidden for property " + name + " on class " + context.getCurrentObject().getClass());
}
}
if (pd != null && this.getIndexedPropertyType(context, context.getCurrentObject()) > 0)
{