in java/ws-server/src/main/java/com/epam/deltix/tbwg/webapp/model/schema/SchemaBuilder.java [132:209]
public DataType getType(DataTypeDef typeDef) {
List<DataType> types = Arrays.stream(ALL_TYPES).filter(t -> t.getBaseName().equals(typeDef.getName())).collect(Collectors.toList());
if (types.size() == 0) {
// non-primitive type
ClassDescriptor rcd = getDescriptor(typeDef.getName());
if (rcd instanceof EnumClassDescriptor)
return new EnumDataType(typeDef.isNullable(), (EnumClassDescriptor) rcd);
else if (rcd instanceof RecordClassDescriptor)
return new ClassDataType(typeDef.isNullable(), (RecordClassDescriptor) rcd);
throw new IllegalArgumentException("Unknown type name: " + typeDef.getName());
}
DataType matched = types.get(0);
DataType type = null;
switch (matched.getCode()) {
case T_BINARY_TYPE:
type = BinaryDataType.getDefaultInstance();
break;
case T_BOOLEAN_TYPE:
type = new BooleanDataType(typeDef.isNullable());
break;
case T_CHAR_TYPE:
type = new CharDataType(typeDef.isNullable());
break;
case T_DATE_TIME_TYPE:
type = new DateTimeDataType(typeDef.isNullable());
break;
case T_FLOAT_TYPE:
type = new FloatDataType(typeDef.getEncoding(), typeDef.isNullable());
break;
case T_INTEGER_TYPE:
type = new IntegerDataType(typeDef.getEncoding(), typeDef.isNullable());
break;
case T_STRING_TYPE:
type = new VarcharDataType(typeDef.getEncoding(), typeDef.isNullable(), true); // always true
break;
case T_TIME_OF_DAY_TYPE:
type = new TimeOfDayDataType(typeDef.isNullable());
break;
case T_OBJECT_TYPE: {
List<RecordClassDescriptor> subtypes = new ArrayList<RecordClassDescriptor>();
if (typeDef.getTypes() == null || typeDef.getTypes().isEmpty())
throw new IllegalStateException("Expected not-nullable types: " + typeDef);
for (String typeDefType : typeDef.getTypes()) {
ClassDescriptor descriptor = getDescriptor(typeDefType);
if (descriptor instanceof RecordClassDescriptor)
subtypes.add((RecordClassDescriptor) descriptor);
else
throw new IllegalStateException("Expected RecordClassDescriptor, but found: " + descriptor);
}
type = new ClassDataType(typeDef.isNullable(), subtypes.toArray(new RecordClassDescriptor[subtypes.size()]));
break;
}
case T_ARRAY_TYPE: {
if (typeDef.getElementType() == null)
throw new IllegalStateException("Expected not-nullable elementType: " + typeDef);
type = new ArrayDataType(typeDef.isNullable(), getType(typeDef.getElementType()));
break;
}
case T_ENUM_TYPE: {
type = new EnumDataType(typeDef.isNullable(), (EnumClassDescriptor) getDescriptor(typeDef.getName()));
break;
}
default:
throw new IllegalArgumentException("Illegal type: " + matched);
}
return type;
}