Search in sources :

Example 26 with ObjectType

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

the class CoreExtensionModelTestCase method otherModels.

@Test
public void otherModels() {
    assertThat(coreExtensionModel.getResources(), empty());
    assertThat(coreExtensionModel.getSubTypes(), hasSize(1));
    SubTypesModel subTypesModel = coreExtensionModel.getSubTypes().iterator().next();
    assertThat(subTypesModel.getBaseType().getAnnotation(TypeIdAnnotation.class).get().getValue(), is(Scheduler.class.getName()));
    assertThat(subTypesModel.getSubTypes(), hasSize(2));
    Iterator<ObjectType> iterator = subTypesModel.getSubTypes().iterator();
    final DefaultObjectType ffSchedulerType = (DefaultObjectType) iterator.next();
    assertThat(ffSchedulerType.getFields(), hasSize(3));
    assertThat(ffSchedulerType.getFieldByName("frequency").get().isRequired(), is(false));
    assertThat(ffSchedulerType.getFieldByName("frequency").get().getValue(), instanceOf(DefaultNumberType.class));
    assertThat(ffSchedulerType.getFieldByName("startDelay").get().isRequired(), is(false));
    assertThat(ffSchedulerType.getFieldByName("startDelay").get().getValue(), instanceOf(DefaultNumberType.class));
    assertThat(ffSchedulerType.getFieldByName("timeUnit").get().isRequired(), is(false));
    assertThat(ffSchedulerType.getFieldByName("timeUnit").get().getValue(), instanceOf(DefaultStringType.class));
    final DefaultObjectType cronSchedulerType = (DefaultObjectType) iterator.next();
    assertThat(cronSchedulerType.getFields(), hasSize(2));
    assertThat(cronSchedulerType.getFieldByName("expression").get().isRequired(), is(true));
    assertThat(cronSchedulerType.getFieldByName("expression").get().getValue(), instanceOf(DefaultStringType.class));
    assertThat(cronSchedulerType.getFieldByName("timeZone").get().isRequired(), is(true));
    assertThat(cronSchedulerType.getFieldByName("timeZone").get().getValue(), instanceOf(DefaultStringType.class));
    assertThat(coreExtensionModel.getExternalLibraryModels(), empty());
    assertThat(coreExtensionModel.getImportedTypes(), empty());
    assertThat(coreExtensionModel.getConfigurationModels(), empty());
    assertThat(coreExtensionModel.getOperationModels(), hasSize(8));
    assertThat(coreExtensionModel.getConstructModels(), hasSize(15));
    assertThat(coreExtensionModel.getConnectionProviders(), empty());
    assertThat(coreExtensionModel.getSourceModels(), hasSize(1));
    assertThat(coreExtensionModel.getErrorModels(), hasItem(newError(TRANSFORMATION).withParent(errorMuleAny).build()));
    assertThat(coreExtensionModel.getTypes(), hasSize(5));
}
Also used : SubTypesModel(org.mule.runtime.api.meta.model.SubTypesModel) ObjectType(org.mule.metadata.api.model.ObjectType) DefaultObjectType(org.mule.metadata.api.model.impl.DefaultObjectType) DefaultNumberType(org.mule.metadata.api.model.impl.DefaultNumberType) DefaultObjectType(org.mule.metadata.api.model.impl.DefaultObjectType) DefaultStringType(org.mule.metadata.api.model.impl.DefaultStringType) TypeIdAnnotation(org.mule.metadata.api.annotation.TypeIdAnnotation) Test(org.junit.Test)

Example 27 with ObjectType

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

the class MapSchemaDelegate method generateMapComplexType.

