use of org.mule.runtime.config.internal.model.ComponentModel 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.model.ComponentModel 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.model.ComponentModel in project mule by mulesoft.
the class BeanDefinitionFactory method resolveComponent.
private BeanDefinition resolveComponent(ComponentModel parentComponentModel, SpringComponentModel componentModel, BeanDefinitionRegistry registry, BiConsumer<ComponentModel, BeanDefinitionRegistry> componentDefinitionModelProcessor, SpringConfigurationComponentLocator componentLocator) {
if (isComponentIgnored(componentModel.getIdentifier())) {
return null;
}
if (!componentModel.isEnabled()) {
// Just register the location, for support of lazyInit scenarios
componentLocator.addComponentLocation(componentModel.getComponentLocation());
return null;
}
resolveComponentBeanDefinition(parentComponentModel, componentModel);
componentDefinitionModelProcessor.accept(componentModel, registry);
// TODO MULE-9638: Once we migrate all core definitions we need to define a mechanism for customizing
// how core constructs are processed.
processMuleConfiguration(componentModel, registry);
processMuleSecurityManager(componentModel, registry);
processRaiseError(componentModel);
componentBuildingDefinitionRegistry.getBuildingDefinition(componentModel.getIdentifier()).ifPresent(componentBuildingDefinition -> {
if ((componentModel.getType() != null) && Component.class.isAssignableFrom(componentModel.getType())) {
addAnnotation(ANNOTATION_NAME, componentModel.getIdentifier(), componentModel);
// We need to use a mutable map since spring will resolve the properties placeholder present in the value if needed
// and it will be done by mutating the same map.
addAnnotation(ANNOTATION_PARAMETERS, new HashMap<>(componentModel.getParameters()), componentModel);
// add any error mappings if present
List<ComponentModel> errorMappingComponents = componentModel.getInnerComponents().stream().filter(innerComponent -> ERROR_MAPPING_IDENTIFIER.equals(innerComponent.getIdentifier())).collect(toList());
if (!errorMappingComponents.isEmpty()) {
addAnnotation(ANNOTATION_ERROR_MAPPINGS, errorMappingComponents.stream().map(innerComponent -> {
Map<String, String> parameters = innerComponent.getParameters();
ComponentIdentifier source = buildFromStringRepresentation(parameters.get(SOURCE_TYPE));
ErrorType errorType = errorTypeRepository.lookupErrorType(source).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not find error '%s'.", source)));
ErrorTypeMatcher errorTypeMatcher = new SingleErrorTypeMatcher(errorType);
ErrorType targetValue = resolveErrorType(parameters.get(TARGET_TYPE));
return new ErrorMapping(errorTypeMatcher, targetValue);
}).collect(toList()), componentModel);
}
componentLocator.addComponentLocation(componentModel.getComponentLocation());
}
});
addAnnotation(LOCATION_KEY, componentModel.getComponentLocation(), componentModel);
BeanDefinition beanDefinition = componentModel.getBeanDefinition();
return beanDefinition;
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class ComponentConfigurationBuilder method collectComplexParametersWithTypes.
private List<ComponentValue> collectComplexParametersWithTypes(ComponentModel componentModel) {
/*
* TODO: MULE-9638 This ugly code is required since we need to get the object type from the bean definition. This code will go
* away one we remove the old parsing method.
*/
return componentModel.getInnerComponents().stream().filter(child -> child.isEnabled()).map(model -> {
// When it comes from old model it does not have the type set
Class<?> beanDefinitionType = model.getType();
final SpringComponentModel springModel = (SpringComponentModel) model;
if (beanDefinitionType == null) {
if (springModel.getBeanDefinition() == null) {
// Some component do not have a bean definition since the element parsing is ignored. i.e: annotations
return null;
} else {
try {
String beanClassName = springModel.getBeanDefinition().getBeanClassName();
if (beanClassName != null) {
beanDefinitionType = org.apache.commons.lang3.ClassUtils.getClass(beanClassName);
} else {
// Happens in case of spring:property
beanDefinitionType = Object.class;
}
} catch (ClassNotFoundException e) {
logger.debug("Exception trying to determine ComponentModel type: ", e);
beanDefinitionType = Object.class;
}
}
}
Object bean = springModel.getBeanDefinition() != null ? springModel.getBeanDefinition() : springModel.getBeanReference();
return new ComponentValue(model, beanDefinitionType, bean);
}).filter(beanDefinitionTypePair -> beanDefinitionTypePair != null).collect(toList());
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class PropertiesMapBeanDefinitionCreator method handleRequest.
@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
if (componentModel.getIdentifier().equals(MULE_PROPERTIES_IDENTIFIER) || componentModel.getIdentifier().equals(MULE_PROPERTY_IDENTIFIER)) {
ManagedMap<Object, Object> managedMap;
if (componentModel.getIdentifier().equals(MULE_PROPERTIES_IDENTIFIER)) {
managedMap = createManagedMapFromEntries(componentModel);
} else {
managedMap = new ManagedMap<>();
ComponentModel parentComponentModel = componentModel.getParent();
parentComponentModel.getInnerComponents().stream().filter(childComponentModel -> childComponentModel.getIdentifier().equals(MULE_PROPERTY_IDENTIFIER)).forEach(childComponentModel -> {
processAndAddMapProperty(childComponentModel, managedMap);
});
}
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(HashMap.class);
componentModel.setBeanDefinition(beanDefinitionBuilder.addConstructorArgValue(managedMap).getBeanDefinition());
return true;
}
return false;
}
Aggregations