List of usage examples for org.springframework.beans.factory.support SimpleAutowireCandidateResolver SimpleAutowireCandidateResolver
SimpleAutowireCandidateResolver
From source file:org.openvpms.web.component.im.table.IMObjectTableModelFactory.java
/** * Helper to create a new table model./*from ww w .j av a 2 s.c o m*/ * * @param handler the archetype handler * @param shortNames the archetype short names. May be {@code null} * @param query the query. May be {@code null} * @param parent the parent object * @param context the layout context * @return a new table model, or {@code null} if there is no valid constructor */ @SuppressWarnings("unchecked") private static <T extends IMObject> IMObjectTableModel<T> construct( ArchetypeHandler<IMObjectTableModel<T>> handler, final String[] shortNames, Query<T> query, final IMObject parent, LayoutContext context) { Class type = handler.getType(); DefaultListableBeanFactory factory = new DefaultListableBeanFactory(); // Spring doesn't automatically autowire the shortNames array when it is registered as a singleton, so need to // register the following to handle it explicitly factory.setAutowireCandidateResolver(new SimpleAutowireCandidateResolver() { @Override public Object getSuggestedValue(DependencyDescriptor descriptor) { if (String[].class.equals(descriptor.getDependencyType())) { return shortNames; } return super.getSuggestedValue(descriptor); } }); if (query != null) { factory.registerSingleton("query", query); } if (parent != null) { factory.registerSingleton("parent", parent); } if (context != null) { factory.registerSingleton("context", context); } try { IMObjectTableModel<T> result = (IMObjectTableModel<T>) factory.createBean(type, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false); handler.initialise(result); return result; } catch (Throwable exception) { log.error(exception, exception); } return null; }