Search in sources :

Example 1 with TypeConverter

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;
}
Also used : TypeConverter(org.mule.runtime.dsl.api.component.TypeConverter) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)

Aggregations

SpringComponentModel (org.mule.runtime.config.internal.dsl.model.SpringComponentModel)1 ObjectTypeVisitor (org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)1 TypeConverter (org.mule.runtime.dsl.api.component.TypeConverter)1