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) { // 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 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; }