Search in sources :

Example 16 with Type

use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.

the class IntrospectionUtilsTestCase method getProperties.

@Test
public void getProperties() {
    Set<Field> fields = IntrospectionUtils.getFieldsWithGetters(SomePojo.class, reflectionCache);
    Type somePojo = typeSupplier.apply(SomePojo.class);
    List<FieldElement> fieldsWithGetters = IntrospectionUtils.getFieldsWithGetters(somePojo);
    assertThat(fieldsWithGetters.size(), is(fields.size()));
}
Also used : Field(java.lang.reflect.Field) IntrospectionUtils.getFieldMetadataType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldMetadataType) VoidType(org.mule.metadata.api.model.VoidType) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MapDataType(org.mule.runtime.api.metadata.MapDataType) ArrayType(org.mule.metadata.api.model.ArrayType) ResolvableType(org.springframework.core.ResolvableType) ObjectType(org.mule.metadata.api.model.ObjectType) StringType(org.mule.metadata.api.model.StringType) IntrospectionUtils.toDataType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.toDataType) MetadataType(org.mule.metadata.api.model.MetadataType) AnyType(org.mule.metadata.api.model.AnyType) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) ExtensionsTestUtils.assertMessageType(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.assertMessageType) FieldElement(org.mule.runtime.module.extension.api.loader.java.type.FieldElement) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 17 with Type

use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.

the class IntrospectionUtilsTestCase method getPagingProviderImplementationTypes.

@Test
public void getPagingProviderImplementationTypes() {
    ResolvableType pagingProvider = ResolvableType.forClass(TestPagingProvider.class);
    Pair<Type, Type> pagingProviderTypes = getPagingProviderTypes(new TypeWrapper(pagingProvider, TYPE_LOADER));
    assertThat(pagingProviderTypes.getFirst().getDeclaringClass().get(), equalTo(Object.class));
    assertThat(pagingProviderTypes.getSecond().getDeclaringClass().get(), equalTo(Result.class));
}
Also used : IntrospectionUtils.getFieldMetadataType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldMetadataType) VoidType(org.mule.metadata.api.model.VoidType) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MapDataType(org.mule.runtime.api.metadata.MapDataType) ArrayType(org.mule.metadata.api.model.ArrayType) ResolvableType(org.springframework.core.ResolvableType) ObjectType(org.mule.metadata.api.model.ObjectType) StringType(org.mule.metadata.api.model.StringType) IntrospectionUtils.toDataType(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.toDataType) MetadataType(org.mule.metadata.api.model.MetadataType) AnyType(org.mule.metadata.api.model.AnyType) MessageMetadataType(org.mule.metadata.message.api.MessageMetadataType) DataType(org.mule.runtime.api.metadata.DataType) CollectionDataType(org.mule.runtime.api.metadata.CollectionDataType) ExtensionsTestUtils.assertMessageType(org.mule.test.module.extension.internal.util.ExtensionsTestUtils.assertMessageType) TypeWrapper(org.mule.runtime.module.extension.internal.loader.java.type.runtime.TypeWrapper) ResolvableType(org.springframework.core.ResolvableType) Result(org.mule.runtime.extension.api.runtime.operation.Result) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 18 with Type

use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.

the class BackPressureDeclarationEnricher method enrich.

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

        @Override
        protected void onSource(SourceDeclaration sourceDeclaration) {
            BackPressureStrategyModelProperty property;
            Optional<ExtensionTypeDescriptorModelProperty> extensionTypeDescriptorModelProperty = sourceDeclaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
            if (extensionTypeDescriptorModelProperty.isPresent()) {
                Type sourceType = extensionTypeDescriptorModelProperty.get().getType();
                property = sourceType.getAnnotation(BackPressure.class).map(BackPressureStrategyModelProperty::of).orElseGet(BackPressureStrategyModelProperty::getDefault);
                sourceDeclaration.addModelProperty(property);
                if (property.getSupportedModes().size() > 1) {
                    addBackPressureParameter(extensionDeclaration, sourceDeclaration, property);
                }
            }
        }
    }.walk(extensionDeclaration);
}
Also used : Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) BackPressureStrategyModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.BackPressureStrategyModelProperty) Optional(java.util.Optional) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Example 19 with Type

use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.

the class OperationModelLoaderDelegate method processPagingTx.

private void processPagingTx(OperationDeclarer operation, MethodElement method) {
    checkArgument(method != null, "Can't introspect a null method");
    Type returnTypeElement = method.getReturnType();
    List<TypeGeneric> generics = returnTypeElement.getGenerics();
    if (!generics.isEmpty()) {
        operation.transactional(generics.get(0).getConcreteType().isAssignableTo(TransactionalConnection.class));
    } else {
        operation.transactional(false);
    }
}
Also used : AnyType(org.mule.metadata.api.model.AnyType) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MetadataType(org.mule.metadata.api.model.MetadataType) TransactionalConnection(org.mule.runtime.extension.api.connectivity.TransactionalConnection) TypeGeneric(org.mule.runtime.module.extension.api.loader.java.type.TypeGeneric)

