use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class SpringPostProcessorIocHelper method toBeanDefinitions.
@Override
public List toBeanDefinitions(List<ComponentConfiguration> components) {
ManagedList responseMessageProcessorsBeanList = new ManagedList();
components.forEach(responseProcessorComponentModel -> {
SpringComponentModel springComponentModel = (SpringComponentModel) responseProcessorComponentModel.getProperty(COMPONENT_MODEL_KEY).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Component configuration is expected to have the component model at this point.")));
BeanDefinition beanDefinition = springComponentModel.getBeanDefinition();
responseMessageProcessorsBeanList.add(beanDefinition != null ? beanDefinition : springComponentModel.getBeanReference());
});
return responseMessageProcessorsBeanList;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class BeanDefinitionFactory method processComponentWrapper.
private void processComponentWrapper(SpringComponentModel componentModel) {
ComponentBuildingDefinition<?> parentBuildingDefinition = componentBuildingDefinitionRegistry.getBuildingDefinition(componentModel.getParent().getIdentifier()).get();
Map<String, WrapperElementType> wrapperIdentifierAndTypeMap = getWrapperIdentifierAndTypeMap(parentBuildingDefinition);
WrapperElementType wrapperElementType = wrapperIdentifierAndTypeMap.get(componentModel.getIdentifier().getName());
if (wrapperElementType.equals(SINGLE)) {
if (componentModel.getInnerComponents().isEmpty()) {
String location = componentModel.getComponentLocation() != null ? componentModel.getComponentLocation().getLocation() : "";
throw new IllegalStateException(format("Element [%s] located at [%s] does not have any child element declared, but one is required.", componentModel.getIdentifier(), location));
}
final SpringComponentModel firstComponentModel = (SpringComponentModel) componentModel.getInnerComponents().get(0);
componentModel.setType(firstComponentModel.getType());
componentModel.setBeanDefinition(firstComponentModel.getBeanDefinition());
componentModel.setBeanReference(firstComponentModel.getBeanReference());
} else {
throw new IllegalStateException(format("Element %s does not have a building definition and it should since it's of type %s", componentModel.getIdentifier(), wrapperElementType));
}
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel 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;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel 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;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class ComponentConfigurationBuilder method collectComplexParametersWithTypes.
private List<ComponentValue> 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());
}
Aggregations