Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.runtime.config.internal.dsl.spring;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toList;
import static org.mule.runtime.config.internal.dsl.spring.CommonBeanDefinitionCreator.areMatchingTypes;
import org.mule.runtime.config.internal.model.ComponentModel;
import org.mule.runtime.config.internal.dsl.model.SpringComponentModel;
import org.mule.runtime.dsl.api.component.AttributeDefinition;
import org.mule.runtime.dsl.api.component.AttributeDefinitionVisitor;
import org.mule.runtime.dsl.api.component.ComponentBuildingDefinition;
import org.mule.runtime.dsl.api.component.KeyAttributeDefinitionPair;
import org.mule.runtime.dsl.api.component.SetterAttributeDefinition;
import org.mule.runtime.dsl.api.component.TypeConverter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Predicate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.support.ManagedMap;
/**
* Based on the object building definition provided by {@link org.mule.runtime.dsl.api.component.ComponentBuildingDefinition} and
* the user configuration defined in {@link ComponentModel} it populates all the
* spring {@link org.springframework.beans.factory.config.BeanDefinition} attributes using the helper class
* {@link BeanDefinitionBuilderHelper}.
* {@link BeanDefinitionBuilderHelper}.
*
* @since 4.0
*/
class ComponentConfigurationBuilder {
private static final Logger logger = LoggerFactory.getLogger(ComponentConfigurationBuilder.class);
private final BeanDefinitionBuilderHelper beanDefinitionBuilderHelper;
private final ObjectReferencePopulator objectReferencePopulator = new ObjectReferencePopulator();
private final List complexParameters;
private final Map simpleParameters;
private final ComponentModel componentModel;
private final ComponentBuildingDefinition componentBuildingDefinition;
public ComponentConfigurationBuilder(ComponentModel componentModel, ComponentBuildingDefinition componentBuildingDefinition,
BeanDefinitionBuilderHelper beanDefinitionBuilderHelper) {
this.componentModel = componentModel;
this.componentBuildingDefinition = componentBuildingDefinition;
this.beanDefinitionBuilderHelper = beanDefinitionBuilderHelper;
this.simpleParameters = new HashMap<>(componentModel.getParameters());
this.complexParameters = collectComplexParametersWithTypes(componentModel);
}
public void processConfiguration() {
componentBuildingDefinition.getIgnoredConfigurationParameters().stream().forEach(simpleParameters::remove);
for (SetterAttributeDefinition setterAttributeDefinition : componentBuildingDefinition.getSetterParameterDefinitions()) {
AttributeDefinition attributeDefinition = setterAttributeDefinition.getAttributeDefinition();
attributeDefinition.accept(setterVisitor(setterAttributeDefinition.getAttributeName(), attributeDefinition));
}
for (AttributeDefinition attributeDefinition : componentBuildingDefinition.getConstructorAttributeDefinition()) {
attributeDefinition.accept(constructorVisitor());
}
}
private List collectComplexParametersWithTypes(ComponentModel componentModel) {
/*
* TODO: MULE-9638 This ugly code is required since we need to get the object type from the bean definition. This code will go
* away one we remove the old parsing method.
*/
return componentModel.getInnerComponents().stream().filter(child -> child.isEnabled()).map(model -> {
// When it comes from old model it does not have the type set
Class beanDefinitionType = model.getType();
final SpringComponentModel springModel = (SpringComponentModel) model;
if (beanDefinitionType == null) {
if (springModel.getBeanDefinition() == null) {
// Some component do not have a bean definition since the element parsing is ignored. i.e: annotations
return null;
} else {
try {
String beanClassName = springModel.getBeanDefinition().getBeanClassName();
if (beanClassName != null) {
beanDefinitionType = org.apache.commons.lang3.ClassUtils.getClass(beanClassName);
} else {
// Happens in case of spring:property
beanDefinitionType = Object.class;
}
} catch (ClassNotFoundException e) {
logger.debug("Exception trying to determine ComponentModel type: ", e);
beanDefinitionType = Object.class;
}
}
}
Object bean = springModel.getBeanDefinition() != null ? springModel.getBeanDefinition() : springModel.getBeanReference();
return new ComponentValue(model, beanDefinitionType, bean);
}).filter(beanDefinitionTypePair -> beanDefinitionTypePair != null).collect(toList());
}
private ConfigurableAttributeDefinitionVisitor constructorVisitor() {
return new ConfigurableAttributeDefinitionVisitor(beanDefinitionBuilderHelper::addConstructorValue);
}
private ConfigurableAttributeDefinitionVisitor setterVisitor(String propertyName, AttributeDefinition attributeDefinition) {
DefaultValueVisitor defaultValueVisitor = new DefaultValueVisitor();
attributeDefinition.accept(defaultValueVisitor);
Optional