/** Adds an alias so that a component with the * given name is also available as the given alias. */ protected void alias(String name, Class<?>... types) { if (types!=null) { for (Class<?> serviceType: types) { alias(serviceType.getName(), name); Class< ? > superclass = serviceType.getSuperclass(); if (superclass!=null && superclass!=Object.class) { alias(name, superclass); } alias(name, serviceType.getInterfaces()); } } }
/** Puts an initialized component into the brewery. * It will be possible to lookup this component by all it's * superclasses and interfaces it implements. * @throws RuntimeException if component is null */ public void beer(Object component) { Exceptions.checkNotNullParameter(component, "component"); String name = component.getClass().getName(); alias(name, component.getClass()); beer(component, name); }
/** Adds an uninitialized component to the brewery. * It will be possible to lookup this component by all it's * superclasses and interfaces it implements. * @throws RuntimeException if component is null */ public void ingredient(Object component) { Exceptions.checkNotNullParameter(component, "component"); String name = component.getClass().getName(); alias(name, component.getClass()); ingredient(component, name); if (component instanceof Stoppable) { addStoppable((Stoppable) component); } }
/** Adds a factory to the brewery that will be able to * create components when it's requested by type. * @throws RuntimeException if supplier is null * @throws RuntimeException if type is null */ public void supplier(Supplier supplier, Class<?> type) { Exceptions.checkNotNullParameter(supplier, "supplier"); Exceptions.checkNotNullParameter(type, "type"); String name = type.getName(); alias(name, type); supplier(supplier, name); }