{
// try other setters that may fit later on. Don't throw this exception though.
}
catch (Exception e)
{
throw new ConfigurationException("Unable to invoke setter " + setter + " on " + objectClass, e);
}
boolean setterFound = false;
// if we get here, we could not find a String or Element setter.
for (Method m : objectClass.getMethods())
{
if (setter.equals(m.getName()))
{
Class paramTypes[] = m.getParameterTypes();
if (paramTypes.length != 1)
{
if (log.isTraceEnabled())
{
log.trace("Rejecting setter " + m + " on class " + objectClass + " due to incorrect number of parameters");
}
continue; // try another param with the same name.
}
Class parameterType = paramTypes[0];
PropertyEditor editor = PropertyEditorManager.findEditor(parameterType);
if (editor == null)
{
throw new ConfigurationException("Couldn't find a property editor for parameter type " + parameterType);
}
editor.setAsText((String) attribs.get(propName));
Object parameter = editor.getValue();
//if (log.isDebugEnabled()) log.debug("Invoking setter method: " + setter + " with parameter \"" + parameter + "\" of type " + parameter.getClass());
try
{
m.invoke(target, parameter);
setterFound = true;
break;
}
catch (Exception e)
{
throw new ConfigurationException("Unable to invoke setter " + setter + " on " + objectClass, e);
}
}
}
if (!setterFound && failOnMissingSetter)
{
throw new ConfigurationException("Couldn't find a setter named [" + setter + "] which takes a single parameter, for parameter " + propName + " on class [" + objectClass + "]");
}
}
}