use of org.mule.runtime.config.internal.model.ComponentModel 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;
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class ComponentLocationVisitor method findProcessorPath.
private String findProcessorPath(ComponentModel componentModel) {
ComponentModel parentComponentModel = componentModel.getParent();
List<ComponentModel> processorModels = parentComponentModel.getInnerComponents().stream().filter(ComponentModelHelper::isProcessor).collect(Collectors.toList());
int i = 0;
for (ComponentModel processorModel : processorModels) {
if (processorModel == componentModel) {
break;
}
i++;
}
return String.valueOf(i);
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class MinimalApplicationModelGenerator method enableTopLevelElementDependencies.
private void enableTopLevelElementDependencies(Set<DependencyNode> allRequiredComponentModels) {
Set<String> topLevelDendencyNames = allRequiredComponentModels.stream().filter(dependencyNode -> dependencyNode.isTopLevel()).map(dependencyNode -> dependencyNode.getComponentName()).collect(toSet());
Iterator<ComponentModel> iterator = dependencyResolver.getApplicationModel().getRootComponentModel().getInnerComponents().iterator();
while (iterator.hasNext()) {
ComponentModel componentModel = iterator.next();
if (componentModel.getNameAttribute() != null && topLevelDendencyNames.contains(componentModel.getNameAttribute())) {
componentModel.setEnabled(true);
componentModel.executedOnEveryInnerComponent(component -> component.setEnabled(true));
}
}
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class MinimalApplicationModelGenerator method getMinimalModel.
/**
* Resolves the minimal set of {@link ComponentModel componentModels} for the components that pass the
* {@link LazyComponentInitializer.ComponentLocationFilter}.
*
* @param predicate to select the {@link ComponentModel componentModels} to be enabled.
* @return the generated {@link ApplicationModel} with the minimal set of {@link ComponentModel}s required.
*/
public ApplicationModel getMinimalModel(Predicate<ComponentModel> predicate) {
List<ComponentModel> required = dependencyResolver.findRequiredComponentModels(predicate);
required.stream().forEach(componentModel -> {
final DefaultComponentLocation componentLocation = componentModel.getComponentLocation();
if (componentLocation != null) {
enableComponentDependencies(componentModel);
}
});
return dependencyResolver.getApplicationModel();
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class MacroExpansionModuleModel method getModuleGlobalElements.
private List<ComponentModel> getModuleGlobalElements() {
List<ComponentModel> moduleGlobalElements = new ArrayList<>();
Optional<ConfigurationModel> config = getConfigurationModel();
if (config.isPresent() && config.get().getModelProperty(GlobalElementComponentModelModelProperty.class).isPresent()) {
GlobalElementComponentModelModelProperty globalElementComponentModelModelProperty = config.get().getModelProperty(GlobalElementComponentModelModelProperty.class).get();
moduleGlobalElements = globalElementComponentModelModelProperty.getGlobalElements();
}
return moduleGlobalElements;
}
Aggregations