private Object convert(Bean source, Object instance, Map<String, Object> valuesToInject, Map<BeanId, Object> instanceCache) { instanceCache.put(source.getId(), instance); convertProperty(source, valuesToInject); convertPropertyList(source, valuesToInject); convertPropertyRef(source, valuesToInject, instanceCache); convertPropertyRefList(source, valuesToInject, instanceCache); convertPropertyRefMap(source, valuesToInject, instanceCache); Schema schema = source.getSchema(); if (!schema.getId().isSingleton()) { // do not try to inject get id: the field is static final valuesToInject.put(getIdField(instance.getClass()), source.getId().getInstanceId()); } inject(instance, valuesToInject); return instance; }
public XmlSchema(Schema bean) { this.id = new XmlSchemaId(bean.getId()); this.name = bean.getName(); this.type = bean.getType(); this.desc = bean.getDesc(); for (SchemaProperty p : bean.get(SchemaProperty.class)) { properties.add(new XmlSchemaProperty(p)); } for (SchemaPropertyList p : bean.get(SchemaPropertyList.class)) { collection.add(new XmlSchemaCollection(p)); } for (SchemaPropertyRef p : bean.get(SchemaPropertyRef.class)) { ref.add(new XmlSchemaRef(p)); } for (SchemaPropertyRefList p : bean.get(SchemaPropertyRefList.class)) { refCollection.add(new XmlSchemaRefCollection(p)); } for (SchemaPropertyRefMap p : bean.get(SchemaPropertyRefMap.class)) { refMap.add(new XmlSchemaRefMap(p)); } } }
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; }
private Optional<Bean> get(BeanId beanId) { Schema schema = schemas.get(beanId.getSchemaName()); if (schema == null) { throw Events.CFG101_SCHEMA_NOT_EXIST(beanId.getSchemaName()); } Map<String, Map<String, Object>> instances = (Map) config.getAnyRef(schema.getName()); try { final Bean bean; if (schema.getId().isSingleton()) { bean = Bean.create(BeanId.createSingleton(schema.getName())); constructBean((Map) instances, schema, bean); } else { if (instances == null) { return Optional.absent(); } bean = Bean.create(beanId); Map<String, Object> properties = instances.get(beanId.getInstanceId()); constructBean(properties, schema, bean); } return Optional.of(bean); } catch (ConfigException e) { return Optional.absent(); } }
private Object convert(Bean source, Object instance, Map<String, Object> valuesToInject, Map<BeanId, Object> instanceCache) { instanceCache.put(source.getId(), instance); convertProperty(source, valuesToInject); convertPropertyList(source, valuesToInject); convertPropertyRef(source, valuesToInject, instanceCache); convertPropertyRefList(source, valuesToInject, instanceCache); convertPropertyRefMap(source, valuesToInject, instanceCache); Schema schema = source.getSchema(); if (!schema.getId().isSingleton()) { // do not try to inject singleton id: the field is static final valuesToInject.put(getIdField(instance.getClass()), source.getId().getInstanceId()); } inject(instance, valuesToInject); return instance; }
@Override public void register(Class<?>... configurable) { doLookup(); for (Class<?> clazz : configurable) { Schema schema = conversion.convert(clazz, Schema.class); schemaManager.regsiterSchema(schema); if (schema.getId().isSingleton()) { beanManager.createSingleton(getSingletonId(schema, clazz)); } // ok to not have validation manager available if (validationManager != null) { validationManager.register(schema.getName(), clazz); } } }
Object value = properties.get(propertyName); Schema refSchema = schemas.get(schema.getReferenceSchemaName(propertyName)); if (refSchema.getId().isSingleton()) { BeanId id = BeanId.createSingleton(refSchema.getName()); Optional<Bean> optional = get(id);