public BindHandler createHandler(Annotation annotation, Method getterMethod, Converter converter, ConversionHandler conversionHandler)
{
BindSelect bindAnnotation = (BindSelect) annotation;
BindSelectHandler handler = new BindSelectHandler();
String expression = bindAnnotation.targetBeanExpression();
handler.setTargetBeanExpression(expression);
String beanLocatingExpression = null;
String propertyName = null;
int lastDot = expression.lastIndexOf('.');
if (lastDot == -1)
{
propertyName = expression;
}
else
{
beanLocatingExpression = expression.substring(0, lastDot);
propertyName = expression.substring(lastDot + 1);
}
handler.setBeanLocatingExpression(beanLocatingExpression);
handler.setBeanPropertyName(propertyName);
handler.setBeanPropertyClass(bindAnnotation.idClass());
handler.setBeanLookupExpression(bindAnnotation.lookupMapExpression());
handler.setBeanPropertyIdName(bindAnnotation.targetBeanIdProperty());
if (converter != null)
{
handler.setConverter(converter);
}
else
{
Class<? extends Converter> converterClass = bindAnnotation.idConverter();
converter = ReflectHelper.createInstance(converterClass, Converter.class);
converter.setTargetClass(bindAnnotation.idClass());
handler.setConverter(converter);
}
PropertyDescriptor property = BeanUtils.findPropertyForMethod(getterMethod);
if (property == null)
{
throw new ApplicationConfigurationException("Method " + getterMethod + " is not a valid JavaBean property");
}
handler.setPropertyDescriptor(property);
handler.setConversionHandler(conversionHandler);
return handler;
}