Example 20 with Type

use of org.mule.runtime.module.extension.api.loader.java.type.Type in project mule by mulesoft.

the class OperationModelLoaderDelegate method processNonBlockingOperation.

static void processNonBlockingOperation(OperationDeclarer operation, MethodElement operationMethod, boolean allowStreaming) {
    List<ExtensionParameter> callbackParameters = operationMethod.getParameters().stream().filter(p -> p.getType().isSameType(CompletionCallback.class)).collect(toList());
    checkDefinition(!callbackParameters.isEmpty(), format("Operation '%s' does not declare a '%s' parameter. One is required for a non-blocking operation", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    checkDefinition(callbackParameters.size() <= 1, format("Operation '%s' defines more than one %s parameters. Only one is allowed", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    checkDefinition(isVoid(operationMethod), format("Operation '%s' has a parameter of type %s but is not void. " + "Non-blocking operations have to be declared as void and the " + "return type provided through the callback", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    ExtensionParameter callbackParameter = callbackParameters.get(0);
    List<MetadataType> genericTypes = callbackParameter.getType().getGenerics().stream().map(generic -> generic.getConcreteType().asMetadataType()).collect(toList());
    if (genericTypes.isEmpty()) {
        // This is an invalid state, but is better to fail when executing the Extension Model Validators
        genericTypes.add(ANY_TYPE);
        genericTypes.add(ANY_TYPE);
    }
    operation.withOutput().ofType(genericTypes.get(0));
    operation.withOutputAttributes().ofType(genericTypes.get(1));
    operation.blocking(false);
    if (allowStreaming) {
        handleByteStreaming(operationMethod, operation, genericTypes.get(0));
    } else {
        operation.supportsStreaming(false);
    }
}
Also used : TypeGeneric(org.mule.runtime.module.extension.api.loader.java.type.TypeGeneric) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) AnyType(org.mule.metadata.api.model.AnyType) CompletionCallback(org.mule.runtime.extension.api.runtime.process.CompletionCallback) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) HashMap(java.util.HashMap) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) JAVA(org.mule.metadata.java.api.JavaTypeLoader.JAVA) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) OperationElement(org.mule.runtime.module.extension.api.loader.java.type.OperationElement) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) ModelLoaderUtils.isScope(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isScope) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) WithOperationContainers(org.mule.runtime.module.extension.api.loader.java.type.WithOperationContainers) Map(java.util.Map) Method(java.lang.reflect.Method) ModelLoaderUtils.isNonBlocking(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isNonBlocking) Execution(org.mule.runtime.extension.api.annotation.execution.Execution) PagedOperationModelProperty(org.mule.runtime.extension.internal.property.PagedOperationModelProperty) String.format(java.lang.String.format) ModelLoaderUtils.isRouter(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isRouter) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ModelLoaderUtils.isAutoPaging(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isAutoPaging) IntrospectionUtils.isVoid(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isVoid) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty) TransactionalConnection(org.mule.runtime.extension.api.connectivity.TransactionalConnection) OperationContainerElement(org.mule.runtime.module.extension.api.loader.java.type.OperationContainerElement) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) IllegalOperationModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalOperationModelDefinitionException) ModelLoaderUtils.handleByteStreaming(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.handleByteStreaming) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) MetadataType(org.mule.metadata.api.model.MetadataType)

Aggregations

Type (org.mule.runtime.module.extension.api.loader.java.type.Type)26 MetadataType (org.mule.metadata.api.model.MetadataType)20 ObjectType (org.mule.metadata.api.model.ObjectType)16 ArrayType (org.mule.metadata.api.model.ArrayType)15 AnyType (org.mule.metadata.api.model.AnyType)13 StringType (org.mule.metadata.api.model.StringType)11 VoidType (org.mule.metadata.api.model.VoidType)11 DataType (org.mule.runtime.api.metadata.DataType)11 ResolvableType (org.springframework.core.ResolvableType)11 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)9 TypeGeneric (org.mule.runtime.module.extension.api.loader.java.type.TypeGeneric)9 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)9 ParameterizedType (java.lang.reflect.ParameterizedType)8 Optional (java.util.Optional)8 DeclaredType (javax.lang.model.type.DeclaredType)8 MetadataTypeUtils.isObjectType (org.mule.metadata.api.utils.MetadataTypeUtils.isObjectType)8 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)8 String.format (java.lang.String.format)7 Field (java.lang.reflect.Field)6 Map (java.util.Map)6