Search in sources :

Example 1 with ObjectTypeVisitor

use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.

the class CollectionBeanDefinitionCreator method handleRequest.

@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
    SpringComponentModel componentModel = (SpringComponentModel) createBeanDefinitionRequest.getComponentModel();
    ComponentBuildingDefinition componentBuildingDefinition = createBeanDefinitionRequest.getComponentBuildingDefinition();
    ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(componentModel);
    componentBuildingDefinition.getTypeDefinition().visit(objectTypeVisitor);
    if (Collection.class.isAssignableFrom(objectTypeVisitor.getType())) {
        componentModel.setType(objectTypeVisitor.getType());
        ManagedList<Object> managedList = new ManagedList<>();
        for (ComponentModel innerComponent : componentModel.getInnerComponents()) {
            SpringComponentModel innerSpringComp = (SpringComponentModel) innerComponent;
            Object bean = innerSpringComp.getBeanDefinition() == null ? innerSpringComp.getBeanReference() : innerSpringComp.getBeanDefinition();
            managedList.add(bean);
        }
        componentModel.setBeanDefinition(BeanDefinitionBuilder.genericBeanDefinition(objectTypeVisitor.getType()).addConstructorArgValue(managedList).getBeanDefinition());
        return true;
    }
    return false;
}
Also used : SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ManagedList(org.springframework.beans.factory.support.ManagedList) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)

Example 2 with ObjectTypeVisitor

use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.

the class CommonBeanDefinitionCreator method createBeanDefinitionBuilderFromObjectFactory.

private BeanDefinitionBuilder createBeanDefinitionBuilderFromObjectFactory(final SpringComponentModel componentModel, final ComponentBuildingDefinition componentBuildingDefinition) {
    ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(componentModel);
    componentBuildingDefinition.getTypeDefinition().visit(objectTypeVisitor);
    Class<?> objectFactoryType = componentBuildingDefinition.getObjectFactoryType();
    Optional<Consumer<Object>> instanceCustomizationFunctionOptional;
    Map<String, Object> customProperties = getTransformerCustomProperties(componentModel);
    if (customProperties.isEmpty()) {
        instanceCustomizationFunctionOptional = empty();
    } else {
        instanceCustomizationFunctionOptional = of(object -> injectSpringProperties(customProperties, object));
    }
    return rootBeanDefinition(objectFactoryClassRepository.getObjectFactoryClass(componentBuildingDefinition, objectFactoryType, objectTypeVisitor.getType(), new LazyValue<>(() -> componentModel.getBeanDefinition().isLazyInit()), instanceCustomizationFunctionOptional));
}
Also used : BeanDefinitionPostProcessor(org.mule.runtime.config.privileged.dsl.BeanDefinitionPostProcessor) Optional.of(java.util.Optional.of) CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) SecurityFilter(org.mule.runtime.core.api.security.SecurityFilter) MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) ROOT_MACRO_EXPANDED_FLOW_CONTAINER_NAME(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel.ROOT_MACRO_EXPANDED_FLOW_CONTAINER_NAME) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) MULE_PROPERTY_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTY_IDENTIFIER) Collectors.toMap(java.util.stream.Collectors.toMap) SecurityFilterMessageProcessor(org.mule.runtime.core.privileged.processor.SecurityFilterMessageProcessor) Map(java.util.Map) CUSTOM_TRANSFORMER_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.CUSTOM_TRANSFORMER_IDENTIFIER) Pair(org.mule.runtime.api.util.Pair) ANNOTATIONS_ELEMENT_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.ANNOTATIONS_ELEMENT_IDENTIFIER) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) SPRING_PROTOTYPE_OBJECT(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory.SPRING_PROTOTYPE_OBJECT) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) XmlCustomAttributeHandler(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) List(java.util.List) Optional(java.util.Optional) BeanUtils.copyProperty(org.apache.commons.beanutils.BeanUtils.copyProperty) QName(javax.xml.namespace.QName) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Optional.empty(java.util.Optional.empty) XmlCustomAttributeHandler.from(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler.from) DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionBuilder.genericBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) HashMap(java.util.HashMap) ANNOTATIONS_PROPERTY_NAME(org.mule.runtime.api.component.Component.ANNOTATIONS_PROPERTY_NAME) XmlMetadataAnnotations(org.mule.runtime.config.internal.parsers.XmlMetadataAnnotations) ArrayList(java.util.ArrayList) Component(org.mule.runtime.api.component.Component) Node(org.w3c.dom.Node) ServiceConfigurationError(java.util.ServiceConfigurationError) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ModuleOperationMessageProcessorChainFactoryBean(org.mule.runtime.config.internal.factories.ModuleOperationMessageProcessorChainFactoryBean) Collections.emptyMap(java.util.Collections.emptyMap) MULE_PROPERTIES_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTIES_IDENTIFIER) PropertyComponentUtils.getPropertyValueFromPropertyComponent(org.mule.runtime.config.internal.dsl.spring.PropertyComponentUtils.getPropertyValueFromPropertyComponent) LocationExecutionContextProvider.addMetadataAnnotationsFromXml(org.mule.runtime.core.privileged.execution.LocationExecutionContextProvider.addMetadataAnnotationsFromXml) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) Consumer(java.util.function.Consumer) LazyValue(org.mule.runtime.api.util.LazyValue) Element(org.w3c.dom.Element) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) BeanDefinitionBuilder.rootBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) LazyValue(org.mule.runtime.api.util.LazyValue) Consumer(java.util.function.Consumer) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)

