public void configure(final Binder binder) { for (final SpaceIndexItem<Extension, Object> item : SpaceIndex.load(Extension.class, Object.class, space, globalIndex)) { try { // ignore the legacy SezPoz ExtensionFinder if (!Sezpoz.class.equals(item.element())) { bindItem(binder, item); } } catch (final Throwable e) { if (item.annotation().optional()) { log.debug("Failed to bind optional extension: {}", item, e); } else { log.warn("Failed to bind extension: {}", item, e); } } } }
private void bindItem(final Binder binder, final SpaceIndexItem<Extension, ?> item) throws InstantiationException { switch (item.kind()) { case TYPE: { final Class impl = (Class) item.element(); binder.bind(impl).in(Scopes.SINGLETON); bindHierarchy(binder, Key.get(impl)); break; } case METHOD: { final Method method = (Method) item.element(); final String name = method.getDeclaringClass().getName() + '.' + method.getName(); final ExtensionQualifier qualifier = new ExtensionQualifierImpl(item.annotation(), name); bindProvider(binder, item, Key.get(method.getReturnType(), qualifier)); break; } case FIELD: { final Field field = (Field) item.element(); final String name = field.getDeclaringClass().getName() + '.' + field.getName(); final ExtensionQualifier qualifier = new ExtensionQualifierImpl(item.annotation(), name); bindProvider(binder, item, Key.get(field.getType(), qualifier)); break; } default: break; } }