private LocalComplexType generateMapComplexType(DslElementSyntax mapDsl, final ObjectType metadataType) {
    final MetadataType valueType = metadataType.getOpenRestriction().get();
    final LocalComplexType entryComplexType = new LocalComplexType();
    final Attribute keyAttribute = builder.createAttribute(KEY_ATTRIBUTE_NAME, keyType, true, REQUIRED);
    entryComplexType.getAttributeOrAttributeGroup().add(keyAttribute);
    final LocalComplexType mapComplexType = new LocalComplexType();
    final ExplicitGroup mapEntrySequence = new ExplicitGroup();
    mapComplexType.setSequence(mapEntrySequence);
    DslElementSyntax entryValueDsl = mapDsl.getGeneric(valueType).orElseThrow(() -> new IllegalArgumentException("Illegal DslSyntax definition of the given DictionaryType. The DslElementSyntax for the entry is required"));
    final TopLevelElement mapEntryElement = new TopLevelElement();
    mapEntryElement.setName(entryValueDsl.getElementName());
    mapEntryElement.setMinOccurs(ZERO);
    mapEntryElement.setMaxOccurs(UNBOUNDED);
    valueType.accept(new MetadataTypeVisitor() {

        /**
         * For a Map with an {@link ObjectType} as value. The resulting {@link ComplexType} declares a sequence of either a
         * {@code ref} or a {@code choice}.
         * <p/>
         * It creates an element {@code ref} to the concrete element whose {@code type} is the {@link ComplexType} associated to the
         * {@code objectType}
         * <p/>
         * In the case of having a {@link DslElementSyntax#isWrapped wrapped} {@link ObjectType}, then a {@link ExplicitGroup
         * Choice} group that can receive a {@code ref} to any subtype that this wrapped type might have, be it either a top-level
         * element for the mule schema, or if it can only be declared as child of this element.
         *
         * If the map's value is another map, then a value attribute is created for the value map.
         *
         * @param objectType the item's type
         */
        @Override
        public void visitObject(ObjectType objectType) {
            Optional<DslElementSyntax> containedElement = entryValueDsl.getContainedElement(VALUE_ATTRIBUTE_NAME);
            if (isMap(objectType) || !containedElement.isPresent()) {
                defaultVisit(objectType);
                return;
            }
            final boolean shouldGenerateChildElement = containedElement.get().supportsChildDeclaration() || containedElement.get().isWrapped();
            entryComplexType.getAttributeOrAttributeGroup().add(builder.createAttribute(VALUE_ATTRIBUTE_NAME, valueType, !shouldGenerateChildElement, SUPPORTED));
            if (shouldGenerateChildElement) {
                DslElementSyntax typeDsl = builder.getDslResolver().resolve(objectType).orElseThrow(() -> new IllegalArgumentException(format("The given type [%s] cannot be represented as a child element in Map entries", getId(objectType))));
                if (typeDsl.isWrapped()) {
                    ExplicitGroup choice = builder.createTypeRefChoiceLocalOrGlobal(typeDsl, objectType, ZERO, UNBOUNDED);
                    entryComplexType.setChoice(choice);
                } else {
                    ExplicitGroup singleItemSequence = new ExplicitGroup();
                    singleItemSequence.setMaxOccurs("1");
                    TopLevelElement mapItemElement = builder.createTypeRef(typeDsl, objectType, false);
                    singleItemSequence.getParticle().add(objectFactory.createElement(mapItemElement));
                    entryComplexType.setSequence(singleItemSequence);
                }
            }
        }

        @Override
        public void visitArrayType(ArrayType arrayType) {
            entryComplexType.getAttributeOrAttributeGroup().add(builder.createAttribute(VALUE_ATTRIBUTE_NAME, valueType, false, SUPPORTED));
            entryComplexType.setSequence(new ExplicitGroup());
            LocalComplexType itemComplexType = new LocalComplexType();
            MetadataType itemType = arrayType.getType();
            itemComplexType.getAttributeOrAttributeGroup().add(builder.createAttribute(VALUE_ATTRIBUTE_NAME, itemType, true, REQUIRED));
            DslElementSyntax itemDsl = entryValueDsl.getGeneric(itemType).orElseThrow(() -> new IllegalArgumentException("Illegal DslSyntax definition of the given ArrayType. The DslElementSyntax for the item is required"));
            TopLevelElement itemElement = builder.createTopLevelElement(itemDsl.getElementName(), ZERO, UNBOUNDED, itemComplexType);
            entryComplexType.getSequence().getParticle().add(objectFactory.createElement(itemElement));
        }

        @Override
        protected void defaultVisit(MetadataType metadataType) {
            entryComplexType.getAttributeOrAttributeGroup().add(builder.createValueAttribute(valueType));
        }
    });
    mapEntryElement.setComplexType(entryComplexType);
    mapEntrySequence.getParticle().add(objectFactory.createElement(mapEntryElement));
    return mapComplexType;
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) ObjectType(org.mule.metadata.api.model.ObjectType) Optional(java.util.Optional) Attribute(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MetadataType(org.mule.metadata.api.model.MetadataType) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 28 with ObjectType

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

the class CollectionSchemaDelegate method generateCollectionComplexType.

private LocalComplexType generateCollectionComplexType(DslElementSyntax collectionDsl, final ArrayType metadataType) {
    final LocalComplexType collectionComplexType = new LocalComplexType();
    final ExplicitGroup sequence = new ExplicitGroup();
    final MetadataType genericType = metadataType.getType();
    DslElementSyntax itemDsl = collectionDsl.getGeneric(genericType).orElseThrow(() -> new IllegalArgumentException(format("Missing item's DSL information for collection [%s]", collectionDsl.getAttributeName())));
    genericType.accept(new MetadataTypeVisitor() {

        /**
         * For a Collection with an {@link ObjectType} as generic. The generated {@link ComplexType} declares a sequence of either a
         * {@code ref} or a {@code choice}.
         * <p/>
         * It creates an element {@code ref} to the concrete element whose {@code type} is the {@link ComplexType} associated to the
         * {@code objectType}
         * <p/>
         * In the case of having a {@link DslElementSyntax#isWrapped wrapped} {@link ObjectType}, then a {@link ExplicitGroup
         * Choice} group that can receive a {@code ref} to any subtype that this wrapped type might have, be it either a top-level
         * element for the mule schema, or if it can only be declared as child of this element.
         *
         * If the collections's value is a map, then a value attribute is created for the value map.
         *
         * @param objectType the item's type
         */
        @Override
        public void visitObject(ObjectType objectType) {
            if (isMap(objectType)) {
                defaultVisit(objectType);
                return;
            }
            DslElementSyntax typeDsl = builder.getDslResolver().resolve(objectType).orElseThrow(() -> new IllegalArgumentException(format("The given type [%s] cannot be represented as a collection item", getId(objectType))));
            if (typeDsl.isWrapped()) {
                ExplicitGroup choice = builder.createTypeRefChoiceLocalOrGlobal(typeDsl, objectType, ZERO, UNBOUNDED);
                sequence.getParticle().add(objectFactory.createChoice(choice));
            } else {
                TopLevelElement collectionItemElement = builder.createTypeRef(typeDsl, objectType, false);
                collectionItemElement.setMaxOccurs(UNBOUNDED);
                sequence.getParticle().add(objectFactory.createElement(collectionItemElement));
            }
        }

        /**
         * For a Collection with any other type as generic.
         * The generated {@link ComplexType} declares a sequence of child elements with an inline declaration of the type
         *
         * @param metadataType the item's type
         */
        @Override
        protected void defaultVisit(MetadataType metadataType) {
            final LocalComplexType complexType = new LocalComplexType();
            complexType.getAttributeOrAttributeGroup().add(builder.createValueAttribute(genericType));
            TopLevelElement collectionItemElement = builder.createTopLevelElement(itemDsl.getElementName(), ZERO, UNBOUNDED);
            collectionItemElement.setComplexType(complexType);
            sequence.getParticle().add(objectFactory.createElement(collectionItemElement));
        }
    });
    collectionComplexType.setSequence(sequence);
    return collectionComplexType;
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MetadataType(org.mule.metadata.api.model.MetadataType) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 29 with ObjectType

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

the class ExtensionDefinitionParser method parseMapParameters.

/**
 * Registers a definition for a {@link ParameterModel} which represents an open {@link ObjectType}
 *
 * @param key               the key that the parsed value should have on the parsed parameter's map
 * @param name              the parameter's name
 * @param dictionaryType    the parameter's open {@link ObjectType}
 * @param defaultValue      the parameter's default value
 * @param expressionSupport the parameter's {@link ExpressionSupport}
 * @param required          whether the parameter is required
 */
protected void parseMapParameters(String key, String name, ObjectType dictionaryType, Object defaultValue, ExpressionSupport expressionSupport, boolean required, DslElementSyntax paramDsl, Set<ModelProperty> modelProperties) {
    parseAttributeParameter(key, name, dictionaryType, defaultValue, expressionSupport, required, modelProperties);
    Class<? extends Map> mapType = getType(dictionaryType);
    if (ConcurrentMap.class.equals(mapType)) {
        mapType = ConcurrentHashMap.class;
    } else if (Map.class.equals(mapType)) {
        mapType = LinkedHashMap.class;
    }
    final MetadataType valueType = dictionaryType.getOpenRestriction().orElse(typeLoader.load(Object.class));
    final Class<?> valueClass = getType(valueType);
    final MetadataType keyType = typeLoader.load(String.class);
    final Class<?> keyClass = String.class;
    final String mapElementName = paramDsl.getElementName();
    addParameter(getChildKey(key), fromChildMapConfiguration(String.class, valueClass).withWrapperIdentifier(mapElementName).withDefaultValue(defaultValue));
    addDefinition(baseDefinitionBuilder.withIdentifier(mapElementName).withTypeDefinition(fromType(mapType)).build());
    Optional<DslElementSyntax> mapValueChildDsl = paramDsl.getGeneric(valueType);
    if (!mapValueChildDsl.isPresent()) {
        return;
    }
    DslElementSyntax valueDsl = mapValueChildDsl.get();
    valueType.accept(new MetadataTypeVisitor() {

        @Override
        protected void defaultVisit(MetadataType metadataType) {
            String parameterName = paramDsl.getAttributeName();
            addDefinition(baseDefinitionBuilder.withIdentifier(valueDsl.getElementName()).withTypeDefinition(fromMapEntryType(keyClass, valueClass)).withKeyTypeConverter(value -> resolverOf(parameterName, keyType, value, null, expressionSupport, true, emptySet(), false)).withTypeConverter(value -> resolverOf(parameterName, valueType, value, null, expressionSupport, true, emptySet(), false)).build());
        }

        @Override
        public void visitObject(ObjectType objectType) {
            defaultVisit(objectType);
            Optional<DslElementSyntax> containedElement = valueDsl.getContainedElement(VALUE_ATTRIBUTE_NAME);
            if (isMap(objectType) || !containedElement.isPresent()) {
                return;
            }
            DslElementSyntax valueChild = containedElement.get();
            if ((valueChild.supportsTopLevelDeclaration() || (valueChild.supportsChildDeclaration() && !valueChild.isWrapped())) && !parsingContext.isRegistered(valueChild.getElementName(), valueChild.getPrefix())) {
                try {
                    parsingContext.registerObjectType(valueChild.getElementName(), valueChild.getPrefix(), objectType);
                    new ObjectTypeParameterParser(baseDefinitionBuilder, objectType, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(definition -> addDefinition(definition));
                } catch (ConfigurationException e) {
                    throw new MuleRuntimeException(createStaticMessage("Could not create parser for map complex type"), e);
                }
            }
        }

        @Override
        public void visitArrayType(ArrayType arrayType) {
            defaultVisit(arrayType);
            Optional<DslElementSyntax> valueListGenericDsl = valueDsl.getGeneric(arrayType.getType());
            if (valueDsl.supportsChildDeclaration() && valueListGenericDsl.isPresent()) {
                arrayType.getType().accept(new BasicTypeMetadataVisitor() {

                    @Override
                    protected void visitBasicType(MetadataType metadataType) {
                        String parameterName = paramDsl.getAttributeName();
                        addDefinition(baseDefinitionBuilder.withIdentifier(valueListGenericDsl.get().getElementName()).withTypeDefinition(fromType(getType(metadataType))).withTypeConverter(value -> resolverOf(parameterName, metadataType, value, getDefaultValue(metadataType), getExpressionSupport(metadataType), false, emptySet())).build());
                    }

                    @Override
                    protected void defaultVisit(MetadataType metadataType) {
                        addDefinition(baseDefinitionBuilder.withIdentifier(valueListGenericDsl.get().getElementName()).withTypeDefinition(fromType(ValueResolver.class)).withObjectFactoryType(TopLevelParameterObjectFactory.class).withConstructorParameterDefinition(fromFixedValue(arrayType.getType()).build()).withConstructorParameterDefinition(fromFixedValue(getContextClassLoader()).build()).build());
                    }
                });
            }
        }
    });
}
Also used : InfrastructureTypeMapping.getNameMap(org.mule.runtime.module.extension.internal.loader.java.type.InfrastructureTypeMapping.getNameMap) ExpressionBasedParameterResolverValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionBasedParameterResolverValueResolver) StaticValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticValueResolver) KeyAttributeDefinitionPair(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair) InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) BEHAVIOUR(org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) DateTimeType(org.mule.metadata.api.model.DateTimeType) RequiredParameterValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.RequiredParameterValueResolverWrapper) Builder.fromSimpleParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleParameter) QueryParameterModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.QueryParameterModelProperty) Instant.ofEpochMilli(java.time.Instant.ofEpochMilli) ArrayType(org.mule.metadata.api.model.ArrayType) Map(java.util.Map) NestableElementModelVisitor(org.mule.runtime.api.meta.model.nested.NestableElementModelVisitor) ExpressionTypedValueValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ExpressionTypedValueValueResolver) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ModelProperty(org.mule.runtime.api.meta.model.ModelProperty) NestableElementModel(org.mule.runtime.api.meta.model.nested.NestableElementModel) ExtensionModelUtils.isContent(org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent) SchedulingStrategyParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.SchedulingStrategyParsingDelegate) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) IntrospectionUtils.isTargetParameter(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isTargetParameter) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterGroupDescriptor(org.mule.runtime.module.extension.internal.loader.ParameterGroupDescriptor) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DateType(org.mule.metadata.api.model.DateType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ZoneId(java.time.ZoneId) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) DefaultValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.DefaultValueResolverParsingDelegate) DateTimeParseException(java.time.format.DateTimeParseException) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) StringType(org.mule.metadata.api.model.StringType) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) IntrospectionUtils.getContainerName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getContainerName) ParameterResolverValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.ParameterResolverValueResolverWrapper) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) StackedTypesModelProperty.getStackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty.getStackedTypesModelProperty) NativeQueryParameterValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.NativeQueryParameterValueResolver) MetadataTypeUtils.getDefaultValue(org.mule.metadata.api.utils.MetadataTypeUtils.getDefaultValue) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) StackedTypesModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.stackabletypes.StackedTypesModelProperty) LocalDateTime(java.time.LocalDateTime) Builder.fromChildMapConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildMapConfiguration) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) Supplier(java.util.function.Supplier) ObjectTypeParameterParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.ObjectTypeParameterParser) ArrayList(java.util.ArrayList) TypeSafeValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeValueResolverWrapper) LinkedHashMap(java.util.LinkedHashMap) Calendar(java.util.Calendar) ExtensionMetadataTypeUtils.getExpressionSupport(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getExpressionSupport) TypedInlineParameterGroupParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.TypedInlineParameterGroupParser) MediaTypeValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.MediaTypeValueResolverParsingDelegate) ConversionService(org.springframework.core.convert.ConversionService) TypeDefinition.fromType(org.mule.runtime.dsl.api.component.TypeDefinition.fromType) MuleExtensionUtils.isExpression(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.isExpression) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ValueResolver) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ParsingDelegate) Builder.fromMultipleDefinitions(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromMultipleDefinitions) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Reference(org.mule.runtime.api.util.Reference) DefaultObjectParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.DefaultObjectParsingDelegate) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) TemplateParser(org.mule.runtime.core.privileged.util.TemplateParser) IntrospectionUtils.getMemberName(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getMemberName) Date(java.util.Date) Builder.fromChildConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildConfiguration) TypeConverter(org.mule.runtime.dsl.api.component.TypeConverter) IntrospectionUtils.isLiteral(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isLiteral) TypeDefinition.fromMapEntryType(org.mule.runtime.dsl.api.component.TypeDefinition.fromMapEntryType) ProcessorChainValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ProcessorChainValueResolver) IntrospectionUtils.isTypedValue(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isTypedValue) TypedValueValueResolverWrapper(org.mule.runtime.module.extension.internal.runtime.resolver.TypedValueValueResolverWrapper) PoolingProfile(org.mule.runtime.api.config.PoolingProfile) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Builder.fromChildCollectionConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildCollectionConfiguration) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) ObjectParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ObjectParsingDelegate) Collection(java.util.Collection) REQUIRED(org.mule.runtime.api.meta.ExpressionSupport.REQUIRED) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Instant(java.time.Instant) String.format(java.lang.String.format) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) LocalDate(java.time.LocalDate) Optional(java.util.Optional) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) CharsetValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.CharsetValueResolverParsingDelegate) TlsContextFactory(org.mule.runtime.api.tls.TlsContextFactory) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) TypeSafeExpressionValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.TypeSafeExpressionValueResolver) KeyAttributeDefinitionPair.newBuilder(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair.newBuilder) Builder.fromSimpleReferenceParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleReferenceParameter) HashMap(java.util.HashMap) Processor(org.mule.runtime.core.api.processor.Processor) Builder.fromFixedValue(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromFixedValue) ConcurrentMap(java.util.concurrent.ConcurrentMap) ValueResolverParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.ValueResolverParsingDelegate) HashSet(java.util.HashSet) ExtensionMetadataTypeUtils.isFlattenedParameterGroup(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isFlattenedParameterGroup) ImmutableList(com.google.common.collect.ImmutableList) Literal(org.mule.runtime.extension.api.runtime.parameter.Literal) BasicTypeMetadataVisitor(org.mule.metadata.api.visitor.BasicTypeMetadataVisitor) ParameterGroupModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ParameterGroupModelProperty) ExclusiveOptionalModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ExclusiveOptionalModelProperty) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) NameUtils.hyphenize(org.mule.runtime.extension.api.util.NameUtils.hyphenize) IntrospectionUtils.isParameterResolver(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isParameterResolver) ExpressionSupport(org.mule.runtime.api.meta.ExpressionSupport) NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) DateTime(org.joda.time.DateTime) AttributeDefinition(org.mule.runtime.dsl.api.component.AttributeDefinition) AnonymousInlineParameterGroupParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.AnonymousInlineParameterGroupParser) Collectors.toList(java.util.stream.Collectors.toList) ExtensionMetadataTypeUtils(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils) RouteComponentParser(org.mule.runtime.module.extension.internal.config.dsl.construct.RouteComponentParser) FixedTypeParsingDelegate(org.mule.runtime.module.extension.internal.config.dsl.object.FixedTypeParsingDelegate) NestedComponentModel(org.mule.runtime.api.meta.model.nested.NestedComponentModel) TopLevelParameterObjectFactory(org.mule.runtime.module.extension.internal.config.dsl.parameter.TopLevelParameterObjectFactory) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) StaticLiteralValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.StaticLiteralValueResolver) ObjectTypeParameterParser(org.mule.runtime.module.extension.internal.config.dsl.parameter.ObjectTypeParameterParser) Optional(java.util.Optional) MetadataType(org.mule.metadata.api.model.MetadataType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) LinkedHashMap(java.util.LinkedHashMap) ArrayType(org.mule.metadata.api.model.ArrayType) BasicTypeMetadataVisitor(org.mule.metadata.api.visitor.BasicTypeMetadataVisitor) ObjectType(org.mule.metadata.api.model.ObjectType) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InfrastructureTypeMapping.getNameMap(org.mule.runtime.module.extension.internal.loader.java.type.InfrastructureTypeMapping.getNameMap) Map(java.util.Map) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Collections.emptyMap(java.util.Collections.emptyMap)

Example 30 with ObjectType

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

ObjectType (org.mule.metadata.api.model.ObjectType)44 MetadataType (org.mule.metadata.api.model.MetadataType)32 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)21 ArrayType (org.mule.metadata.api.model.ArrayType)19 Optional (java.util.Optional)17 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)17 Reference (org.mule.runtime.api.util.Reference)17 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)16 List (java.util.List)15 String.format (java.lang.String.format)14 ClassTypeLoader (org.mule.metadata.api.ClassTypeLoader)14 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)14 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)14 Set (java.util.Set)13 ParameterizedModel (org.mule.runtime.api.meta.model.parameter.ParameterizedModel)13 Map (java.util.Map)12 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)12 Collectors.toList (java.util.stream.Collectors.toList)11 HashSet (java.util.HashSet)10 ExtensionsTypeLoaderFactory (org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory)10