Search in sources :

Example 1 with StackedTypesModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty in project mule by mulesoft.

the class ExtensionDefinitionParser method getExpressionBasedValueResolver.

/**
 * Generates the {@link ValueResolver} for expression based values
 */
private ValueResolver getExpressionBasedValueResolver(MetadataType expectedType, String value, Set<ModelProperty> modelProperties, Class<?> expectedClass) {
    ValueResolver resolver;
    Optional<StackedTypesModelProperty> stackedTypesModelProperty = getStackedTypesModelProperty(modelProperties);
    if (stackedTypesModelProperty.isPresent()) {
        resolver = stackedTypesModelProperty.get().getValueResolverFactory().getExpressionBasedValueResolver(value, expectedClass);
    // TODO MULE-13518: Add support for stacked value resolvers for @Parameter inside pojos // The following "IFs" should be removed once implemented
    } else if (isParameterResolver(expectedType)) {
        resolver = new ExpressionBasedParameterResolverValueResolver<>(value, expectedClass, expectedType);
    } else if (isTypedValue(expectedType)) {
        resolver = new ExpressionTypedValueValueResolver<>(value, expectedClass);
    } else if (isLiteral(expectedType) || isTargetParameter(modelProperties)) {
        resolver = new StaticLiteralValueResolver<>(value, expectedClass);
    } else {
        resolver = new TypeSafeExpressionValueResolver<>(value, expectedClass, expectedType);
    }
    return resolver;
}
Also used : StackedTypesModelProperty.getStackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty.getStackedTypesModelProperty) StackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty) ExpressionBasedParameterResolverValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) ExpressionTypedValueValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver) NativeQueryParameterValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ProcessorChainValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver) TypeSafeExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver) StaticLiteralValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver) StaticLiteralValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver) ExpressionBasedParameterResolverValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver) TypeSafeExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver)

Example 2 with StackedTypesModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty in project mule by mulesoft.

the class ExtensionDefinitionParser method getStaticValueResolver.

/**
 * Generates the {@link ValueResolver} for non expression based values
 */
private ValueResolver getStaticValueResolver(String parameterName, MetadataType expectedType, Object value, Object defaultValue, Set<ModelProperty> modelProperties, boolean acceptsReferences, Class<?> expectedClass) {
    Optional<StackedTypesModelProperty> optionalStackedTypeModelProperty = getStackedTypesModelProperty(modelProperties);
    if (optionalStackedTypeModelProperty.isPresent()) {
        StackedTypesModelProperty property = optionalStackedTypeModelProperty.get();
        Optional<ValueResolver> optionalResolver = property.getValueResolverFactory().getStaticValueResolver(value, Literal.class);
        if (optionalResolver.isPresent()) {
            return optionalResolver.get();
        }
    }
    if (isLiteral(expectedType)) {
        return new StaticLiteralValueResolver<>(value != null ? value.toString() : null, expectedClass);
    }
    ValueResolver resolver;
    resolver = value != null ? getValueResolverFromMetadataType(parameterName, expectedType, value, defaultValue, acceptsReferences, expectedClass) : new StaticValueResolver<>(defaultValue);
    if (optionalStackedTypeModelProperty.isPresent()) {
        resolver = optionalStackedTypeModelProperty.get().getValueResolverFactory().getWrapperValueResolver(resolver);
    } else if (isParameterResolver(expectedType)) {
        resolver = new ParameterResolverValueResolverWrapper(resolver);
    } else if (isTypedValue(expectedType)) {
        resolver = new TypedValueValueResolverWrapper(resolver);
    }
    return resolver;
}
Also used : TypedValueValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.TypedValueValueResolverWrapper) StackedTypesModelProperty.getStackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty.getStackedTypesModelProperty) StackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty) ParameterResolverValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.ParameterResolverValueResolverWrapper) ExpressionBasedParameterResolverValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) ExpressionTypedValueValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver) NativeQueryParameterValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ProcessorChainValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver) TypeSafeExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver) StaticLiteralValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver) StaticLiteralValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver)

Aggregations

StackedTypesModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty)2 StackedTypesModelProperty.getStackedTypesModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty.getStackedTypesModelProperty)2 ExpressionBasedParameterResolverValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver)2 ExpressionTypedValueValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver)2 NativeQueryParameterValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver)2 ProcessorChainValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver)2 StaticLiteralValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver)2 StaticValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver)2 TypeSafeExpressionValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver)2 ValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver)2 ParameterResolverValueResolverWrapper (org.mule.runtime.module.extension.internal.runtime.resolver.ParameterResolverValueResolverWrapper)1 TypedValueValueResolverWrapper (org.mule.runtime.module.extension.internal.runtime.resolver.TypedValueValueResolverWrapper)1