String expression = trim.substring(constantPrefix.length(), trim.length() - constantSuffix.length()).trim();
int lastDotIndex = expression.lastIndexOf('.');
if (lastDotIndex < 0) {
throw new ConfigurationException("Invalid expression '" + expression + "' in expression '" + strVal + "'. Must evaluate to constant (e.g. 'constant:[org.impalframework.constants.LocationConstant.MODULE_CLASS_DIR_PROPERTY]'");
}
String className = expression.substring(0, lastDotIndex);
String fieldName = expression.substring(lastDotIndex + 1);
try {
Class<?> clazz = Class.forName(className, true, classLoader);
try {
Field field = clazz.getField(fieldName);
Object value = field.get(null);
if (value != null) {
return value.toString();
} else {
throw new ConfigurationException("Field '" + fieldName + "' in class " + className + " in expression '" + strVal + "' cannot evaluate to null");
}
}
catch (ConfigurationException e) {
throw e;
}
catch (Exception e) {
throw new ConfigurationException("Field '" + fieldName + "' in class " + className + " in expression '" + strVal + "' could not be evaluated. Could not evaluate constant in bean '" + beanName +"'", e);
}
}
catch (ClassNotFoundException e) {
throw new ConfigurationException("Class '" + className + "' in expression '" + strVal + "' could not be found. Could not evaluate constant in bean '" + beanName +"'" );
}
}
return strVal;
}