Search in sources :

Example 11 with ComponentBuildingDefinition

use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition in project mule by mulesoft.

the class ExtensionDefinitionParser method parse.

/**
 * Creates a list of {@link ComponentBuildingDefinition} built on copies of {@link #baseDefinitionBuilder}. It also sets the
 * parsed parsed parameters on the backing {@link AbstractExtensionObjectFactory}
 *
 * @return a list with the generated {@link ComponentBuildingDefinition}
 * @throws ConfigurationException if a parsing error occurs
 */
public final List<ComponentBuildingDefinition> parse() throws ConfigurationException {
    Builder builder = baseDefinitionBuilder;
    builder = doParse(builder);
    AttributeDefinition parametersDefinition = fromFixedValue(new HashMap<>()).build();
    if (!parameters.isEmpty()) {
        KeyAttributeDefinitionPair[] attributeDefinitions = parameters.entrySet().stream().map(entry -> newBuilder().withAttributeDefinition(entry.getValue().build()).withKey(entry.getKey()).build()).toArray(KeyAttributeDefinitionPair[]::new);
        parametersDefinition = fromMultipleDefinitions(attributeDefinitions).build();
    }
    builder = builder.withSetterParameterDefinition("parameters", parametersDefinition);
    addDefinition(builder.build());
    return parsedDefinitions;
}
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) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) KeyAttributeDefinitionPair.newBuilder(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair.newBuilder) KeyAttributeDefinitionPair(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair) AttributeDefinition(org.mule.runtime.dsl.api.component.AttributeDefinition)

Example 12 with ComponentBuildingDefinition

use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition in project mule by mulesoft.

the class BeanDefinitionFactory method resolveComponent.

