use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel 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;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel 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;
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class ObjectTypeVisitorTestCase method testFailsIfTypeIsNotOfCheckedClass.
@Test
public void testFailsIfTypeIsNotOfCheckedClass() throws ClassNotFoundException {
exception.expect(MuleRuntimeException.class);
exception.expectMessage("is not the same nor inherits from");
ComponentModel componentModel = new SpringComponentModel();
componentModel.setParameter("type", this.getClass().getName());
ObjectTypeVisitor visitor = new ObjectTypeVisitor(componentModel);
TypeDefinition typeDefinition = fromConfigurationAttribute("type").checkingThatIsClassOrInheritsFrom(ReferenceProcessor.class);
typeDefinition.visit(visitor);
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class ObjectTypeVisitorTestCase method typeIsInstanceOfGivenClass.
@Test
public void typeIsInstanceOfGivenClass() {
ObjectTypeVisitor visitor = new ObjectTypeVisitor(new SpringComponentModel());
TypeDefinition typeDefinition = fromType(String.class);
typeDefinition.visit(visitor);
assertTrue(String.class.isAssignableFrom(visitor.getType()));
}
use of org.mule.runtime.config.internal.dsl.model.SpringComponentModel in project mule by mulesoft.
the class MuleArtifactContext method createApplicationComponents.
/**
* Creates te definition for all the objects to be created form the enabled components in the {@code applicationModel}.
*
* @param beanFactory the bean factory in which definition must be created.
* @param applicationModel the artifact application model.
* @param mustBeRoot if the component must be root to be created.
* @return an order list of the created bean names. The order must be respected for the creation of the objects.
*/
protected List<String> createApplicationComponents(DefaultListableBeanFactory beanFactory, ApplicationModel applicationModel, boolean mustBeRoot) {
// This should only be done once at the initial application model creation, called from Spring
List<Pair<ComponentModel, Optional<String>>> objectProvidersByName = lookObjectProvidersComponentModels(applicationModel);
List<String> createdComponentModels = new ArrayList<>();
applicationModel.executeOnEveryMuleComponentTree(cm -> {
SpringComponentModel componentModel = (SpringComponentModel) cm;
if (!mustBeRoot || componentModel.isRoot()) {
if (componentModel.getIdentifier().equals(MULE_IDENTIFIER) || componentModel.getIdentifier().equals(MULE_DOMAIN_IDENTIFIER) || componentModel.getIdentifier().equals(MULE_EE_DOMAIN_IDENTIFIER)) {
return;
}
SpringComponentModel parentComponentModel = componentModel.getParent() != null ? (SpringComponentModel) componentModel.getParent() : (SpringComponentModel) applicationModel.getRootComponentModel();
if (componentModel.isEnabled()) {
if (componentModel.getNameAttribute() != null && componentModel.isRoot()) {
createdComponentModels.add(componentModel.getNameAttribute());
}
beanDefinitionFactory.resolveComponentRecursively(parentComponentModel, componentModel, beanFactory, (resolvedComponentModel, registry) -> {
SpringComponentModel resolvedSpringComponentModel = (SpringComponentModel) resolvedComponentModel;
if (resolvedComponentModel.isRoot()) {
String nameAttribute = resolvedComponentModel.getNameAttribute();
if (resolvedComponentModel.getIdentifier().equals(CONFIGURATION_IDENTIFIER)) {
nameAttribute = OBJECT_MULE_CONFIGURATION;
} else if (nameAttribute == null) {
// This may be a configuration that does not requires a name.
nameAttribute = uniqueValue(resolvedSpringComponentModel.getBeanDefinition().getBeanClassName());
}
registry.registerBeanDefinition(nameAttribute, resolvedSpringComponentModel.getBeanDefinition());
postProcessBeanDefinition(componentModel, registry, nameAttribute);
}
}, null, componentLocator);
} else {
beanDefinitionFactory.resolveComponentRecursively(parentComponentModel, componentModel, beanFactory, null, null, componentLocator);
}
componentLocator.addComponentLocation(cm.getComponentLocation());
}
});
this.objectProviders.addAll(objectProvidersByName.stream().map(pair -> (ConfigurableObjectProvider) pair.getFirst().getObjectInstance()).collect(toList()));
registerObjectFromObjectProviders(beanFactory);
Set<String> alwaysEnabledComponents = dependencyResolver.resolveAlwaysEnabledComponents().stream().map(dependencyNode -> dependencyNode.getComponentName()).collect(toSet());
Set<String> objectProviderNames = objectProvidersByName.stream().map(Pair::getSecond).filter(Optional::isPresent).map(Optional::get).collect(toSet());
// Put object providers first, then always enabled components, then the rest
createdComponentModels.sort(Comparator.comparing(beanName -> {
if (objectProviderNames.contains(beanName)) {
return 1;
} else if (alwaysEnabledComponents.contains(beanName)) {
return 2;
} else {
return 3;
}
}));
return createdComponentModels;
}
Aggregations