use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.
the class ApplicationModel method resolveComponentTypes.
/**
* Resolves the types of each component model when possible.
*/
public void resolveComponentTypes() {
// TODO MULE-13894 enable this once changes are completed and no componentBuildingDefinition is needed
// checkState(componentBuildingDefinitionRegistry.isPresent(),
// "ApplicationModel was created without a " + ComponentBuildingDefinitionProvider.class.getName());
componentBuildingDefinitionRegistry.ifPresent(buildingDefinitionRegistry -> {
executeOnEveryComponentTree(componentModel -> {
Optional<ComponentBuildingDefinition<?>> buildingDefinition = buildingDefinitionRegistry.getBuildingDefinition(componentModel.getIdentifier());
buildingDefinition.map(definition -> {
ObjectTypeVisitor typeDefinitionVisitor = new ObjectTypeVisitor(componentModel);
definition.getTypeDefinition().visit(typeDefinitionVisitor);
componentModel.setType(typeDefinitionVisitor.getType());
return definition;
}).orElseGet(() -> {
String classParameter = componentModel.getParameters().get(CLASS_ATTRIBUTE);
if (classParameter != null) {
try {
componentModel.setType(ClassUtils.getClass(classParameter));
} catch (ClassNotFoundException e) {
throw new RuntimeConfigurationException(I18nMessageFactory.createStaticMessage(String.format("Could not resolve class '%s' for component '%s'", classParameter, componentModel.getComponentLocation())));
}
}
return null;
});
});
});
}
use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.
the class ObjectTypeVisitorTestCase method typeIsInstanceOfCheckedClassFromAttribute.
@Test
public void typeIsInstanceOfCheckedClassFromAttribute() throws ClassNotFoundException {
ComponentModel componentModel = new SpringComponentModel();
componentModel.setParameter("type", "org.mule.runtime.core.internal.processor.ReferenceProcessor");
ObjectTypeVisitor visitor = new ObjectTypeVisitor(componentModel);
TypeDefinition typeDefinition = fromConfigurationAttribute("type").checkingThatIsClassOrInheritsFrom(ReferenceProcessor.class);
typeDefinition.visit(visitor);
assertTrue(ReferenceProcessor.class.isAssignableFrom(visitor.getType()));
}
use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.
the class ObjectTypeVisitorTestCase method typeIsInstanceOfClassInheritedFromCheckedClassFromAttribute.
@Test
public void typeIsInstanceOfClassInheritedFromCheckedClassFromAttribute() throws ClassNotFoundException {
ComponentModel componentModel = new SpringComponentModel();
componentModel.setParameter("type", "org.mule.runtime.core.internal.processor.ReferenceProcessor");
ObjectTypeVisitor visitor = new ObjectTypeVisitor(componentModel);
// Check that ReferenceProcessor inherits from AbstractProcessor
TypeDefinition typeDefinition = fromConfigurationAttribute("type").checkingThatIsClassOrInheritsFrom(AbstractProcessor.class);
typeDefinition.visit(visitor);
assertTrue(AbstractProcessor.class.isAssignableFrom(visitor.getType()));
}
use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor in project mule by mulesoft.
the class ObjectTypeVisitorTestCase method typeIsInstanceOfGivenClassFromAttribute.
@Test
public void typeIsInstanceOfGivenClassFromAttribute() throws ClassNotFoundException {
ComponentModel componentModel = new SpringComponentModel();
componentModel.setParameter("type", "org.mule.runtime.core.internal.processor.ReferenceProcessor");
ObjectTypeVisitor visitor = new ObjectTypeVisitor(componentModel);
TypeDefinition typeDefinition = fromConfigurationAttribute("type");
typeDefinition.visit(visitor);
assertTrue(ReferenceProcessor.class.isAssignableFrom(visitor.getType()));
}
use of org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor 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