use of com.linkedin.data.schema.ComplexDataSchema in project rest.li by linkedin.
the class TemplateSpecGenerator method processSchema.
private ClassTemplateSpec processSchema(DataSchema schema, ClassTemplateSpec enclosingClass, String memberName) {
final CustomInfoSpec customInfo = getImmediateCustomInfo(schema);
ClassTemplateSpec result = null;
TyperefDataSchema originalTyperefSchema = null;
while (schema.getType() == DataSchema.Type.TYPEREF) {
final TyperefDataSchema typerefSchema = (TyperefDataSchema) schema;
if (originalTyperefSchema == null) {
originalTyperefSchema = typerefSchema;
}
final ClassTemplateSpec found = _schemaToClassMap.get(schema);
schema = typerefSchema.getRef();
if (found == null) {
if (schema.getType() == DataSchema.Type.UNION) {
result = generateUnion((UnionDataSchema) schema, typerefSchema);
break;
} else {
generateTyperef(typerefSchema, originalTyperefSchema);
}
} else if (schema.getType() == DataSchema.Type.UNION) {
result = found;
break;
}
}
if (result == null) {
assert schema == schema.getDereferencedDataSchema();
if (schema instanceof ComplexDataSchema) {
final ClassTemplateSpec found = _schemaToClassMap.get(schema);
if (found == null) {
if (schema instanceof NamedDataSchema) {
result = generateNamedSchema((NamedDataSchema) schema);
} else {
result = generateUnnamedComplexSchema(schema, enclosingClass, memberName);
}
} else {
result = found;
}
if (customInfo != null) {
result = customInfo.getCustomClass();
}
} else if (schema instanceof PrimitiveDataSchema) {
result = (customInfo != null) ? customInfo.getCustomClass() : getPrimitiveClassForSchema((PrimitiveDataSchema) schema, enclosingClass, memberName);
}
}
if (result == null) {
throw unrecognizedSchemaType(enclosingClass, memberName, schema);
}
result.setOriginalTyperefSchema(originalTyperefSchema);
return result;
}
Aggregations