use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method addConnectionProvider.
/**
* Adds a connection provider if (a) there's at least one global element that has test connection or (b) there's at least one
* <property/> that has been placed within a <connection/> wrapper in the <module/> element.
*
* @param configurationDeclarer declarer to add the {@link ConnectionProviderDeclarer} if applies.
* @param connectionProperties collection of <property/>s that should be added to the {@link ConnectionProviderDeclarer}.
* @param globalElementsComponentModel collection of global elements where through {@link #getTestConnectionGlobalElement(List, Set)}
* will look for one that supports test connectivity.
* @param extensions used also in {@link #getTestConnectionGlobalElement(List, Set)}, through the {@link #findTestConnectionGlobalElementFrom},
* as the XML of the extensions might change of the values that the {@link ExtensionModel} has (heavily relies
* on {@link DslSyntaxResolver#resolve(NamedObject)}).
*/
private void addConnectionProvider(ConfigurationDeclarer configurationDeclarer, List<ComponentModel> connectionProperties, List<ComponentModel> globalElementsComponentModel, Set<ExtensionModel> extensions) {
final Optional<ComponentModel> testConnectionGlobalElementOptional = getTestConnectionGlobalElement(globalElementsComponentModel, extensions);
if (testConnectionGlobalElementOptional.isPresent() || !connectionProperties.isEmpty()) {
final ConnectionProviderDeclarer connectionProviderDeclarer = configurationDeclarer.withConnectionProvider(MODULE_CONNECTION_GLOBAL_ELEMENT_NAME);
connectionProviderDeclarer.withConnectionManagementType(ConnectionManagementType.NONE);
connectionProperties.stream().forEach(param -> extractProperty(connectionProviderDeclarer, param));
testConnectionGlobalElementOptional.ifPresent(testConnectionGlobalElement -> {
final String testConnectionGlobalElementName = testConnectionGlobalElement.getParameters().get(GLOBAL_ELEMENT_NAME_ATTRIBUTE);
connectionProviderDeclarer.withModelProperty(new TestConnectionGlobalElementModelProperty(testConnectionGlobalElementName));
});
// TODO until MULE-12734, all test connection must be shut down in smart connectors
connectionProviderDeclarer.supportsConnectivityTesting(false);
}
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method extractOutputType.
private void extractOutputType(OutputDeclarer outputDeclarer, ComponentIdentifier componentIdentifier, ComponentModel operationModel, Optional<MetadataType> calculatedOutput) {
Optional<ComponentModel> outputAttributesComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(componentIdentifier)).findFirst();
outputAttributesComponentModel.ifPresent(outputComponentModel -> outputDeclarer.describedAs(getDescription(outputComponentModel)));
MetadataType metadataType = getMetadataType(outputAttributesComponentModel, calculatedOutput);
outputDeclarer.ofType(metadataType);
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method declareErrorModels.
private void declareErrorModels(OperationDeclarer operationDeclarer, XmlDslModel xmlDslModel, String operationName, ComponentModel operationModel) {
Optional<ComponentModel> optionalParametersComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERRORS_IDENTIFIER)).findAny();
optionalParametersComponentModel.ifPresent(componentModel -> componentModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERROR_IDENTIFIER)).forEach(param -> {
final String namespace = xmlDslModel.getPrefix().toUpperCase();
final String typeName = param.getParameters().get(ERROR_TYPE_ATTRIBUTE);
if (StringUtils.isBlank(typeName)) {
throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> with an empty 'type' attribute", operationName));
}
if (typeName.contains(NAMESPACE_SEPARATOR)) {
throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> [%s] that contains a reserved character [%s]", operationName, typeName, NAMESPACE_SEPARATOR));
}
operationDeclarer.withErrorModel(ErrorModelBuilder.newError(typeName, namespace).withParent(ErrorModelBuilder.newError(ANY).build()).build());
}));
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class LazyMuleArtifactContext method createComponents.
private List<String> createComponents(Optional<Predicate> predicateOptional, Optional<Location> locationOptional, Optional<ComponentModelInitializerAdapter> parentComponentModelInitializerAdapter) {
checkState(predicateOptional.isPresent() != locationOptional.isPresent(), "predicate or location has to be passed");
List<String> alreadyCreatedApplicationComponents = new ArrayList<>();
alreadyCreatedApplicationComponents.addAll(trackingPostProcessor.getBeansTracked());
reverse(alreadyCreatedApplicationComponents);
trackingPostProcessor.startTracking();
Reference<List<String>> createdComponents = new Reference<>();
withContextClassLoader(muleContext.getExecutionClassLoader(), () -> {
applicationModel.executeOnEveryMuleComponentTree(componentModel -> componentModel.setEnabled(false));
ConfigurationDependencyResolver dependencyResolver = new ConfigurationDependencyResolver(this.applicationModel, componentBuildingDefinitionRegistry);
MinimalApplicationModelGenerator minimalApplicationModelGenerator = new MinimalApplicationModelGenerator(dependencyResolver);
Reference<ApplicationModel> minimalApplicationModel = new Reference<>();
predicateOptional.ifPresent(predicate -> minimalApplicationModel.set(minimalApplicationModelGenerator.getMinimalModel(predicate)));
locationOptional.ifPresent(location -> minimalApplicationModel.set(minimalApplicationModelGenerator.getMinimalModel(location)));
// First unregister any already initialized/started component
unregisterBeans(alreadyCreatedApplicationComponents);
objectProviders.clear();
if (parentComponentModelInitializerAdapter.isPresent()) {
List<String> missingComponentNames = dependencyResolver.getMissingDependencies().stream().filter(dependencyNode -> dependencyNode.isTopLevel()).map(dependencyNode -> dependencyNode.getComponentName()).collect(toList());
parentComponentModelInitializerAdapter.get().initializeComponents(componentModel -> {
if (componentModel.getNameAttribute() != null) {
return missingComponentNames.contains(componentModel.getNameAttribute());
}
return false;
});
} else {
dependencyResolver.getMissingDependencies().stream().forEach(globalElementName -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Ignoring dependency %s because it does not exists", globalElementName));
}
});
}
List<String> applicationComponents = createApplicationComponents((DefaultListableBeanFactory) this.getBeanFactory(), minimalApplicationModel.get(), false);
createdComponents.set(applicationComponents);
super.prepareObjectProviders();
// This is required to force the execution of postProcessAfterInitialization() for each created component
applicationComponents.forEach(component -> getRegistry().lookupByName(component).get());
});
trackingPostProcessor.stopTracking();
List<String> createdComponentNames = createdComponents.get();
trackingPostProcessor.intersection(createdComponentNames);
return createdComponentNames;
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class MuleArtifactContext method postProcessBeanFactory.
@Override
protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
Optional<ComponentModel> configurationOptional = applicationModel.findComponentDefinitionModel(CONFIGURATION_IDENTIFIER);
if (configurationOptional.isPresent()) {
return;
}
BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) beanFactory;
beanDefinitionRegistry.registerBeanDefinition(OBJECT_MULE_CONFIGURATION, genericBeanDefinition(MuleConfigurationConfigurator.class).getBeanDefinition());
}
Aggregations