private void setSingletonReferences(Bean bean) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemaManager.getSchema(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()); bean.setReference(ref.getName(), singletonId); } } }
private void setSingletonReferences(Bean bean) { Schema s = bean.getSchema(); for (SchemaPropertyRef ref : s.get(SchemaPropertyRef.class)) { if (ref.isSingleton()) { Schema singletonSchema = schemaManager.getSchema(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()); bean.setReference(ref.getName(), singletonId); } } } }
public JaxrsSchema(Schema schema) { this.schemaName = schema.getName(); this.className = schema.getType(); this.desc = schema.getDesc(); this.idName = schema.getId().getName(); this.idDesc = schema.getId().getDesc(); this.singleton = schema.getId().isSingleton(); for (Schema.SchemaProperty prop : schema.get(Schema.SchemaProperty.class)) { property.add(new SchemaProperty(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyList prop : schema.get(Schema.SchemaPropertyList.class)) { propertyList.add(new SchemaPropertyList(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRef prop : schema.get(Schema.SchemaPropertyRef.class)) { propertyRef.add(new SchemaPropertyRef(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRefList prop : schema.get(Schema.SchemaPropertyRefList.class)) { propertyRefList.add(new SchemaPropertyRefList(prop)); propertyNames.add(prop.getName()); } for (Schema.SchemaPropertyRefMap prop : schema.get(Schema.SchemaPropertyRefMap.class)) { propertyRefMap.add(new SchemaPropertyRefMap(prop)); propertyNames.add(prop.getName()); } }
private void convertPropertyRef(Bean source, Map<String, Object> values, Map<BeanId, Object> instanceCache) { for (SchemaPropertyRef prop : source.getSchema().get(SchemaPropertyRef.class)) { BeanId id = source.getFirstReference(prop.getName()); if (id == null) { continue; } Bean ref = id.getBean(); if (ref == null) { continue; } Schema refSchema = ref.getSchema(); if (refSchema == null) { throw Events.CFG101_SCHEMA_NOT_EXIST(ref.getId().getSchemaName()); } SchemaPropertyRef schemaRef = source.getSchema().get(SchemaPropertyRef.class, prop.getName()); Object beanInstance = instanceCache.get(id); if (beanInstance == null) { try { beanInstance = newInstance(loadClass(refSchema.getType())); } catch (Exception e) { throw new UnsupportedOperationException(e); } beanInstance = convert(ref, beanInstance, new HashMap<String, Object>(), instanceCache); } values.put(schemaRef.getFieldName(), beanInstance); } }