Search in sources :

Example 1 with ComponentModel

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);
    }
}
Also used : TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel)

Example 2 with ComponentModel

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);
}
Also used : PRIMITIVE_TYPES(org.mule.metadata.catalog.api.PrimitiveTypesTypeLoader.PRIMITIVE_TYPES) BEHAVIOUR(org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR) ErrorModelBuilder(org.mule.runtime.api.meta.model.error.ErrorModelBuilder) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) Optional.of(java.util.Optional.of) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) StreamResult(javax.xml.transform.stream.StreamResult) Thread.currentThread(java.lang.Thread.currentThread) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) Collections.singletonList(java.util.Collections.singletonList) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) Document(org.w3c.dom.Document) Map(java.util.Map) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) IllegalParameterModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalParameterModelDefinitionException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) DisplayModel(org.mule.runtime.api.meta.model.display.DisplayModel) IOUtils(org.apache.commons.io.IOUtils) DeclarationOperation(org.mule.runtime.extension.api.loader.xml.declaration.DeclarationOperation) MacroExpansionModulesModel.getUsedNamespaces(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel.getUsedNamespaces) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) XmlModelUtils.createXmlLanguageModel(org.mule.runtime.extension.api.util.XmlModelUtils.createXmlLanguageModel) Category(org.mule.runtime.api.meta.Category) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) LayoutModel(org.mule.runtime.api.meta.model.display.LayoutModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) DirectedGraph(org.jgrapht.DirectedGraph) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) Optional.empty(java.util.Optional.empty) TransformerException(javax.xml.transform.TransformerException) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) TreeSet(java.util.TreeSet) Placement(org.mule.runtime.extension.api.annotation.param.display.Placement) String.join(java.lang.String.join) LayoutModel.builder(org.mule.runtime.api.meta.model.display.LayoutModel.builder) CycleDetector(org.jgrapht.alg.CycleDetector) DefaultEdge(org.jgrapht.graph.DefaultEdge) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ANY(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.ANY) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) IOException(java.io.IOException) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) NoReconnectionStrategyModelProperty(org.mule.runtime.extension.internal.property.NoReconnectionStrategyModelProperty) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) TransformerFactory(javax.xml.transform.TransformerFactory) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MacroExpansionModulesModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel) URL(java.net.URL) NamedObject(org.mule.runtime.api.meta.NamedObject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ByteArrayInputStream(java.io.ByteArrayInputStream) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) MacroExpansionModuleModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel) ComponentModelReader(org.mule.runtime.config.internal.dsl.model.ComponentModelReader) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) List(java.util.List) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) NoOpXmlErrorHandler(org.mule.runtime.config.internal.util.NoOpXmlErrorHandler) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashMap(java.util.HashMap) HashSet(java.util.HashSet) TypeResolverException(org.mule.metadata.catalog.api.TypeResolverException) TNS_PREFIX(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel.TNS_PREFIX) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) TypeResolver(org.mule.metadata.catalog.api.TypeResolver) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) Optional.ofNullable(java.util.Optional.ofNullable) ParameterizedDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclarer) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader) XMLNS_ATTRIBUTE(javax.xml.XMLConstants.XMLNS_ATTRIBUTE) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OutputDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OutputDeclarer) Collections(java.util.Collections) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MetadataType(org.mule.metadata.api.model.MetadataType)

Example 3 with ComponentModel

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());
    }));
}
Also used : PRIMITIVE_TYPES(org.mule.metadata.catalog.api.PrimitiveTypesTypeLoader.PRIMITIVE_TYPES) BEHAVIOUR(org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR) ErrorModelBuilder(org.mule.runtime.api.meta.model.error.ErrorModelBuilder) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) Optional.of(java.util.Optional.of) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) StreamResult(javax.xml.transform.stream.StreamResult) Thread.currentThread(java.lang.Thread.currentThread) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) Collections.singletonList(java.util.Collections.singletonList) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) Document(org.w3c.dom.Document) Map(java.util.Map) StringUtils.isEmpty(org.apache.commons.lang3.StringUtils.isEmpty) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) IllegalParameterModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalParameterModelDefinitionException) ConnectionProvider(org.mule.runtime.api.connection.ConnectionProvider) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) DisplayModel(org.mule.runtime.api.meta.model.display.DisplayModel) IOUtils(org.apache.commons.io.IOUtils) DeclarationOperation(org.mule.runtime.extension.api.loader.xml.declaration.DeclarationOperation) MacroExpansionModulesModel.getUsedNamespaces(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel.getUsedNamespaces) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) XmlModelUtils.createXmlLanguageModel(org.mule.runtime.extension.api.util.XmlModelUtils.createXmlLanguageModel) Category(org.mule.runtime.api.meta.Category) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) LayoutModel(org.mule.runtime.api.meta.model.display.LayoutModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) DirectedGraph(org.jgrapht.DirectedGraph) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) Optional.empty(java.util.Optional.empty) TransformerException(javax.xml.transform.TransformerException) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) TreeSet(java.util.TreeSet) Placement(org.mule.runtime.extension.api.annotation.param.display.Placement) String.join(java.lang.String.join) LayoutModel.builder(org.mule.runtime.api.meta.model.display.LayoutModel.builder) CycleDetector(org.jgrapht.alg.CycleDetector) DefaultEdge(org.jgrapht.graph.DefaultEdge) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ANY(org.mule.runtime.core.api.exception.Errors.ComponentIdentifiers.Handleable.ANY) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) IOException(java.io.IOException) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) NoReconnectionStrategyModelProperty(org.mule.runtime.extension.internal.property.NoReconnectionStrategyModelProperty) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) TransformerFactory(javax.xml.transform.TransformerFactory) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MacroExpansionModulesModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel) URL(java.net.URL) NamedObject(org.mule.runtime.api.meta.NamedObject) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ByteArrayInputStream(java.io.ByteArrayInputStream) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) MacroExpansionModuleModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel) ComponentModelReader(org.mule.runtime.config.internal.dsl.model.ComponentModelReader) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) ImmutableMap(com.google.common.collect.ImmutableMap) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Sets(com.google.common.collect.Sets) List(java.util.List) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) NoOpXmlErrorHandler(org.mule.runtime.config.internal.util.NoOpXmlErrorHandler) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashMap(java.util.HashMap) HashSet(java.util.HashSet) TypeResolverException(org.mule.metadata.catalog.api.TypeResolverException) TNS_PREFIX(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel.TNS_PREFIX) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) TypeResolver(org.mule.metadata.catalog.api.TypeResolver) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) Optional.ofNullable(java.util.Optional.ofNullable) ParameterizedDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclarer) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader) XMLNS_ATTRIBUTE(javax.xml.XMLConstants.XMLNS_ATTRIBUTE) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OutputDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OutputDeclarer) Collections(java.util.Collections) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel)

