Search in sources :

Example 1 with TypeSafeValueResolverWrapper

use of org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeValueResolverWrapper in project mule by mulesoft.

the class ExtensionDefinitionParser method getValueResolverFromMetadataType.

private ValueResolver getValueResolverFromMetadataType(final String parameterName, MetadataType expectedType, final Object value, final Object defaultValue, final boolean acceptsReferences, final Class<?> expectedClass) {
    final Reference<ValueResolver> resolverValueHolder = new Reference<>();
    expectedType.accept(new BasicTypeMetadataVisitor() {

        @Override
        protected void visitBasicType(MetadataType metadataType) {
            if (conversionService.canConvert(value.getClass(), expectedClass)) {
                resolverValueHolder.set(new StaticValueResolver<>(convertSimpleValue(value, expectedClass, parameterName)));
            } else {
                defaultVisit(metadataType);
            }
        }

        @Override
        public void visitDateTime(DateTimeType dateTimeType) {
            resolverValueHolder.set(parseDate(value, dateTimeType, defaultValue));
        }

        @Override
        public void visitDate(DateType dateType) {
            resolverValueHolder.set(parseDate(value, dateType, defaultValue));
        }

        @Override
        public void visitObject(ObjectType objectType) {
            if (isMap(objectType)) {
                defaultVisit(objectType);
                return;
            }
            ValueResolver valueResolver;
            Optional<? extends ParsingDelegate> delegate = locateParsingDelegate(valueResolverParsingDelegates, objectType);
            Optional<DslElementSyntax> typeDsl = dslResolver.resolve(objectType);
            if (delegate.isPresent() && typeDsl.isPresent()) {
                valueResolver = (ValueResolver) delegate.get().parse(value.toString(), objectType, typeDsl.get());
            } else {
                valueResolver = acceptsReferences ? defaultValueResolverParsingDelegate.parse(value.toString(), objectType, null) : new StaticValueResolver<>(value);
            }
            resolverValueHolder.set(valueResolver);
        }

        @Override
        protected void defaultVisit(MetadataType metadataType) {
            ValueResolver delegateResolver = locateParsingDelegate(valueResolverParsingDelegates, metadataType).map(delegate -> delegate.parse(value.toString(), metadataType, null)).orElseGet(() -> acceptsReferences ? defaultValueResolverParsingDelegate.parse(value.toString(), metadataType, null) : new TypeSafeValueResolverWrapper(new StaticValueResolver<>(value), expectedClass));
            resolverValueHolder.set(delegateResolver);
        }
    });
    return resolverValueHolder.get();
}
Also used : SchedulingStrategyParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.SchedulingStrategyParsingDelegate) DefaultValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.DefaultValueResolverParsingDelegate) MediaTypeValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.MediaTypeValueResolverParsingDelegate) ParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ParsingDelegate) DefaultObjectParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.DefaultObjectParsingDelegate) ObjectParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ObjectParsingDelegate) CharsetValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.CharsetValueResolverParsingDelegate) ValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ValueResolverParsingDelegate) FixedTypeParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.FixedTypeParsingDelegate) Optional(java.util.Optional) Reference(org.mule.runtime.api.util.Reference) MetadataType(org.mule.metadata.api.model.MetadataType) BasicTypeMetadataVisitor(org.mule.metadata.api.visitor.BasicTypeMetadataVisitor) ObjectType(org.mule.metadata.api.model.ObjectType) DateTimeType(org.mule.metadata.api.model.DateTimeType) TypeSafeValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeValueResolverWrapper) 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) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) DateType(org.mule.metadata.api.model.DateType)

Aggregations

Optional (java.util.Optional)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 ObjectType (org.mule.metadata.api.model.ObjectType)1 BasicTypeMetadataVisitor (org.mule.metadata.api.visitor.BasicTypeMetadataVisitor)1 Reference (org.mule.runtime.api.util.Reference)1 CharsetValueResolverParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.CharsetValueResolverParsingDelegate)1 DefaultObjectParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.DefaultObjectParsingDelegate)1 DefaultValueResolverParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.DefaultValueResolverParsingDelegate)1 FixedTypeParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.FixedTypeParsingDelegate)1 MediaTypeValueResolverParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.MediaTypeValueResolverParsingDelegate)1 ObjectParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.ObjectParsingDelegate)1 ParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.ParsingDelegate)1 SchedulingStrategyParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.SchedulingStrategyParsingDelegate)1 ValueResolverParsingDelegate (org.mule.runtime.module.extension.internal.config.dsl.object.ValueResolverParsingDelegate)1 ExpressionBasedParameterResolverValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver)1 ExpressionTypedValueValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver)1 NativeQueryParameterValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver)1 ProcessorChainValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver)1