private BeanId getRecursiveBeanId(Object bean) { BeanId targetId = getBeanId(bean); Bean targetBean = conversion.convert(bean, Bean.class); targetBean.set(conversion.convert(bean.getClass(), Schema.class)); targetId.setBean(targetBean); return targetId; } }
private void setSingletonReferences(Bean bean, Map<String, Schema> schemas) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemas.get(ref.getSchemaName()); Optional<Bean> singleton = beanManager.getSingleton(ref.getSchemaName()); if (singleton.isPresent()) { singleton.get().set(singletonSchema); BeanId singletonId = singleton.get().getId(); singletonId.setBean(singleton.get()); // recursive call. setSingletonReferences(singleton.get(), schemas); bean.setReference(ref.getName(), singletonId); } } } }
private void setSingletonReferences(Bean bean, Map<String, Schema> schemas) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemas.get(ref.getSchemaName()); Optional<Bean> singleton = beanManager.getSingleton(ref.getSchemaName()); if (!singleton.isPresent()) { initFile(null); Bean fileBean = FILE_CONFIG.get(BeanId.createSingleton(ref.getSchemaName())); if (fileBean != null) { singleton = Optional.of(fileBean); } } if (!singleton.isPresent()) { singleton = Optional.of(Bean.create(BeanId.createSingleton(ref.getSchemaName()))); } singleton.get().set(singletonSchema); BeanId singletonId = singleton.get().getId(); singletonId.setBean(singleton.get()); // recursive call. setSingletonReferences(singleton.get(), schemas); bean.setReference(ref.getName(), singletonId); } } }
@Override public <T> T get(Class<T> configurable) { doLookup(); Schema schema = getSchema(configurable); BeanId singleton = getSingletonId(schema, configurable); Optional<Bean> bean = beanManager.getEager(singleton); 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 = conversion.convert(bean.get(), configurable); core.cache(bean.get()); return object; } } if (!bean.isPresent()) { bean = Optional.of(Bean.create(BeanId.createSingleton(schema.getName()))); } core.setSchema(bean.get(), schemas); setSingletonReferences(bean.get(), schemas); T object = conversion.convert(bean.get(), configurable); core.cache(bean.get()); return object; }
private void setSingletonReferences(Bean bean, Map<String, Schema> schemas) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemas.get(ref.getSchemaName()); Bean singleton = beanManager.getSingleton(ref.getSchemaName()); singleton.set(singletonSchema); BeanId singletonId = singleton.getId(); singletonId.setBean(singleton); // recursive call. setSingletonReferences(singleton, schemas); bean.setReference(ref.getName(), singletonId); } } }
@Override public Bean convert(Object source, Class<? extends Bean> specificType) { ClassIntrospector i = new ClassIntrospector(source.getClass()); Bean bean = Bean.create(getBeanId(source)); for (FieldWrap field : i.getNonStaticFieldList()) { field.checkNotPublic(); Object value = field.getValue(source); if (value == null) { continue; } addProperty(value, bean, field); } Schema schema = conversion.convert(source.getClass(), Schema.class); bean.set(schema); return bean; }
private void setSingletonReferences(Bean bean, Map<String, Schema> schemas) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemas.get(ref.getSchemaName()); Bean singleton = beanManager.getSingleton(ref.getSchemaName()); singleton.set(singletonSchema); BeanId singletonId = singleton.getId(); singletonId.setBean(singleton); // recursive call. setSingletonReferences(singleton, schemas); bean.setReference(ref.getName(), singletonId); } } }
public List<Bean> list(Schema schema) { List<Bean> beans = new ArrayList<>(); Map<String, Map<String, Object>> instances; try { instances = (Map) config.getAnyRef(schema.getName()); if (instances == null) { return beans; } } catch (ConfigException e) { return beans; } if (schema.getId().isSingleton()) { final Bean bean = Bean.create(BeanId.createSingleton(schema.getName())); Map<String, Object> properties = (Map) instances; beans.add(bean); constructBean(properties, schema, bean); } else { for (String instanceId : instances.keySet()) { final Map<String, Object> properties = instances.get(instanceId); final Bean bean = Bean.create(BeanId.create(instanceId, schema.getName())); bean.set(schema); beans.add(bean); constructBean(properties, schema, bean); } } return beans; }
public void setSchema(Bean b, Map<String, Schema> schemas) { Schema s = schemas.get(b.getId().getSchemaName()); if (s == null) { throw CFG101_SCHEMA_NOT_EXIST(b.getId().getSchemaName()); } b.set(s); for (BeanId id : b.getReferences()) { Bean ref = id.getBean(); if (ref != null && ref.getSchema() == null) { setSchema(ref, schemas); } } }
private void constructBean(Map<String, Object> properties, Schema schema, Bean bean) { bean.set(schemas.get(bean.getId().getSchemaName())); for (String propertyName : schema.getPropertyNames()) { Object value = properties.get(propertyName); b.set(schemas.get(b.getId().getSchemaName())); id.setBean(b); bean.addReference(propertyName, id); b.set(schemas.get(b.getId().getSchemaName())); beanId.setBean(b); beanIds.add(beanId); b.set(schemas.get(b.getId().getSchemaName())); id.setBean(b); bean.addReference(propertyName, id);
public static void setSchema(Bean b, Map<String, Schema> schemas) { Schema s = schemas.get(b.getId().getSchemaName()); if (s == null) { throw CFG101_SCHEMA_NOT_EXIST(b.getId().getSchemaName()); } b.set(s); for (BeanId id : b.getReferences()) { Bean ref = id.getBean(); if (ref != null && ref.getSchema() == null) { setSchema(ref, schemas); } } }
@Override public <T> T singleton(Class<T> configurable) { doLookup(); Schema schema = conversion.convert(configurable, Schema.class); BeanId singleton = getSingletonId(schema, configurable); Map<String, Schema> schemas = schemaManager.getSchemas(); Bean bean = beanManager.getEager(singleton); bean.set(schema); setSingletonReferences(bean, schemas); return conversion.convert(bean, configurable); }