Search in sources :

Example 6 with StringType

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

the class MimeTypeParametersDeclarationEnricherTestCase method enumTypeOperation.

@Test
public void enumTypeOperation() {
    StringType type = builder.stringType().with(new EnumAnnotation<>(new String[] { "val" })).build();
    mockOutput(operation, type);
    enricher.enrich(extensionLoadingContext);
    assertThat(getGroupParameters(operation), hasSize(0));
}
Also used : StringType(org.mule.metadata.api.model.StringType) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 7 with StringType

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

the class SoapInvokeOperationDeclarer method declareMetadataKeyParameters.

/**
 * Given the Invoke Operation Declarer declares all the parameters that the operation has.
 *
 * @param operation the invoke operation declarer.
 */
private void declareMetadataKeyParameters(OperationDeclarer operation, ClassTypeLoader loader, ReflectionCache reflectionCache) {
    TypeWrapper keyType = new TypeWrapper(WebServiceTypeKey.class, loader);
    ParameterGroupDeclarer group = operation.onParameterGroup(KEYS_GROUP).withModelProperty(new ParameterGroupModelProperty(new ParameterGroupDescriptor(KEYS_GROUP, keyType)));
    StringType stringType = TYPE_BUILDER.stringType().build();
    group.withRequiredParameter(SERVICE_PARAM).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, SERVICE_PARAM, reflectionCache).get())).ofType(stringType).withModelProperty(new MetadataKeyPartModelProperty(1)).withLayout(getLayout(1));
    group.withRequiredParameter(OPERATION_PARAM).ofType(stringType).withModelProperty(new DeclaringMemberModelProperty(getField(WebServiceTypeKey.class, OPERATION_PARAM, reflectionCache).get())).withModelProperty(new MetadataKeyPartModelProperty(2)).withLayout(getLayout(2));
}
Also used : DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) TypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.TypeWrapper) StringType(org.mule.metadata.api.model.StringType) WebServiceTypeKey(org.mule.runtime.extension.api.soap.WebServiceTypeKey) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) MetadataKeyPartModelProperty(org.mule.runtime.extension.api.property.MetadataKeyPartModelProperty) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)

Example 8 with StringType

use of org.mule.metadata.api.model.StringType 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 9 with StringType

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

the class IntrospectionUtils method collectRelativeClasses.

/**
 * Given a {@link MetadataType} it adds all the {@link Class} that are related from that type. This includes generics of an
 * {@link ArrayType}, open restriction of an {@link ObjectType} as well as its fields.
 *
 * @param type {@link MetadataType} to inspect
 * @param extensionClassLoader extension class loader
 * @return {@link Set<Class<?>>} with the classes reachable from the {@code type}
 */