private BeanDefinition resolveComponent(ComponentModel parentComponentModel, SpringComponentModel componentModel, BeanDefinitionRegistry registry, BiConsumer<ComponentModel, BeanDefinitionRegistry> componentDefinitionModelProcessor, SpringConfigurationComponentLocator componentLocator) {
    if (isComponentIgnored(componentModel.getIdentifier())) {
        return null;
    }
    if (!componentModel.isEnabled()) {
        // Just register the location, for support of lazyInit scenarios
        componentLocator.addComponentLocation(componentModel.getComponentLocation());
        return null;
    }
    resolveComponentBeanDefinition(parentComponentModel, componentModel);
    componentDefinitionModelProcessor.accept(componentModel, registry);
    // TODO MULE-9638: Once we migrate all core definitions we need to define a mechanism for customizing
    // how core constructs are processed.
    processMuleConfiguration(componentModel, registry);
    processMuleSecurityManager(componentModel, registry);
    processRaiseError(componentModel);
    componentBuildingDefinitionRegistry.getBuildingDefinition(componentModel.getIdentifier()).ifPresent(componentBuildingDefinition -> {
        if ((componentModel.getType() != null) && Component.class.isAssignableFrom(componentModel.getType())) {
            addAnnotation(ANNOTATION_NAME, componentModel.getIdentifier(), componentModel);
            // We need to use a mutable map since spring will resolve the properties placeholder present in the value if needed
            // and it will be done by mutating the same map.
            addAnnotation(ANNOTATION_PARAMETERS, new HashMap<>(componentModel.getParameters()), componentModel);
            // add any error mappings if present
            List<ComponentModel> errorMappingComponents = componentModel.getInnerComponents().stream().filter(innerComponent -> ERROR_MAPPING_IDENTIFIER.equals(innerComponent.getIdentifier())).collect(toList());
            if (!errorMappingComponents.isEmpty()) {
                addAnnotation(ANNOTATION_ERROR_MAPPINGS, errorMappingComponents.stream().map(innerComponent -> {
                    Map<String, String> parameters = innerComponent.getParameters();
                    ComponentIdentifier source = buildFromStringRepresentation(parameters.get(SOURCE_TYPE));
                    ErrorType errorType = errorTypeRepository.lookupErrorType(source).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not find error '%s'.", source)));
                    ErrorTypeMatcher errorTypeMatcher = new SingleErrorTypeMatcher(errorType);
                    ErrorType targetValue = resolveErrorType(parameters.get(TARGET_TYPE));
                    return new ErrorMapping(errorTypeMatcher, targetValue);
                }).collect(toList()), componentModel);
            }
            componentLocator.addComponentLocation(componentModel.getComponentLocation());
        }
    });
    addAnnotation(LOCATION_KEY, componentModel.getComponentLocation(), componentModel);
    BeanDefinition beanDefinition = componentModel.getBeanDefinition();
    return beanDefinition;
}
Also used : KeyAttributeDefinitionPair(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) BeanReference(org.springframework.beans.factory.config.BeanReference) Optional.of(java.util.Optional.of) BiFunction(java.util.function.BiFunction) ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) DESCRIPTION_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.DESCRIPTION_IDENTIFIER) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) SECURITY_MANAGER_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.SECURITY_MANAGER_IDENTIFIER) MULE_PROPERTY_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTY_IDENTIFIER) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) MVELExpressionLanguage(org.mule.runtime.core.internal.el.mvel.MVELExpressionLanguage) Map(java.util.Map) MULE_EE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_EE_DOMAIN_IDENTIFIER) DEFAULT_OBJECT_SERIALIZER_NAME(org.mule.runtime.api.serialization.ObjectSerializer.DEFAULT_OBJECT_SERIALIZER_NAME) RAISE_ERROR_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.RAISE_ERROR_IDENTIFIER) MULE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_DOMAIN_IDENTIFIER) ANNOTATIONS_ELEMENT_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.ANNOTATIONS_ELEMENT_IDENTIFIER) ERROR_MAPPING_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.ERROR_MAPPING_IDENTIFIER) ImmutableSet(com.google.common.collect.ImmutableSet) SpringConfigurationComponentLocator(org.mule.runtime.config.internal.SpringConfigurationComponentLocator) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ServiceLoader(java.util.ServiceLoader) CommonBeanDefinitionCreator.areMatchingTypes(org.mule.runtime.config.internal.dsl.spring.CommonBeanDefinitionCreator.areMatchingTypes) String.format(java.lang.String.format) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) List(java.util.List) ErrorType(org.mule.runtime.api.message.ErrorType) Optional(java.util.Optional) ANNOTATION_NAME(org.mule.runtime.core.internal.component.ComponentAnnotations.ANNOTATION_NAME) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ANNOTATION_PARAMETERS(org.mule.runtime.core.internal.component.ComponentAnnotations.ANNOTATION_PARAMETERS) DOC_DESCRIPTION_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.DOC_DESCRIPTION_IDENTIFIER) RetryPolicyTemplate(org.mule.runtime.core.api.retry.policy.RetryPolicyTemplate) ComponentBuildingDefinitionRegistry(org.mule.runtime.config.api.dsl.model.ComponentBuildingDefinitionRegistry) OBJECT_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.OBJECT_IDENTIFIER) ErrorMapping(org.mule.runtime.core.internal.exception.ErrorMapping) ComponentIdentifier.buildFromStringRepresentation(org.mule.runtime.api.component.ComponentIdentifier.buildFromStringRepresentation) OBJECT_EXPRESSION_LANGUAGE(org.mule.runtime.core.api.config.MuleProperties.OBJECT_EXPRESSION_LANGUAGE) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) HashSet(java.util.HashSet) MAP(org.mule.runtime.config.internal.dsl.spring.WrapperElementType.MAP) MULE_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_IDENTIFIER) SINGLE(org.mule.runtime.config.internal.dsl.spring.WrapperElementType.SINGLE) COLLECTION(org.mule.runtime.config.internal.dsl.spring.WrapperElementType.COLLECTION) Component(org.mule.runtime.api.component.Component) BiConsumer(java.util.function.BiConsumer) ComponentModelHelper.addAnnotation(org.mule.runtime.config.internal.dsl.spring.ComponentModelHelper.addAnnotation) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) OBJECT_DEFAULT_RETRY_POLICY_TEMPLATE(org.mule.runtime.core.api.config.MuleProperties.OBJECT_DEFAULT_RETRY_POLICY_TEMPLATE) LOCATION_KEY(org.mule.runtime.api.component.AbstractComponent.LOCATION_KEY) MULE_PROPERTIES_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTIES_IDENTIFIER) GLOBAL_PROPERTY_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.GLOBAL_PROPERTY_IDENTIFIER) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) AttributeDefinition(org.mule.runtime.dsl.api.component.AttributeDefinition) AbstractAttributeDefinitionVisitor(org.mule.runtime.config.api.dsl.processor.AbstractAttributeDefinitionVisitor) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) Consumer(java.util.function.Consumer) Either(org.mule.runtime.core.api.functional.Either) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationPropertiesProviderFactory(org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProviderFactory) Element(org.w3c.dom.Element) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) CONFIGURATION_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.CONFIGURATION_IDENTIFIER) ANNOTATION_ERROR_MAPPINGS(org.mule.runtime.core.internal.exception.ErrorMapping.ANNOTATION_ERROR_MAPPINGS) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ErrorMapping(org.mule.runtime.core.internal.exception.ErrorMapping) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) ErrorTypeMatcher(org.mule.runtime.core.api.exception.ErrorTypeMatcher) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) SingleErrorTypeMatcher(org.mule.runtime.core.api.exception.SingleErrorTypeMatcher) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ErrorType(org.mule.runtime.api.message.ErrorType) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Component(org.mule.runtime.api.component.Component)