Example 4 with ComponentModel

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;
}
Also used : Optional.empty(java.util.Optional.empty) Optional.of(java.util.Optional.of) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) Location(org.mule.runtime.api.component.location.Location) NON_LAZY_VALUE_PROVIDER_SERVICE(org.mule.runtime.config.internal.LazyValueProviderService.NON_LAZY_VALUE_PROVIDER_SERVICE) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ArrayList(java.util.ArrayList) ValueProviderService(org.mule.runtime.api.value.ValueProviderService) MuleContext(org.mule.runtime.core.api.MuleContext) NON_LAZY_CONNECTIVITY_TESTING_SERVICE(org.mule.runtime.config.internal.LazyConnectivityTestingService.NON_LAZY_CONNECTIVITY_TESTING_SERVICE) MuleException(org.mule.runtime.api.exception.MuleException) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) Map(java.util.Map) Location.builderFromStringRepresentation(org.mule.runtime.api.component.location.Location.builderFromStringRepresentation) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) LegacyRegistryUtils.unregisterObject(org.mule.runtime.core.privileged.registry.LegacyRegistryUtils.unregisterObject) ConfigurationDependencyResolver(org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) MinimalApplicationModelGenerator(org.mule.runtime.config.internal.dsl.model.MinimalApplicationModelGenerator) MetadataService(org.mule.runtime.api.metadata.MetadataService) VALUE_PROVIDER_SERVICE_KEY(org.mule.runtime.api.value.ValueProviderService.VALUE_PROVIDER_SERVICE_KEY) Collections.reverse(java.util.Collections.reverse) Startable(org.mule.runtime.api.lifecycle.Startable) Logger(org.slf4j.Logger) DefaultConnectivityTestingService(org.mule.runtime.core.internal.connectivity.DefaultConnectivityTestingService) Predicate(java.util.function.Predicate) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) BeansException(org.springframework.beans.BeansException) MuleDeploymentProperties(org.mule.runtime.core.api.config.MuleDeploymentProperties) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) String.format(java.lang.String.format) ConnectivityTestingService(org.mule.runtime.api.connectivity.ConnectivityTestingService) MuleValueProviderService(org.mule.runtime.core.internal.value.MuleValueProviderService) Collectors.toList(java.util.stream.Collectors.toList) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) List(java.util.List) METADATA_SERVICE_KEY(org.mule.runtime.api.metadata.MetadataService.METADATA_SERVICE_KEY) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) Reference(org.mule.runtime.api.util.Reference) MuleMetadataService(org.mule.runtime.core.internal.metadata.MuleMetadataService) NON_LAZY_METADATA_SERVICE(org.mule.runtime.config.internal.LazyMetadataService.NON_LAZY_METADATA_SERVICE) Optional(java.util.Optional) CONNECTIVITY_TESTING_SERVICE_KEY(org.mule.runtime.api.connectivity.ConnectivityTestingService.CONNECTIVITY_TESTING_SERVICE_KEY) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Reference(org.mule.runtime.api.util.Reference) ArrayList(java.util.ArrayList) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ConfigurationDependencyResolver(org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver) MinimalApplicationModelGenerator(org.mule.runtime.config.internal.dsl.model.MinimalApplicationModelGenerator)

Example 5 with ComponentModel

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());
}
Also used : SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Aggregations

ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)41 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 SpringComponentModel (org.mule.runtime.config.internal.dsl.model.SpringComponentModel)13 Optional (java.util.Optional)11 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)11 Set (java.util.Set)9 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)9 String.format (java.lang.String.format)8 ArrayList (java.util.ArrayList)8 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)8 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)8 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)8 Collections.emptyMap (java.util.Collections.emptyMap)7 GlobalElementComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty)7 Optional.of (java.util.Optional.of)6 Collectors (java.util.stream.Collectors)6 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)6 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)6