use of org.mule.runtime.dsl.api.component.TypeConverter in project mule by mulesoft.
the class SimpleTypeBeanDefinitionCreator method handleRequest.
@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(createBeanDefinitionRequest.getComponentModel());
createBeanDefinitionRequest.getComponentBuildingDefinition().getTypeDefinition().visit(objectTypeVisitor);
Class<?> type = objectTypeVisitor.getType();
if (isSimpleType(type)) {
SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
componentModel.setType(type);
Map<String, String> parameters = componentModel.getParameters();
if (parameters.size() >= 2) {
// Component model has more than one parameter when it's supposed to have at most one parameter
return false;
}
if (componentModel.getTextContent() != null && !componentModel.getParameters().isEmpty()) {
// Component model has both a parameter and an inner content
return false;
}
final String value = componentModel.getTextContent() != null ? componentModel.getTextContent() : parameters.values().iterator().next();
Optional<TypeConverter> typeConverterOptional = createBeanDefinitionRequest.getComponentBuildingDefinition().getTypeConverter();
componentModel.setBeanDefinition(getConvertibleBeanDefinition(type, value, typeConverterOptional));
return true;
}
return false;
}
Aggregations