Example 13 with ComponentBuildingDefinition

use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition in project mule by mulesoft.

the class CommonBeanDefinitionCreator method handleRequest.

@Override
public boolean handleRequest(CreateBeanDefinitionRequest request) {
    SpringComponentModel componentModel = request.getComponentModel();
    ComponentBuildingDefinition buildingDefinition = request.getComponentBuildingDefinition();
    componentModel.setType(retrieveComponentType(componentModel, buildingDefinition));
    BeanDefinitionBuilder beanDefinitionBuilder = createBeanDefinitionBuilder(componentModel, buildingDefinition);
    processAnnotations(componentModel, beanDefinitionBuilder);
    processComponentDefinitionModel(request.getParentComponentModel(), componentModel, buildingDefinition, beanDefinitionBuilder);
    return true;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition)

Example 14 with ComponentBuildingDefinition

use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition in project mule by mulesoft.

the class ObjectFactoryClassRepository method getObjectFactoryDynamicClass.

private Class<ObjectFactory> getObjectFactoryDynamicClass(final ComponentBuildingDefinition componentBuildingDefinition, final Class objectFactoryType, final Class createdObjectType, final Supplier<Boolean> isLazyInitFunction, final Optional<Consumer<Object>> instancePostCreationFunction) {
    /*
     * We need this to allow spring create the object using a FactoryBean but using the object factory setters and getters so we
     * create as FactoryBean a dynamic class that will have the same attributes and methods as the ObjectFactory that the user
     * defined. This way our API does not expose spring specific classes.
     */
    Enhancer enhancer = new Enhancer();
    // Use SmartFactoryBean since it's the only way to force spring to pre-instantiate FactoryBean for singletons
    enhancer.setInterfaces(new Class[] { SmartFactoryBean.class });
    enhancer.setSuperclass(objectFactoryType);
    enhancer.setCallbackType(MethodInterceptor.class);
    if (SmartFactoryBean.class.getClassLoader() != objectFactoryType.getClassLoader()) {
        // CGLIB needs access to both the spring interface and the extended factory class.
        // If the factory class is defined in a plugin, its classloader has to be passed.
        enhancer.setClassLoader(new CompositeClassLoader(ObjectFactoryClassRepository.class.getClassLoader(), objectFactoryType.getClassLoader()));
    }
    // The use of the CGLIB cache is turned off when a post creation function is passed as argument in order to
    // enrich the created proxy with properties. This is only to enable injecting properties in components
    // from the compatibility module.
    // Setting this to false will generate an excessive amount of different proxy classes loaded by the container CL
    // that will end up in Metaspace OOM.
    enhancer.setUseCache(!instancePostCreationFunction.isPresent());
    Class<ObjectFactory> factoryBeanClass = enhancer.createClass();
    registerStaticCallbacks(factoryBeanClass, new Callback[] { (MethodInterceptor) (obj, method, args, proxy) -> {
        final boolean eager = !isLazyInitFunction.get();
        if (method.getName().equals("isSingleton")) {
            return !componentBuildingDefinition.isPrototype();
        }
        if (method.getName().equals("getObjectType") && !ObjectTypeProvider.class.isAssignableFrom(obj.getClass())) {
            return createdObjectType;
        }
        if (method.getName().equals("getObject")) {
            Object createdInstance = proxy.invokeSuper(obj, args);
            instancePostCreationFunction.ifPresent(consumer -> consumer.accept(createdInstance));
            return createdInstance;
        }
        if (method.getName().equals("isPrototype")) {
            return componentBuildingDefinition.isPrototype();
        }
        if (method.getName().equals("isEagerInit")) {
            return eager;
        }
        return proxy.invokeSuper(obj, args);
    } });
    return factoryBeanClass;
}
Also used : MethodInterceptor(org.springframework.cglib.proxy.MethodInterceptor) Consumer(java.util.function.Consumer) Enhancer(org.springframework.cglib.proxy.Enhancer) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) Enhancer.registerStaticCallbacks(org.springframework.cglib.proxy.Enhancer.registerStaticCallbacks) CompositeClassLoader(org.mule.runtime.core.internal.util.CompositeClassLoader) Callback(org.springframework.cglib.proxy.Callback) SmartFactoryBean(org.springframework.beans.factory.SmartFactoryBean) Optional(java.util.Optional) ObjectFactory(org.mule.runtime.dsl.api.component.ObjectFactory) Supplier(java.util.function.Supplier) ObjectTypeProvider(org.mule.runtime.dsl.api.component.ObjectTypeProvider) ObjectTypeProvider(org.mule.runtime.dsl.api.component.ObjectTypeProvider) Enhancer(org.springframework.cglib.proxy.Enhancer) ObjectFactory(org.mule.runtime.dsl.api.component.ObjectFactory) SmartFactoryBean(org.springframework.beans.factory.SmartFactoryBean) CompositeClassLoader(org.mule.runtime.core.internal.util.CompositeClassLoader)

