Config schemaConfig = config.getConfig(schemaName); Bean bean; if (schema.getId().isSingleton()) { bean = Bean.create(BeanId.createSingleton(schema.getName())); constructBean(schemaConfig, schema, bean, schemas);
throw Events.CFG101_SCHEMA_NOT_EXIST(schemaName); if (refSchema.getId().isSingleton()) { BeanId id = BeanId.createSingleton(refSchema.getName()); Optional<Bean> optional = get(id, schemas);
public Bean toBean(Schema schema) { final BeanId id; if (schema.getId().isSingleton()) { id = BeanId.createSingleton(schema.getName()); } else {
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()); } }
@Override public Schema convert(Class<?> source, Class<? extends Schema> specificType) { ClassIntrospector introspector = new ClassIntrospector(source); Config config = introspector.getAnnotation(Config.class); if (config == null) { throw CFG102_NOT_CONFIGURABLE(source); } SchemaId schemaId = getId(introspector); if (schemaId == null) { // lookup instance does not have @Id annotations so we create // it from the @Config annotation schemaId = SchemaId.create(config.name(), config.desc(), true); } String schemaName = config.name(); if (schemaName == null || "".equals(schemaName)) { schemaName = source.getName(); } Schema schema = Schema.create(schemaId, introspector.getName(), schemaName, config.desc()); Collection<Object> fields = new ArrayList<>(); fields.addAll(introspector.getNonStaticFieldList()); Collection<AbstractSchemaProperty> props = conversion.convert(fields, AbstractSchemaProperty.class); for (AbstractSchemaProperty abstractProp : props) { schema.add(abstractProp); } return schema; }
public List<Bean> list(Schema schema, Map<String, Schema> schemas) { List<Bean> beans = new ArrayList<>(); Config schemaConfig; try { String schemaName = schema.getName().replaceAll("\\$", "\\."); schemaConfig = config.getConfig(schemaName); if (schemaConfig == null) { return beans; } } catch (Exception e) { return beans; } if (schema.getId().isSingleton()) { final Bean bean = Bean.create(BeanId.createSingleton(schema.getName())); beans.add(bean); constructBean(schemaConfig, schema, bean, schemas); } else { for (Object instanceId : schemaConfig.root().keySet()) { Config instance = schemaConfig.getConfig(instanceId.toString()); final Bean bean = Bean.create(BeanId.create(instanceId.toString(), schema.getName())); beans.add(bean); constructBean(instance, schema, bean, schemas); } } return beans; }
private SchemaId getId(ClassIntrospector introspector) { List<FieldWrap> ids = introspector.getFieldList(Id.class); boolean isSingleton = false; if (ids == null || ids.size() == 0) { return null; } else { FieldWrap id = ids.get(0); Id anno = (Id) id.getAnnotation().get(); if ((id.isStatic() && !id.isFinal()) || (id.isFinal() && !id.isStatic())) { throw CFG108_ILLEGAL_MODIFIERS(id.getField()); } String name = anno.name(); if (name == null || "".equals(name)) { name = id.getFieldName(); } return SchemaId.create(name, anno.desc(), isSingleton); } }
public Schema toSchema() { SchemaId id = SchemaId.create(idName, idDesc, singleton); Schema schema = Schema.create(id, className, schemaName, desc); for (SchemaProperty schemaProperty : property) { schema.add(schemaProperty.toSchema()); } for (SchemaPropertyList schemaPropertyList : propertyList) { schema.add(schemaPropertyList.toSchema()); } for (SchemaPropertyRef schemaPropertyRef : propertyRef) { schema.add(schemaPropertyRef.toSchema()); } for (SchemaPropertyRefList schemaPropertyRefList : propertyRefList) { schema.add(schemaPropertyRefList.toSchema()); } for (SchemaPropertyRefMap schemaPropertyRefMap : propertyRefMap) { schema.add(schemaPropertyRefMap.toSchema()); } return schema; }
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 lookup id: the field is static final valuesToInject.put(getIdField(instance.getClass()), source.getId().getInstanceId()); } inject(instance, valuesToInject); return instance; }
public static SchemaId create(final String name, final String desc, final boolean isSingleton) { return new SchemaId(name, desc, isSingleton); }
public static SchemaId create(final String name, final String desc, final boolean isSingleton) { return new SchemaId(name, desc, isSingleton); }