String name = "configName" + i; String desc = "configDesc" + i; SchemaId id = SchemaId.create("configId" + i, "configDesc" + i, false); Schema schema = Schema.create(id, type, name, desc); for (int j = 0; j < numProps; j++) {
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); } }
@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) { // get 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 Map<String, Schema> getSchemas() { Map<String, Schema> result = new HashMap<String, Schema>(); for (XmlSchema b : schemas) { Schema schema = Schema.create( SchemaId.create(b.id.name, b.id.desc, b.id.singleton), b.type, b.name, b.desc); for (XmlSchemaProperty p : b.properties) { schema.add(SchemaProperty.create(p.name, p.fieldName, p.type, p.desc, p.isImmutable, p.isEnum, p.defaultValue)); } for (XmlSchemaCollection p : b.collection) { schema.add(SchemaPropertyList.create(p.name, p.fieldName, p.parameterizedType, p.desc, p.isImmutable, p.isEnum, p.defaultValues, p.collectionType)); } for (XmlSchemaRef p : b.ref) { schema.add(SchemaPropertyRef.create(p.name, p.fieldName, p.schemaName, p.desc, p.isImmutable, p.isSingleton)); } for (XmlSchemaRefCollection p : b.refCollection) { schema.add(SchemaPropertyRefList.create(p.name, p.fieldName, p.schemaName, p.desc, p.isImmutable, p.collectionType)); } for (XmlSchemaRefMap p : b.refMap) { schema.add(SchemaPropertyRefMap.create(p.name, p.fieldName, p.schemaName, p.desc, p.isImmutable, p.mapType)); } result.put(schema.getName(), schema); } return result; }
private SchemaId getId(ClassIntrospector introspector) { List<FieldWrap<Id>> ids = introspector.getFieldList(Id.class); if (ids == null || ids.size() == 0) { throw CFG103_NO_ID(introspector.getTarget()); } FieldWrap<Id> id = ids.get(0); if ((id.isStatic() && !id.isFinal()) || (id.isFinal() && !id.isStatic())) { throw CFG108_ILLEGAL_MODIFIERS(id.getAnnotation().name()); } boolean isSingleton = false; if (id.isFinal()) { isSingleton = true; } String name = id.getAnnotation().name(); if (name == null || "".equals(name)) { name = id.getFieldName(); } SchemaId schemaId = SchemaId.create(name, id.getAnnotation().desc(), isSingleton); return schemaId; } }