Example 15 with ComponentBuildingDefinition

use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition in project mule by mulesoft.

the class TestParsersComponentBuildingDefinitionProvider method getComponentBuildingDefinitions.

@Override
public List<ComponentBuildingDefinition> getComponentBuildingDefinitions() {
    List<ComponentBuildingDefinition> definitions = new ArrayList<>();
    ComponentBuildingDefinition.Builder baseBuilder = new ComponentBuildingDefinition.Builder().withNamespace(TestParsersNamespaceInfoProvider.PARSERS_TEST_NAMESPACE);
    ComponentBuildingDefinition.Builder baseParameterCollectionParserBuilder = baseBuilder.withTypeDefinition(fromType(ParsersTestObject.class)).asNamed().withSetterParameterDefinition("simpleTypeWithConverter", fromChildConfiguration(String.class).build()).withSetterParameterDefinition("simpleTypeList", fromChildConfiguration(List.class).withWrapperIdentifier("simple-type-child-list").build()).withSetterParameterDefinition("simpleTypeListWithConverter", fromChildConfiguration(List.class).withWrapperIdentifier("simple-type-child-list-with-converter").build()).withSetterParameterDefinition("simpleTypeSet", fromChildConfiguration(Set.class).withWrapperIdentifier("simple-type-child-set").build()).withSetterParameterDefinition("simpleTypeMap", fromChildMapConfiguration(String.class, Integer.class).withWrapperIdentifier("simple-type-map").build()).withSetterParameterDefinition("simpleListTypeMap", fromChildMapConfiguration(String.class, String.class).withWrapperIdentifier("simple-list-type-map").build()).withSetterParameterDefinition("complexTypeMap", fromChildMapConfiguration(Long.class, ParsersTestObject.class).withWrapperIdentifier("complex-type-map").build()).withSetterParameterDefinition("simpleParameters", fromMultipleDefinitions(newBuilder().withAttributeDefinition(fromSimpleParameter("firstname").build()).withKey("firstname").build(), newBuilder().withAttributeDefinition(fromSimpleParameter("lastname").build()).withKey("lastname").build(), newBuilder().withAttributeDefinition(fromSimpleParameter("age").build()).withKey("age").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(ParsersTestObject.class).withWrapperIdentifier("first-child").build()).withKey("first-child").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(ParsersTestObject.class).withWrapperIdentifier("second-child").build()).withKey("second-child").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(List.class).withWrapperIdentifier("other-children").build()).withKey("other-children").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(List.class).withWrapperIdentifier("other-children-custom-collection-type").build()).withKey("other-children-custom-collection-type").build(), newBuilder().withAttributeDefinition(fromChildConfiguration(List.class).withWrapperIdentifier("other-simple-type-child-list").build()).withKey("other-simple-type-child-list-custom-key").build()).build());
    definitions.add(baseParameterCollectionParserBuilder.withIdentifier("parameter-collection-parser").build());
    definitions.add(baseParameterCollectionParserBuilder.withIdentifier("elementTypeA").build());
    definitions.add(baseParameterCollectionParserBuilder.withIdentifier("anotherElementTypeA").build());
    definitions.add(baseBuilder.withIdentifier("simple-type-child-list").withTypeDefinition(fromType(List.class)).build());
    definitions.add(baseBuilder.withIdentifier("simple-type-child-list-with-converter").withTypeDefinition(fromType(List.class)).build());
    definitions.add(baseBuilder.withIdentifier("other-children-custom-collection-type").withTypeDefinition(fromType(LinkedList.class)).build());
    definitions.add(baseBuilder.withIdentifier("other-children").withTypeDefinition(fromType(List.class)).build());
    definitions.add(baseBuilder.withIdentifier("simple-type-child-set").withTypeDefinition(fromType(TreeSet.class)).build());
    definitions.add(baseBuilder.withIdentifier("other-simple-type-child-list").withTypeDefinition(fromType(List.class)).build());
    definitions.add(baseBuilder.withIdentifier("simple-type-child").withTypeDefinition(fromType(String.class)).build());
    definitions.add(baseBuilder.withIdentifier("simple-type-child-with-converter").withTypeDefinition(fromType(String.class)).withTypeConverter(input -> input + "-with-converter").build());
    definitions.add(baseBuilder.withIdentifier("simple-type-map").withTypeDefinition(fromType(TreeMap.class)).build());
    definitions.add(baseBuilder.withIdentifier("simple-type-entry").withTypeDefinition(fromMapEntryType(String.class, Integer.class)).withKeyTypeConverter(input -> input + "-with-converter").withTypeConverter(input -> valueOf((String) input) + 1).build());
    definitions.add(baseBuilder.withIdentifier("simple-list-type-map").withTypeDefinition(fromType(Map.class)).build());
    definitions.add(baseBuilder.withIdentifier("simple-list-entry").withTypeDefinition(fromMapEntryType(String.class, List.class)).build());
    definitions.add(baseBuilder.withIdentifier("complex-type-map").withTypeDefinition(fromType(Map.class)).build());
    definitions.add(baseBuilder.withIdentifier("complex-type-entry").withTypeDefinition(fromMapEntryType(Long.class, ParsersTestObject.class)).build());
    definitions.add(baseBuilder.withIdentifier("global-element-with-object-factory").withTypeDefinition(fromType(LifecycleSensingMessageProcessor.class)).withObjectFactoryType(LifecycleSensingObjectFactory.class).build());
    definitions.add(baseBuilder.withIdentifier("inner-element-with-object-factory").withTypeDefinition(fromType(LifecycleSensingMessageProcessor.class)).withObjectFactoryType(LifecycleSensingObjectFactory.class).build());
    definitions.add(baseBuilder.withIdentifier("element-with-attribute-and-child").withTypeDefinition(fromType(ParameterAndChildElement.class)).withSetterParameterDefinition("simplePojo", fromSimpleParameter("myPojo", input -> new SimplePojo((String) input)).withDefaultValue("jose").build()).withSetterParameterDefinition("simplePojo", fromChildConfiguration(SimplePojo.class).build()).build());
    definitions.add(baseBuilder.withIdentifier("my-pojo").withTypeDefinition(fromType(SimplePojo.class)).withSetterParameterDefinition("someParameter", fromSimpleParameter("someParameter").build()).build());
    definitions.add(baseBuilder.withIdentifier("text-pojo").withTypeDefinition(fromType(SimplePojo.class)).withSetterParameterDefinition("someParameter", fromChildConfiguration(String.class).withIdentifier("text").build()).build());
    definitions.add(baseBuilder.withIdentifier("text").withTypeDefinition(fromType(String.class)).build());
    definitions.add(baseBuilder.withIdentifier("same-child-type-container").withTypeDefinition(fromType(PojoWithSameTypeChildren.class)).withSetterParameterDefinition("elementTypeA", fromChildConfiguration(ParsersTestObject.class).withIdentifier("elementTypeA").build()).withSetterParameterDefinition("anotherElementTypeA", fromChildConfiguration(ParsersTestObject.class).withIdentifier("anotherElementTypeA").build()).build());
    definitions.add(baseBuilder.withIdentifier("simple-type").withTypeConverter(o -> new SimplePojo((String) o)).withTypeDefinition(fromType(String.class)).build());
    definitions.add(baseBuilder.withIdentifier("component-created-with-object-factory").withObjectFactoryType(TestObjectFactory.class).withTypeDefinition(fromType(TestObject.class)).build());
    definitions.add(baseBuilder.withIdentifier("composite-processor-chain-router").withTypeDefinition(fromType(CompositeProcessorChainRouter.class)).withSetterParameterDefinition("processorChains", fromChildCollectionConfiguration(Object.class).build()).build());
    definitions.add(baseBuilder.withIdentifier("chain").withTypeDefinition(fromType(Component.class)).withObjectFactoryType(MessageProcessorChainObjectFactory.class).withSetterParameterDefinition("messageProcessors", fromChildCollectionConfiguration(Object.class).build()).build());
    definitions.add(baseBuilder.withIdentifier("processor-chain-router").withTypeDefinition(fromType(ProcessorChainRouter.class)).withSetterParameterDefinition("processors", fromChildCollectionConfiguration(Object.class).build()).build());
    return definitions;
}
Also used : LifecycleSensingMessageProcessor(org.mule.tests.parsers.api.LifecycleSensingMessageProcessor) KeyAttributeDefinitionPair.newBuilder(org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair.newBuilder) CompositeProcessorChainRouter(org.mule.runtime.core.privileged.processor.CompositeProcessorChainRouter) Builder.fromChildConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildConfiguration) Builder.fromChildMapConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildMapConfiguration) MessageProcessorChainObjectFactory(org.mule.runtime.core.privileged.processor.objectfactory.MessageProcessorChainObjectFactory) TreeSet(java.util.TreeSet) Builder.fromSimpleParameter(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromSimpleParameter) ComponentBuildingDefinitionProvider(org.mule.runtime.dsl.api.component.ComponentBuildingDefinitionProvider) ArrayList(java.util.ArrayList) TypeDefinition.fromMapEntryType(org.mule.runtime.dsl.api.component.TypeDefinition.fromMapEntryType) SimplePojo(org.mule.tests.parsers.api.SimplePojo) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) Integer.valueOf(java.lang.Integer.valueOf) ProcessorChainRouter(org.mule.runtime.core.privileged.processor.ProcessorChainRouter) LinkedList(java.util.LinkedList) Builder.fromChildCollectionConfiguration(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromChildCollectionConfiguration) TestObjectFactory(org.mule.tests.parsers.api.TestObjectFactory) TypeDefinition.fromType(org.mule.runtime.dsl.api.component.TypeDefinition.fromType) ParsersTestObject(org.mule.tests.parsers.api.ParsersTestObject) Set(java.util.Set) Builder.fromMultipleDefinitions(org.mule.runtime.dsl.api.component.AttributeDefinition.Builder.fromMultipleDefinitions) TestObject(org.mule.tests.parsers.api.TestObject) LifecycleSensingObjectFactory(org.mule.tests.parsers.api.LifecycleSensingObjectFactory) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) List(java.util.List) TreeMap(java.util.TreeMap) PojoWithSameTypeChildren(org.mule.tests.parsers.api.PojoWithSameTypeChildren) ParameterAndChildElement(org.mule.tests.parsers.api.ParameterAndChildElement) TestObjectFactory(org.mule.tests.parsers.api.TestObjectFactory) TreeSet(java.util.TreeSet) Set(java.util.Set) ArrayList(java.util.ArrayList) ParameterAndChildElement(org.mule.tests.parsers.api.ParameterAndChildElement) ParsersTestObject(org.mule.tests.parsers.api.ParsersTestObject) TestObject(org.mule.tests.parsers.api.TestObject) TreeMap(java.util.TreeMap) PojoWithSameTypeChildren(org.mule.tests.parsers.api.PojoWithSameTypeChildren) SimplePojo(org.mule.tests.parsers.api.SimplePojo) LinkedList(java.util.LinkedList) MessageProcessorChainObjectFactory(org.mule.runtime.core.privileged.processor.objectfactory.MessageProcessorChainObjectFactory) TreeSet(java.util.TreeSet) ParsersTestObject(org.mule.tests.parsers.api.ParsersTestObject) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) TreeMap(java.util.TreeMap)

Aggregations

ComponentBuildingDefinition (org.mule.runtime.dsl.api.component.ComponentBuildingDefinition)19 Map (java.util.Map)10 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Optional (java.util.Optional)8 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)8 SpringComponentModel (org.mule.runtime.config.internal.dsl.model.SpringComponentModel)8 Set (java.util.Set)7 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)7 String.format (java.lang.String.format)6 HashMap (java.util.HashMap)6 Consumer (java.util.function.Consumer)6 Component (org.mule.runtime.api.component.Component)6 ObjectTypeVisitor (org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 HashSet (java.util.HashSet)5 Collectors.toList (java.util.stream.Collectors.toList)5 Optional.of (java.util.Optional.of)4 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)4 ComponentBuildingDefinitionRegistry (org.mule.runtime.config.api.dsl.model.ComponentBuildingDefinitionRegistry)4