use of org.mule.metadata.api.model.NumberType in project mule by mulesoft.
the class SchemaTypeConversion method convertType.
public static QName convertType(final MetadataType type, ExpressionSupport expressionSupport) {
final boolean dynamic = acceptsExpressions(expressionSupport);
final Reference<QName> qName = new Reference<>(null);
type.accept(new MetadataTypeVisitor() {
@Override
public void visitBoolean(BooleanType booleanType) {
qName.set(dynamic ? EXPRESSION_BOOLEAN : SUBSTITUTABLE_BOOLEAN);
}
@Override
public void visitNumber(NumberType numberType) {
if (getId(numberType).isPresent()) {
Class<Number> type = JavaTypeUtils.getType(numberType);
if (anyOf(type, Integer.class, int.class)) {
qName.set(dynamic ? EXPRESSION_INTEGER : SUBSTITUTABLE_INT);
} else if (anyOf(type, Double.class, double.class)) {
qName.set(dynamic ? EXPRESSION_DOUBLE : SUBSTITUTABLE_DECIMAL);
} else if (anyOf(type, Long.class, long.class)) {
qName.set(dynamic ? EXPRESSION_LONG : SUBSTITUTABLE_LONG);
} else {
qName.set(dynamic ? EXPRESSION_DECIMAL : SUBSTITUTABLE_DECIMAL);
}
} else {
if (numberType.getAnnotation(IntAnnotation.class).isPresent()) {
qName.set(dynamic ? EXPRESSION_INTEGER : SUBSTITUTABLE_INT);
} else {
qName.set(dynamic ? EXPRESSION_DECIMAL : SUBSTITUTABLE_DECIMAL);
}
}
}
@Override
public void visitString(StringType stringType) {
qName.set(dynamic ? EXPRESSION_STRING : STRING);
}
@Override
public void visitDateTime(DateTimeType dateTimeType) {
onDate();
}
@Override
public void visitDate(DateType dateType) {
onDate();
}
@Override
public void visitArrayType(ArrayType arrayType) {
qName.set(dynamic ? EXPRESSION_LIST : SUBSTITUTABLE_NAME);
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
qName.set(dynamic ? EXPRESSION_MAP : SUBSTITUTABLE_NAME);
} else {
defaultVisit(objectType);
}
}
@Override
protected void defaultVisit(MetadataType metadataType) {
qName.set(STRING);
}
private void onDate() {
qName.set(dynamic ? EXPRESSION_DATE_TIME : SUBSTITUTABLE_DATE_TIME);
}
private boolean anyOf(Class<Number> type, Class<?>... targets) {
for (Class<?> target : targets) {
if (type.equals(target)) {
return true;
}
}
return false;
}
});
return qName.get();
}
Aggregations