boolean retval = false;
final ElementStyleSheet style = e.getStyle();
for (final Map.Entry<StyleKey, Expression> entry : styleExpressions.entrySet())
{
final StyleKey key = entry.getKey();
final Expression ex = entry.getValue();
if (ex == null)
{
continue;
}
retval = true;
ex.setRuntime(getRuntime());
try
{
final Object value = evaluate(ex);
if (value == null)
{
style.setStyleProperty(key, null);
}
else if (key.getValueType().isInstance(value))
{
style.setStyleProperty(key, value);
}
else if (value instanceof ErrorValue)
{
if (failOnErrors)
{
throw new InvalidReportStateException(String.format
("Failed to evaluate style-expression for key %s on element [%s]",// NON-NLS
key.getName(),
FunctionUtilities.computeElementLocation(e)));
}
style.setStyleProperty(key, null);
}
else
{
final ValueConverter valueConverter = ConverterRegistry.getInstance().getValueConverter(key.getValueType());
if (valueConverter != null)
{
// try to convert it ..
final Object o = ConverterRegistry.toPropertyValue(String.valueOf(value), key.getValueType());
style.setStyleProperty(key, o);
}
else
{
style.setStyleProperty(key, null);
}
}
}
catch (InvalidReportStateException exception)
{
throw exception;
}
catch (Exception exception)
{
if (logger.isDebugEnabled())
{
logger.debug(String.format
("Failed to evaluate style expression for element '%s', style-key %s", // NON-NLS
e, key), exception);
}
if (failOnErrors)
{
throw new InvalidReportStateException(String.format
("Failed to evaluate style-expression for key %s on element [%s]",// NON-NLS
key.getName(),
FunctionUtilities.computeElementLocation(e)), exception);
}
// ignored, but we clear the style as we have no valid value anymore.
style.setStyleProperty(key, null);
}