Example 3 with ObjectTypeVisitor

use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.

the class CommonBeanDefinitionCreator method retrieveComponentType.

private Class<?> retrieveComponentType(final ComponentModel componentModel, ComponentBuildingDefinition componentBuildingDefinition) {
    ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(componentModel);
    componentBuildingDefinition.getTypeDefinition().visit(objectTypeVisitor);
    return objectTypeVisitor.getType();
}
Also used : ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)

Example 4 with ObjectTypeVisitor

use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.

the class MapBeanDefinitionCreator method handleRequest.

@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
    SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
    ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(componentModel);
    ComponentBuildingDefinition componentBuildingDefinition = createBeanDefinitionRequest.getComponentBuildingDefinition();
    componentBuildingDefinition.getTypeDefinition().visit(objectTypeVisitor);
    Class<?> type = objectTypeVisitor.getType();
    if (Map.class.isAssignableFrom(type) && componentBuildingDefinition.getObjectFactoryType() == null) {
        ManagedList managedList = componentModel.getInnerComponents().stream().map(c -> ((SpringComponentModel) c).getBeanDefinition()).collect(toCollection(ManagedList::new));
        componentModel.setBeanDefinition(BeanDefinitionBuilder.genericBeanDefinition(MapFactoryBean.class).addConstructorArgValue(managedList).addConstructorArgValue(type).getBeanDefinition());
        return true;
    }
    return false;
}
Also used : Collectors.toCollection(java.util.stream.Collectors.toCollection) ManagedList(org.springframework.beans.factory.support.ManagedList) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Map(java.util.Map) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ManagedList(org.springframework.beans.factory.support.ManagedList) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) Map(java.util.Map) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)

Example 5 with ObjectTypeVisitor

use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.

the class MapEntryBeanDefinitionCreator method handleRequest.

@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
    ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(createBeanDefinitionRequest.getComponentModel());
    createBeanDefinitionRequest.getComponentBuildingDefinition().getTypeDefinition().visit(objectTypeVisitor);
    Class<?> type = objectTypeVisitor.getType();
    if (!(MapEntryType.class.isAssignableFrom(type))) {
        return false;
    }
    SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
    ComponentBuildingDefinition componentBuildingDefinition = createBeanDefinitionRequest.getComponentBuildingDefinition();
    componentModel.setType(type);
    final Object key = componentModel.getParameters().get(ENTRY_TYPE_KEY_PARAMETER_NAME);
    Object keyBeanDefinition = getConvertibleBeanDefinition(objectTypeVisitor.getMapEntryType().get().getKeyType(), key, componentBuildingDefinition.getKeyTypeConverter());
    Object value = null;
    // MULE-11984: Check that generated map entries are not empty
    if (componentModel.getParameters().get(ENTRY_TYPE_VALUE_REF_PARAMETER_NAME) != null) {
        value = new RuntimeBeanReference(componentModel.getParameters().get(ENTRY_TYPE_VALUE_REF_PARAMETER_NAME));
    } else {
        value = getValue(objectTypeVisitor, componentModel, componentBuildingDefinition);
    }
    AbstractBeanDefinition beanDefinition = genericBeanDefinition(MapEntry.class).addConstructorArgValue(keyBeanDefinition).addConstructorArgValue(value).getBeanDefinition();
    componentModel.setBeanDefinition(beanDefinition);
    return true;
}
Also used : MapEntry(org.mule.runtime.dsl.api.component.MapEntry) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)

Aggregations

ObjectTypeVisitor (org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)12 SpringComponentModel (org.mule.runtime.config.internal.dsl.model.SpringComponentModel)10 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)6 Test (org.junit.Test)5 ComponentBuildingDefinition (org.mule.runtime.dsl.api.component.ComponentBuildingDefinition)5 TypeDefinition (org.mule.runtime.dsl.api.component.TypeDefinition)5 Map (java.util.Map)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 ArrayList (java.util.ArrayList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Optional (java.util.Optional)2 Optional.empty (java.util.Optional.empty)2 Optional.of (java.util.Optional.of)2 Set (java.util.Set)2 Consumer (java.util.function.Consumer)2 QName (javax.xml.namespace.QName)2 AbstractComponent (org.mule.runtime.api.component.AbstractComponent)2 Component (org.mule.runtime.api.component.Component)2