You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Karl Kildén <ka...@gmail.com> on 2015/03/06 22:48:14 UTC

PostBind method for DocumentObjectBinder?

Hello,

DocumentObjectBinder would benefit from a post bind call imo. Something
like:

  public <T> List<T> getBeans(Class<T> clazz, SolrDocumentList solrDocList,
boolean postBind) {
    List<DocField> fields = getDocFields(clazz);
    List<T> result = new ArrayList<>(solrDocList.size());

    for (SolrDocument sdoc : solrDocList) {
      T bean = getBean(clazz, fields, sdoc);
      if (postBind) {
          runAnnotatedMethod(bean, PostBind.class);
      }
result.add(bean);
    }
    return result;
  }
private void runAnnotatedMethod(final Object instance, Class<? extends
Annotation> annotation) {
for (Method m : instance.getClass().getDeclaredMethods()) {
if (m.isAnnotationPresent(annotation)) {
m.setAccessible(true);
try {
m.invoke(instance, new Object[] {});
} catch (Exception e) {
throw new BindingException("Could not run postbind " + instance.getClass(),
e);
}
}
}
}


Can probably take some thinking on how to do the API pretty staying
backwards compatible and the found annotated method should be cached.

WDYT?