protected void copyAccessors(Schema schema) { SchemaFactory parentSchemaFactory = schemaFactory; Class<?> clz = parentSchemaFactory.getSchemaClass(schema.getId()); if (clz == null) { return; } schemaClasses.put(schema.getId().toLowerCase(), clz); Schema parentSchema = parentSchemaFactory.getSchema(clz); for (Map.Entry<String, Field> entry : schema.getResourceFields().entrySet()) { ((FieldImpl) entry.getValue()).setName(entry.getKey()); Field parentField = parentSchema.getResourceFields().get(entry.getKey()); if (parentField == null || !(parentField instanceof FieldImpl)) { continue; } ((FieldImpl) entry.getValue()).setReadMethod(((FieldImpl) parentField).getReadMethod()); } }
protected void addField(SchemaImpl schema, String name, FieldType type, String... options) { Field f = schema.getResourceFields().get(name); if (f != null) { return; } FieldImpl newField = new FieldImpl(); newField.setTypeEnum(type); newField.setName(name); if (type == FieldType.ENUM) { newField.setOptions(Arrays.asList(options)); } else { newField.setNullable(true); } schema.getResourceFields().put(name, newField); }
@Override public Schema parseSchema(String name) { SchemaImpl schema = readSchema(name); Class<?> clz = typeToClass.get(name); processParent(schema); List<Field> fields = getFields(clz); for (Map.Entry<String, Field> entry : schema.getResourceFields().entrySet()) { Field field = entry.getValue(); if (field instanceof FieldImpl) { ((FieldImpl)field).setName(entry.getKey()); } fields.add(field); } Map<String, Field> resourceFields = sortFields(fields); schema.setResourceFields(resourceFields); schema.getResourceActions().putAll(getResourceActions(clz)); schema.getCollectionActions().putAll(getCollectionActions(clz)); for (SchemaPostProcessor processor : postProcessors) { schema = processor.postProcess(schema, this); } addToMap(schemasByName, schema, schema); if (clz == null && schema.getParent() != null) { clz = typeToClass.get(schema.getParent()); if (clz != null) { addToMap(typeToClass, schema, clz); } } return schema; }