public static Set<Class<?>> collectRelativeClasses(MetadataType type, ClassLoader extensionClassLoader) {
    Set<Class<?>> relativeClasses = new HashSet<>();
    type.accept(new MetadataTypeVisitor() {

        @Override
        public void visitArrayType(ArrayType arrayType) {
            arrayType.getType().accept(this);
        }

        @Override
        public void visitObjectField(ObjectFieldType objectFieldType) {
            objectFieldType.getValue().accept(this);
        }

        @Override
        public void visitObject(ObjectType objectType) {
            if (objectType.getMetadataFormat() != JAVA) {
                return;
            }
            final Class<Object> clazz = getType(objectType).orElse(null);
            if (clazz == null || relativeClasses.contains(clazz)) {
                return;
            }
            Optional<ClassInformationAnnotation> classInformation = objectType.getAnnotation(ClassInformationAnnotation.class);
            if (classInformation.isPresent()) {
                classInformation.get().getGenericTypes().forEach(generic -> relativeClasses.add(loadClass(generic, extensionClassLoader)));
            }
            relativeClasses.add(clazz);
            objectType.getFields().stream().forEach(objectFieldType -> objectFieldType.accept(this));
            objectType.getOpenRestriction().ifPresent(t -> t.accept(this));
        }

        @Override
        public void visitString(StringType stringType) {
            if (stringType.getMetadataFormat() == JAVA && isEnum(stringType)) {
                getType(stringType).ifPresent(relativeClasses::add);
            }
        }
    });
    return relativeClasses;
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) FieldElement(org.mule.runtime.module.extension.api.loader.java.type.FieldElement) READ_ONLY(org.mule.runtime.module.extension.api.loader.java.type.PropertyElement.Accessibility.READ_ONLY) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) Message(org.mule.runtime.api.message.Message) Optional.of(java.util.Optional.of) RequireNameField(org.mule.runtime.module.extension.internal.loader.java.property.RequireNameField) ImplementingParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingParameterModelProperty) TypeElement(javax.lang.model.element.TypeElement) ClassUtils(org.mule.runtime.core.api.util.ClassUtils) DeclaringMemberModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DeclaringMemberModelProperty) ArrayUtils.isEmpty(org.apache.commons.lang3.ArrayUtils.isEmpty) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ArrayType(org.mule.metadata.api.model.ArrayType) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Objects.isNull(java.util.Objects.isNull) LiteralTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.LiteralTypeAnnotation) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ModelProperty(org.mule.runtime.api.meta.model.ModelProperty) Startable(org.mule.runtime.api.lifecycle.Startable) Collectors.toImmutableList(org.mule.runtime.api.util.collection.Collectors.toImmutableList) ObjectType(org.mule.metadata.api.model.ObjectType) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) Member(java.lang.reflect.Member) Set(java.util.Set) ParameterResolverTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.ParameterResolverTypeAnnotation) Element(javax.lang.model.element.Element) JavaTypeUtils.getId(org.mule.metadata.java.api.utils.JavaTypeUtils.getId) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) IntrospectionException(java.beans.IntrospectionException) BaseTypeBuilder.create(org.mule.metadata.api.builder.BaseTypeBuilder.create) IllegalConfigurationModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalConfigurationModelDefinitionException) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) StringType(org.mule.metadata.api.model.StringType) ParameterResolver(org.mule.runtime.extension.api.runtime.parameter.ParameterResolver) Stream(java.util.stream.Stream) PropertyDescriptor(java.beans.PropertyDescriptor) MetadataType(org.mule.metadata.api.model.MetadataType) InjectedFieldModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.InjectedFieldModelProperty) Expression(org.mule.runtime.extension.api.annotation.Expression) AnnotatedElement(java.lang.reflect.AnnotatedElement) Optional.empty(java.util.Optional.empty) MetadataTypeUtils.isObjectType(org.mule.metadata.api.utils.MetadataTypeUtils.isObjectType) AnyType(org.mule.metadata.api.model.AnyType) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) VariableElement(javax.lang.model.element.VariableElement) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) Modifier.isStatic(java.lang.reflect.Modifier.isStatic) Supplier(java.util.function.Supplier) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) ArrayList(java.util.ArrayList) Introspector(java.beans.Introspector) DeclaredType(javax.lang.model.type.DeclaredType) ParameterGroup(org.mule.runtime.extension.api.annotation.param.ParameterGroup) LinkedHashSet(java.util.LinkedHashSet) Disposable(org.mule.runtime.api.lifecycle.Disposable) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) DataType(org.mule.runtime.api.metadata.DataType) Field(java.lang.reflect.Field) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) TypedValue(org.mule.runtime.api.metadata.TypedValue) ExtensionMetadataTypeUtils.getType(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getType) Modifier.isPublic(java.lang.reflect.Modifier.isPublic) ParameterizedType(java.lang.reflect.ParameterizedType) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) Reference(org.mule.runtime.api.util.Reference) RefName(org.mule.runtime.extension.api.annotation.param.RefName) CollectionUtils.isEmpty(org.apache.commons.collections.CollectionUtils.isEmpty) ReflectionUtils(org.reflections.ReflectionUtils) ReflectionUtils.getAllFields(org.reflections.ReflectionUtils.getAllFields) SubTypesModel(org.mule.runtime.api.meta.model.SubTypesModel) HasOutputModel(org.mule.runtime.api.meta.model.HasOutputModel) TargetModelProperty(org.mule.runtime.extension.internal.property.TargetModelProperty) NamedObject(org.mule.runtime.api.meta.NamedObject) Source(org.mule.runtime.extension.api.runtime.source.Source) VoidType(org.mule.metadata.api.model.VoidType) MetadataTypeUtils.isEnum(org.mule.metadata.api.utils.MetadataTypeUtils.isEnum) DefaultEncodingModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.DefaultEncodingModelProperty) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.SUPPORTED) ResolvableType(org.springframework.core.ResolvableType) Pair(org.mule.runtime.api.util.Pair) Method(java.lang.reflect.Method) Collectors.toSet(java.util.stream.Collectors.toSet) Collections.reverse(java.util.Collections.reverse) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) Types(javax.lang.model.util.Types) String.format(java.lang.String.format) List(java.util.List) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) TypeVariable(javax.lang.model.type.TypeVariable) EnrichableModel(org.mule.runtime.api.meta.model.EnrichableModel) Arrays.stream(java.util.Arrays.stream) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) MessageMetadataTypeBuilder(org.mule.metadata.message.api.MessageMetadataTypeBuilder) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) Alias(org.mule.runtime.extension.api.annotation.Alias) TypeGeneric(org.mule.runtime.module.extension.api.loader.java.type.TypeGeneric) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) MetadataKeyId(org.mule.runtime.extension.api.annotation.metadata.MetadataKeyId) Ignore(org.mule.runtime.extension.api.annotation.Ignore) HashSet(java.util.HashSet) Collectors.toCollection(java.util.stream.Collectors.toCollection) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) ImmutableList(com.google.common.collect.ImmutableList) Literal(org.mule.runtime.extension.api.runtime.parameter.Literal) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) LinkedList(java.util.LinkedList) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) TypedValueTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.TypedValueTypeAnnotation) AccessibleObject(java.lang.reflect.AccessibleObject) Iterator(java.util.Iterator) ElementKind(javax.lang.model.element.ElementKind) PUBLIC(javax.lang.model.element.Modifier.PUBLIC) ExpressionSupport(org.mule.runtime.api.meta.ExpressionSupport) ExecutableElement(javax.lang.model.element.ExecutableElement) READ_WRITE(org.mule.runtime.module.extension.api.loader.java.type.PropertyElement.Accessibility.READ_WRITE) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Result(org.mule.runtime.extension.api.runtime.operation.Result) DefaultEncoding(org.mule.runtime.extension.api.annotation.param.DefaultEncoding) Collectors.toList(java.util.stream.Collectors.toList) TypeMirror(javax.lang.model.type.TypeMirror) BaseDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.BaseDeclaration) METHOD(javax.lang.model.element.ElementKind.METHOD) PagingProvider(org.mule.runtime.extension.api.runtime.streaming.PagingProvider) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MuleExtensionAnnotationParser(org.mule.runtime.module.extension.internal.loader.java.MuleExtensionAnnotationParser) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) ObjectType(org.mule.metadata.api.model.ObjectType) MetadataTypeUtils.isObjectType(org.mule.metadata.api.utils.MetadataTypeUtils.isObjectType) Optional(java.util.Optional) StringType(org.mule.metadata.api.model.StringType) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ClassInformationAnnotation(org.mule.metadata.java.api.annotation.ClassInformationAnnotation) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Aggregations

StringType (org.mule.metadata.api.model.StringType)9 MetadataType (org.mule.metadata.api.model.MetadataType)7 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)6 Optional (java.util.Optional)5 ArrayType (org.mule.metadata.api.model.ArrayType)5 ObjectType (org.mule.metadata.api.model.ObjectType)5 Reference (org.mule.runtime.api.util.Reference)5 ParameterGroupModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty)5 ImmutableList (com.google.common.collect.ImmutableList)4 String.format (java.lang.String.format)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Set (java.util.Set)4 Supplier (java.util.function.Supplier)3 Collectors.toList (java.util.stream.Collectors.toList)3 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)3 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)3