use of org.mule.runtime.config.internal.dsl.spring.WrapperElementType.MAP in project mule by mulesoft.
the class BeanDefinitionFactory method getWrapperIdentifierAndTypeMap.
private <T> Map<String, WrapperElementType> getWrapperIdentifierAndTypeMap(ComponentBuildingDefinition<T> buildingDefinition) {
final Map<String, WrapperElementType> wrapperIdentifierAndTypeMap = new HashMap<>();
AbstractAttributeDefinitionVisitor wrapperIdentifiersCollector = new AbstractAttributeDefinitionVisitor() {
@Override
public void onComplexChildCollection(Class<?> type, Optional<String> wrapperIdentifierOptional) {
wrapperIdentifierOptional.ifPresent(wrapperIdentifier -> wrapperIdentifierAndTypeMap.put(wrapperIdentifier, COLLECTION));
}
@Override
public void onComplexChild(Class<?> type, Optional<String> wrapperIdentifierOptional, Optional<String> childIdentifier) {
wrapperIdentifierOptional.ifPresent(wrapperIdentifier -> wrapperIdentifierAndTypeMap.put(wrapperIdentifier, SINGLE));
}
@Override
public void onComplexChildMap(Class<?> keyType, Class<?> valueType, String wrapperIdentifier) {
wrapperIdentifierAndTypeMap.put(wrapperIdentifier, MAP);
}
@Override
public void onMultipleValues(KeyAttributeDefinitionPair[] definitions) {
for (KeyAttributeDefinitionPair attributeDefinition : definitions) {
attributeDefinition.getAttributeDefinition().accept(this);
}
}
};
Consumer<AttributeDefinition> collectWrappersConsumer = attributeDefinition -> attributeDefinition.accept(wrapperIdentifiersCollector);
buildingDefinition.getSetterParameterDefinitions().stream().map(setterAttributeDefinition -> setterAttributeDefinition.getAttributeDefinition()).forEach(collectWrappersConsumer);
buildingDefinition.getConstructorAttributeDefinition().stream().forEach(collectWrappersConsumer);
return wrapperIdentifierAndTypeMap;
}
use of org.mule.runtime.config.internal.dsl.spring.WrapperElementType.MAP 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;
}
Aggregations