use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class MapEntryBeanDefinitionCreator method handleRequest.
@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(createBeanDefinitionRequest.getComponentModel());
createBeanDefinitionRequest.getComponentBuildingDefinition().getTypeDefinition().visit(objectTypeVisitor);
Class<?> type = objectTypeVisitor.getType();
if (!(MapEntryType.class.isAssignableFrom(type))) {
return false;
}
SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
ComponentBuildingDefinition componentBuildingDefinition = createBeanDefinitionRequest.getComponentBuildingDefinition();
componentModel.setType(type);
final Object key = componentModel.getParameters().get(ENTRY_TYPE_KEY_PARAMETER_NAME);
Object keyBeanDefinition = getConvertibleBeanDefinition(objectTypeVisitor.getMapEntryType().get().getKeyType(), key, componentBuildingDefinition.getKeyTypeConverter());
Object value = null;
// MULE-11984: Check that generated map entries are not empty
if (componentModel.getParameters().get(ENTRY_TYPE_VALUE_REF_PARAMETER_NAME) != null) {
value = new RuntimeBeanReference(componentModel.getParameters().get(ENTRY_TYPE_VALUE_REF_PARAMETER_NAME));
} else {
value = getValue(objectTypeVisitor, componentModel, componentBuildingDefinition);
}
AbstractBeanDefinition beanDefinition = genericBeanDefinition(MapEntry.class).addConstructorArgValue(keyBeanDefinition).addConstructorArgValue(value).getBeanDefinition();
componentModel.setBeanDefinition(beanDefinition);
return true;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class ObjectBeanDefinitionCreator method handleRequest.
@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
SpringComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
if (!componentModel.getIdentifier().equals(buildFromStringRepresentation("mule:object"))) {
return false;
}
String refParameterValue = componentModel.getParameters().get(REF_PARAMETER);
String classParameterValue = componentModel.getParameters().get(CLASS_PARAMETER);
if (refParameterValue != null && classParameterValue != null) {
throw new RuntimeConfigurationException(createStaticMessage(format("Object cannot contain both '%s' and '%s' parameters. Offending resource is '%s'", REF_PARAMETER, CLASS_PARAMETER, componentModel.getComponentLocation())));
}
if (refParameterValue == null && classParameterValue == null) {
throw new RuntimeConfigurationException(createStaticMessage(format("Object must contain '%s' or '%s' parameter. Offending resource is '%s'", REF_PARAMETER, CLASS_PARAMETER, componentModel.getComponentLocation())));
}
if (refParameterValue != null) {
componentModel.setBeanReference(new RuntimeBeanReference(refParameterValue));
}
if (classParameterValue != null) {
BeanDefinitionBuilder beanDefinitionBuilder;
final Class<?> classParameter;
try {
classParameter = ClassUtils.getClass(classParameterValue);
} catch (ClassNotFoundException e) {
throw new RuntimeConfigurationException(createStaticMessage(format("Could not resolve class '%s' for component '%s'", classParameterValue, componentModel.getComponentLocation())));
}
beanDefinitionBuilder = rootBeanDefinition(addAnnotationsToClass(classParameter));
processMuleProperties(componentModel, beanDefinitionBuilder, null);
componentModel.setBeanDefinition(beanDefinitionBuilder.getBeanDefinition());
}
return true;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel 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.model.SpringComponentModel 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.model.SpringComponentModel 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()));
}
Aggregations