use of org.mule.runtime.dsl.api.component.SetterAttributeDefinition in project mule by mulesoft.
the class ComponentConfigurationBuilder method processConfiguration.
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());
}
}
use of org.mule.runtime.dsl.api.component.SetterAttributeDefinition 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);
}
Aggregations