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;
}
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));
}
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();
}
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;
}
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;
}
Aggregations