use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel 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.model.SpringComponentModel 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.model.SpringComponentModel in project mule by mulesoft.
the class EagerObjectCreator method handleRequest.
@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
Class<?> type = componentModel.getType();
if (type == null) {
return false;
}
Optional<Class<?>> foundClass = earlyCreationObjectTypes.stream().filter(clazz -> clazz.isAssignableFrom(type)).findAny();
return foundClass.map(clazz -> {
ComponentBuildingDefinition componentBuildingDefinition = createBeanDefinitionRequest.getComponentBuildingDefinition();
Object instance;
try {
instance = type.newInstance();
} catch (Exception e) {
throw new MuleRuntimeException(createStaticMessage("Could not create an instance of '%s' using default constructor. Early created object must have a default constructor", type.getName()));
}
componentBuildingDefinition.getSetterParameterDefinitions().forEach(attributeDefinition -> {
SetterAttributeDefinition setterAttributeDefinition = (SetterAttributeDefinition) attributeDefinition;
setterAttributeDefinition.getAttributeDefinition().accept(new AbstractAttributeDefinitionVisitor() {
@Override
public void onUndefinedSimpleParameters() {
Map<String, String> parameters = componentModel.getParameters();
String attributeName = setterAttributeDefinition.getAttributeName();
try {
setProperty(instance, attributeName, parameters);
} catch (Exception e) {
throw new MuleRuntimeException(e);
}
}
@Override
protected void doOnOperation(String operation) {
throw new MuleRuntimeException(createStaticMessage(format("Attribute definition with operation '%s' is not supported for earlyCreationObjects", operation)));
}
});
});
componentModel.setObjectInstance(instance);
componentModel.setBeanDefinition(rootBeanDefinition(ConstantFactoryBean.class).addConstructorArgValue(instance).getBeanDefinition());
return true;
}).orElse(false);
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class ExceptionStrategyRefBeanDefinitionCreator method handleRequest.
@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
ComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
if (componentModel.getIdentifier().equals(EXCEPTION_STRATEGY_REFERENCE_IDENTIFIER)) {
componentModel.setType(FlowExceptionHandler.class);
((SpringComponentModel) componentModel).setBeanReference(new RuntimeBeanReference(componentModel.getParameters().get(REFERENCE_ATTRIBUTE)));
return true;
}
return false;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel 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;
}
Aggregations