// Bind beans
for (BeanBinding<?> beanBinding : bootstrap.bindings) {
// Get a binding key
Key key;
if (beanBinding.qualifiers != null && beanBinding.qualifiers.size() > 0) {
Iterator<Annotation> i = beanBinding.qualifiers.iterator();
// Construction to make compiler happy
// b = a.annotatedWith(i.next());
// while (i.hasNext()) {
// b = a.annotatedWith(i.next());
// }
key = Key.get(beanBinding.type, i.next());
}
else {
key = Key.get(beanBinding.type);
}
LinkedBindingBuilder b = bind(key);
//
ScopedBindingBuilder c;
if (beanBinding instanceof BeanBinding.ToInstance) {
BeanBinding.ToInstance d = (BeanBinding.ToInstance)beanBinding;
b.toInstance(d.instance);
c = b;
}
else if (beanBinding instanceof BeanBinding.ToProviderInstance) {
BeanBinding.ToProviderInstance d = (BeanBinding.ToProviderInstance)beanBinding;
c = b.toProvider(d);
if (beanBinding.scopeType != null) {
c.in(beanBinding.scopeType);
}
}
else {
if (beanBinding instanceof BeanBinding.ToProviderType) {
BeanBinding.ToProviderType d = (BeanBinding.ToProviderType)beanBinding;
c = b.toProvider(d.provider);
}
else {
BeanBinding.ToType d = (BeanBinding.ToType)beanBinding;
if (d.qualifiers != null) {
if (d.implementationType != null) {
c = b.to(d.implementationType);
// Guice trick : need to bind alias so the implementation type will be bound with the qualifier
bind(Key.get(d.implementationType, key.getAnnotation())).toProvider(new BeanAlias(key));
}
else {
c = b.to(beanBinding.type);
}
}
else {
if (d.implementationType != null) {
c = b.to(d.implementationType);
}
else {
c = b;
}
}
}
if (beanBinding.scopeType != null) {
c.in(beanBinding.scopeType);
}
}
}
// Bind the manager itself
bind(InjectionContext.class).toInstance(GuiceContext.this);
}
private <T> void bind(Class<T> clazz, T instance) {
bind(clazz).toInstance(instance);
}
};
//
Map<String, Key<?>> nameMap = new HashMap<String, Key<?>>();
Injector injector = Guice.createInjector(module);
for (Key<?> key : injector.getBindings().keySet()) {
Class<? extends Annotation> annotationType = key.getAnnotationType();
if (annotationType != null && Named.class.isAssignableFrom(annotationType)) {
Named named = (Named)key.getAnnotation();
nameMap.put(named.value(), key);
}
}
//