@Test public void test_singleton_file_fallback() throws Exception { SingletonParent singletonParent = config.get(SingletonParent.class); assertNotNull(singletonParent); assertThat(singletonParent.getProperty(), is(SINGLETON_PARENT_SCHEMA_NAME)); Singleton singleton = singletonParent.getSingleton(); assertNotNull(singleton); assertThat(singleton.getProperty(), is(SINGLETON_SCHEMA_NAME)); Parent p10 = singleton.getParent(); assertThat(p10.getProp1(), is("p10")); List<Child> children = p10.getProp7(); assertNotNull(children); assertThat(children.size(), is(1)); Child child = children.get(0); assertThat(child.getBeanId().getInstanceId(), is("c10")); assertThat(child.getProp11(), is(1.1f)); }
@Override public <T> T get(Class<T> configurable) { doLookup(); Schema schema = schemaManager.getSchema(configurable); BeanId singleton = getSingletonId(schema, configurable); Optional<Bean> bean; try { if (configurable.getName().equals(RECURSION_SHORTCIRCUIT.get())) { bean = Optional.absent(); } else { RECURSION_SHORTCIRCUIT.set(configurable.getName()); bean = beanManager.getEager(singleton); } } finally { RECURSION_SHORTCIRCUIT.set(null); } if (!bean.isPresent()) { initFile(configurable); Bean fileBean = FILE_CONFIG.get(singleton); if (fileBean != null) { fileBean.set(schema); bean = Optional.of(fileBean); } if (bean.isPresent()) { T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; } } if (!bean.isPresent()) { bean = Optional.of(Bean.create(BeanId.createSingleton(schema.getName()))); } schemaManager.setSchema(Arrays.asList(bean.get())); setSingletonReferences(bean.get()); T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; }
ConfigCoreContext extends ConfigContext { @Override public <T> T get(Class<T> configurable) { doLookup(); Schema schema = schemaManager.getSchema(configurable); BeanId singleton = getSingletonId(schema, configurable); Optional<Bean> bean; try { if (configurable.getName().equals(RECURSION_SHORTCIRCUIT.get())) { bean = Optional.absent(); } else { RECURSION_SHORTCIRCUIT.set(configurable.getName()); bean = beanManager.getEager(singleton); } } finally { RECURSION_SHORTCIRCUIT.set(null); } if (!bean.isPresent()) { initFile(configurable); Bean fileBean = FILE_CONFIG.get(singleton); if (fileBean != null) { fileBean.set(schema); bean = Optional.of(fileBean); } if (bean.isPresent()) { T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; } } if (!bean.isPresent()) { bean = Optional.of(Bean.create(BeanId.createSingleton(schema.getName()))); } schemaManager.setSchema(Arrays.asList(bean.get())); setSingletonReferences(bean.get()); T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; } }
ConfigCoreContext extends ConfigContext { @Override public <T> T get(Class<T> configurable) { doLookup(); Schema schema = schemaManager.getSchema(configurable); BeanId singleton = getSingletonId(schema, configurable); Optional<Bean> bean; try { if (configurable.getName().equals(RECURSION_SHORTCIRCUIT.get())) { bean = Optional.absent(); } else { RECURSION_SHORTCIRCUIT.set(configurable.getName()); bean = beanManager.getEager(singleton); } } finally { RECURSION_SHORTCIRCUIT.set(null); } if (!bean.isPresent()) { initFile(configurable); Bean fileBean = FILE_CONFIG.get(singleton); if (fileBean != null) { fileBean.set(schema); bean = Optional.of(fileBean); } if (bean.isPresent()) { T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; } } if (!bean.isPresent()) { bean = Optional.of(Bean.create(BeanId.createSingleton(schema.getName()))); } schemaManager.setSchema(Arrays.asList(bean.get())); setSingletonReferences(bean.get()); T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; }  }
ConfigCoreContext extends ConfigContext { @Override public <T> T get(Class<T> configurable) { doLookup(); Schema schema = schemaManager.getSchema(configurable); BeanId singleton = getSingletonId(schema, configurable); Optional<Bean> bean; try { if (configurable.getName().equals(RECURSION_SHORTCIRCUIT.get())) { bean = Optional.absent(); } else { RECURSION_SHORTCIRCUIT.set(configurable.getName()); bean = beanManager.getEager(singleton); } } finally { RECURSION_SHORTCIRCUIT.set(null); } if (!bean.isPresent()) { initFile(configurable); Bean fileBean = FILE_CONFIG.get(singleton); if (fileBean != null) { fileBean.set(schema); bean = Optional.of(fileBean); } if (bean.isPresent()) { T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; } } if (!bean.isPresent()) { bean = Optional.of(Bean.create(BeanId.createSingleton(schema.getName()))); } schemaManager.setSchema(Arrays.asList(bean.get())); setSingletonReferences(bean.get()); T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; }  @Override void register(Class<?>... configurable); @Override void unregister(Class<?>... configurable); @Override T get(Class<T> configurable); @Override List<T> list(Class<T> configurable); @Override Optional<T> get(String id, Class<T> configurable); @Override ConfigQuery<T> newQuery(Class<T> configurable); @Override void registerObserver(ConfigObserver observer); void doLookup(); }
ConfigCoreContext extends ConfigContext { @Override public <T> T get(Class<T> configurable) { doLookup(); Schema schema = schemaManager.getSchema(configurable); BeanId singleton = getSingletonId(schema, configurable); Optional<Bean> bean; try { if (configurable.getName().equals(RECURSION_SHORTCIRCUIT.get())) { bean = Optional.absent(); } else { RECURSION_SHORTCIRCUIT.set(configurable.getName()); bean = beanManager.getEager(singleton); } } finally { RECURSION_SHORTCIRCUIT.set(null); } if (!bean.isPresent()) { initFile(configurable); Bean fileBean = FILE_CONFIG.get(singleton); if (fileBean != null) { fileBean.set(schema); bean = Optional.of(fileBean); } if (bean.isPresent()) { T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; } } if (!bean.isPresent()) { bean = Optional.of(Bean.create(BeanId.createSingleton(schema.getName()))); } schemaManager.setSchema(Arrays.asList(bean.get())); setSingletonReferences(bean.get()); T object = (T) schemaManager.convertBean(bean.get()); if (cacheManager.isPresent()) { cacheManager.get().put(bean.get()); } return object; }  @Override void register(Class<?>... configurable); @Override void unregister(Class<?>... configurable); @Override T get(Class<T> configurable); @Override List<T> list(Class<T> configurable); @Override Optional<T> get(String id, Class<T> configurable); @Override ConfigQuery<T> newQuery(Class<T> configurable); @Override void registerObserver(ConfigObserver observer); void doLookup();  }