public final <T> Iterable<BeanLifeCycle<T>> resolve(final Class<T> type) { final Iterable<B> a = resolveBeans(type); return new Iterable<BeanLifeCycle<T>>() { public Iterator<BeanLifeCycle<T>> iterator() { return new Iterator<BeanLifeCycle<T>>() { final Iterator<B> i = a.iterator(); public boolean hasNext() { return i.hasNext(); } public BeanLifeCycle<T> next() { B b = i.next(); return new BeanLifeCycleImpl<B, C,T>(type, InjectionContext.this, b); } public void remove() { throw new UnsupportedOperationException(); } }; } }; }
public final <T> Iterable<BeanLifeCycle<T>> resolve(final Class<T> type) { final Iterable<B> a = resolveBeans(type); return new Iterable<BeanLifeCycle<T>>() { public Iterator<BeanLifeCycle<T>> iterator() { return new Iterator<BeanLifeCycle<T>>() { final Iterator<B> i = a.iterator(); public boolean hasNext() { return i.hasNext(); } public BeanLifeCycle<T> next() { B b = i.next(); return new BeanLifeCycleImpl<B, C,T>(type, InjectionContext.this, b); } public void remove() { throw new UnsupportedOperationException(); } }; } }; }
private void injectRealms(JSON config, SecurityManager currentManager, InjectionContext manager) throws InvocationTargetException { JSON realmsJSON = config.getJSON("realms"); Iterable beans = manager.resolveBeans(AuthorizingRealm.class); for (Object bean : beans) { Object instance = manager.createContext(bean); AuthorizingRealm realm = AuthorizingRealm.class.cast(manager.getInstance(bean, instance)); JSON realmJSON = realmsJSON.getJSON(realm.getClass().getName()); if (realmJSON != null) { if (realmJSON.get("name") != null) { realm.setName(realmJSON.getString("name")); } Collection<Realm> realms = ((RealmSecurityManager)currentManager).getRealms(); if (realms == null) { ((RealmSecurityManager)currentManager).setRealm(realm); } else { ((RealmSecurityManager)currentManager).getRealms().add(realm); } } } } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Bean1.class, null, null, null); bootstrap.declareBean(Bean2.class, null, null, null); boot(); // ArrayList<B> beans = Tools.list(mgr.resolveBeans(AbstractBean.class)); assertEquals(2, beans.size()); HashSet<Class<?>> classes = new HashSet<Class<?>>(); for (B bean : beans) { I instance = mgr.createContext(bean); Object o = mgr.getInstance(bean, instance); classes.add(o.getClass()); } assertEquals(Tools.<Class<?>>set(Bean1.class, Bean2.class), classes); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Bean1.class, null, null, null); bootstrap.declareBean(Bean2.class, null, null, null); boot(); // ArrayList<B> beans = Tools.list(mgr.resolveBeans(AbstractBean.class)); assertEquals(2, beans.size()); HashSet<Class<?>> classes = new HashSet<Class<?>>(); for (B bean : beans) { I instance = mgr.createContext(bean); Object o = mgr.getInstance(bean, instance); classes.add(o.getClass()); } assertEquals(Tools.<Class<?>>set(Bean1.class, Bean2.class), classes); } }