Search in sources :

Example 1 with BooleanType

use of org.mule.metadata.api.model.BooleanType 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();
}
Also used : StringType(org.mule.metadata.api.model.StringType) QName(javax.xml.namespace.QName) Reference(org.mule.runtime.api.util.Reference) BooleanType(org.mule.metadata.api.model.BooleanType) MetadataType(org.mule.metadata.api.model.MetadataType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ArrayType(org.mule.metadata.api.model.ArrayType) ObjectType(org.mule.metadata.api.model.ObjectType) NumberType(org.mule.metadata.api.model.NumberType) DateTimeType(org.mule.metadata.api.model.DateTimeType) DateType(org.mule.metadata.api.model.DateType)

Example 2 with BooleanType

use of org.mule.metadata.api.model.BooleanType in project mule by mulesoft.

the class BooleanParameterDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration extensionDeclaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    new DeclarationWalker() {

        @Override
        protected void onParameter(ParameterizedDeclaration owner, ParameterGroupDeclaration parameterGroup, ParameterDeclaration declaration) {
            declaration.getType().accept(new MetadataTypeVisitor() {

                @Override
                public void visitBoolean(BooleanType booleanType) {
                    declaration.setRequired(false);
                    if (declaration.getDefaultValue() == null && !declaration.isConfigOverride()) {
                        declaration.setDefaultValue(valueOf(FALSE));
                    }
                }
            });
        }
    }.walk(extensionDeclaration);
}
Also used : ParameterGroupDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) BooleanType(org.mule.metadata.api.model.BooleanType) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ConfigOverride(org.mule.runtime.extension.api.annotation.param.ConfigOverride)

Aggregations

BooleanType (org.mule.metadata.api.model.BooleanType)2 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)2 QName (javax.xml.namespace.QName)1 ArrayType (org.mule.metadata.api.model.ArrayType)1 DateTimeType (org.mule.metadata.api.model.DateTimeType)1 DateType (org.mule.metadata.api.model.DateType)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 NumberType (org.mule.metadata.api.model.NumberType)1 ObjectType (org.mule.metadata.api.model.ObjectType)1 StringType (org.mule.metadata.api.model.StringType)1 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)1 ParameterDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration)1 ParameterGroupDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclaration)1 ParameterizedDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration)1 DeclarationWalker (org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker)1 Reference (org.mule.runtime.api.util.Reference)1 ConfigOverride (org.mule.runtime.extension.api.annotation.param.ConfigOverride)1