final String namespace = namespaces[namespaceIdx];
final String[] names = e.getAttributeExpressionNames(namespace);
for (int nameIdx = 0; nameIdx < names.length; nameIdx++)
{
final String name = names[nameIdx];
final Expression ex = e.getAttributeExpression(namespace, name);
if (ex == null)
{
continue;
}
final AttributeMetaData attribute = metaData.getAttributeDescription(namespace, name);
if (attribute != null && attribute.isDesignTimeValue())
{
continue;
}
retval = true;
ex.setRuntime(getRuntime());
try
{
final Object value = evaluate(ex);
if (attribute == null)
{
// Not a declared attribute, but maybe one of the output-handlers can work on this one.
e.setAttribute(namespace, name, value);
}
else
{
final Class type = attribute.getTargetType();
if (value == null || type.isAssignableFrom(value.getClass()))
{
e.setAttribute(namespace, name, value);
}
else if (value instanceof ErrorValue)
{
e.setAttribute(namespace, name, null);
}
else
{
final PropertyEditor propertyEditor = attribute.getEditor();
if (propertyEditor != null)
{
propertyEditor.setAsText(String.valueOf(value));
e.setAttribute(namespace, name, propertyEditor.getValue());
}
else
{
try
{
final ValueConverter valueConverter = instance.getValueConverter(type);
if (type.isAssignableFrom(String.class))
{
// the attribute would allow raw-string values, so copy the element ..
e.setAttribute(namespace, name, value);
}
else if (valueConverter != null)
{
final Object o = ConverterRegistry.toPropertyValue(String.valueOf(value), type);
e.setAttribute(namespace, name, o);
}
else
{
// undo any previous computation
e.setAttribute(namespace, name, null);
}
}
catch (BeanException be)
{
// ignore.
// AttributeExpressionsEvaluator.logger.debug("Attribute '" + namespace + '|' + name +
// "' is not convertible with the bean-methods for value " + value);
e.setAttribute(namespace, name, null);
}
}
}
}
}
catch (Exception exception)
{
// ignored .. but we unset the attribute as we have no valid value anymore ..
e.setAttribute(namespace, name, null);
}
finally
{
ex.setRuntime(null);
}
}
}
return retval;
}