Search in sources :

Example 1 with ComplexDataSchema

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;
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) CustomInfoSpec(com.linkedin.pegasus.generator.spec.CustomInfoSpec) ComplexDataSchema(com.linkedin.data.schema.ComplexDataSchema)

Aggregations

ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)1 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)1 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)1 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)1 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)1 ClassTemplateSpec (com.linkedin.pegasus.generator.spec.ClassTemplateSpec)1 CustomInfoSpec (com.linkedin.pegasus.generator.spec.CustomInfoSpec)1