Search in sources :

Example 1 with SimpleConfigAttribute

use of org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute in project mule by mulesoft.

the class MuleArtifactContext method recursivelyResolveConfigFiles.

private List<ConfigFile> recursivelyResolveConfigFiles(List<Pair<String, InputStream>> configFilesToResolve, List<ConfigFile> alreadyResolvedConfigFiles) {
    DefaultConfigurationPropertiesResolver propertyResolver = new DefaultConfigurationPropertiesResolver(empty(), new EnvironmentPropertiesConfigurationProvider());
    ImmutableList.Builder<ConfigFile> resolvedConfigFilesBuilder = ImmutableList.<ConfigFile>builder().addAll(alreadyResolvedConfigFiles);
    configFilesToResolve.stream().filter(fileNameInputStreamPair -> !alreadyResolvedConfigFiles.stream().anyMatch(configFile -> configFile.getFilename().equals(fileNameInputStreamPair.getFirst()))).forEach(fileNameInputStreamPair -> {
        Document document = xmlConfigurationDocumentLoader.loadDocument(muleContext.getExtensionManager() == null ? emptySet() : muleContext.getExtensionManager().getExtensions(), fileNameInputStreamPair.getFirst(), fileNameInputStreamPair.getSecond());
        ConfigLine mainConfigLine = xmlApplicationParser.parse(document.getDocumentElement()).get();
        ConfigFile configFile = new ConfigFile(fileNameInputStreamPair.getFirst(), asList(mainConfigLine));
        resolvedConfigFilesBuilder.add(configFile);
        try {
            fileNameInputStreamPair.getSecond().close();
        } catch (IOException e) {
            throw new MuleRuntimeException(e);
        }
    });
    ImmutableSet.Builder<String> importedFiles = ImmutableSet.builder();
    for (ConfigFile configFile : resolvedConfigFilesBuilder.build()) {
        List<ConfigLine> rootConfigLines = configFile.getConfigLines();
        ConfigLine muleRootElementConfigLine = rootConfigLines.get(0);
        importedFiles.addAll(muleRootElementConfigLine.getChildren().stream().filter(configLine -> configLine.getNamespace().equals(CORE_PREFIX) && configLine.getIdentifier().equals(IMPORT_ELEMENT)).map(configLine -> {
            SimpleConfigAttribute fileConfigAttribute = configLine.getConfigAttributes().get("file");
            if (fileConfigAttribute == null) {
                throw new RuntimeConfigurationException(createStaticMessage(format("<import> does not have a file attribute defined. At file '%s', at line %s", configFile.getFilename(), configLine.getLineNumber())));
            }
            return fileConfigAttribute.getValue();
        }).map(value -> (String) propertyResolver.resolveValue(value)).filter(fileName -> !alreadyResolvedConfigFiles.stream().anyMatch(solvedConfigFile -> solvedConfigFile.getFilename().equals(fileName))).collect(toList()));
    }
    Set<String> importedConfigurationFiles = importedFiles.build();
    if (importedConfigurationFiles.isEmpty()) {
        return resolvedConfigFilesBuilder.build();
    }
    List<Pair<String, InputStream>> newConfigFilesToResolved = importedConfigurationFiles.stream().map(importedFileName -> {
        InputStream resourceAsStream = muleContext.getExecutionClassLoader().getResourceAsStream(importedFileName);
        if (resourceAsStream == null) {
            throw new RuntimeConfigurationException(createStaticMessage(format("Could not find imported resource '%s'", importedFileName)));
        }
        return (Pair<String, InputStream>) new Pair(importedFileName, resourceAsStream);
    }).collect(toList());
    return recursivelyResolveConfigFiles(newConfigFilesToResolved, resolvedConfigFilesBuilder.build());
}
Also used : ClassLoaderResourceProvider(org.mule.runtime.config.internal.dsl.model.ClassLoaderResourceProvider) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) Optional.of(java.util.Optional.of) Thread.currentThread(java.lang.Thread.currentThread) ContextAnnotationAutowireCandidateResolver(org.springframework.context.annotation.ContextAnnotationAutowireCandidateResolver) ByteArrayResource(org.springframework.core.io.ByteArrayResource) MuleInjectorProcessor(org.mule.runtime.config.internal.processor.MuleInjectorProcessor) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) BeanDefinitionFactory(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory) Arrays.asList(java.util.Arrays.asList) Document(org.w3c.dom.Document) Map(java.util.Map) MULE_EE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_EE_DOMAIN_IDENTIFIER) PostRegistrationActionsPostProcessor(org.mule.runtime.config.internal.processor.PostRegistrationActionsPostProcessor) ComponentBuildingDefinitionUtils.registerComponentBuildingDefinitions(org.mule.runtime.config.internal.util.ComponentBuildingDefinitionUtils.registerComponentBuildingDefinitions) Resource(org.springframework.core.io.Resource) ConfigurableObjectProvider(org.mule.runtime.api.ioc.ConfigurableObjectProvider) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME(org.springframework.context.annotation.AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME) ComponentLocatorCreatePostProcessor(org.mule.runtime.config.internal.processor.ComponentLocatorCreatePostProcessor) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Optional.empty(java.util.Optional.empty) MulePropertyEditorRegistrar(org.mule.runtime.config.internal.editors.MulePropertyEditorRegistrar) BeanDefinitionBuilder.genericBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) TransformerResolver(org.mule.runtime.core.internal.registry.TransformerResolver) DefaultRegistry(org.mule.runtime.core.internal.registry.DefaultRegistry) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MULE_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_IDENTIFIER) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) Component(org.mule.runtime.api.component.Component) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) XmlConfigurationDocumentLoader.noValidationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.noValidationDocumentLoader) Registry(org.mule.runtime.api.artifact.Registry) ConfigurationDependencyResolver(org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver) ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME(org.springframework.context.annotation.AnnotationConfigUtils.REQUIRED_ANNOTATION_PROCESSOR_BEAN_NAME) LaxInstantiationStrategyWrapper(org.mule.runtime.config.internal.util.LaxInstantiationStrategyWrapper) ManagedMap(org.springframework.beans.factory.support.ManagedMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ComponentModelHelper.updateAnnotationValue(org.mule.runtime.config.internal.dsl.spring.ComponentModelHelper.updateAnnotationValue) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) IOException(java.io.IOException) BeansException(org.springframework.beans.BeansException) ArtifactConfig(org.mule.runtime.config.api.dsl.processor.ArtifactConfig) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) LifecycleUtils.disposeIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.disposeIfNeeded) SPRING_SINGLETON_OBJECT(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory.SPRING_SINGLETON_OBJECT) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ResourceProvider(org.mule.runtime.config.api.dsl.model.ResourceProvider) CglibSubclassingInstantiationStrategy(org.springframework.beans.factory.support.CglibSubclassingInstantiationStrategy) LoggerFactory(org.slf4j.LoggerFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ManagedList(org.springframework.beans.factory.support.ManagedList) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) OBJECT_REGISTRY(org.mule.runtime.core.api.config.MuleProperties.OBJECT_REGISTRY) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) Pair(org.mule.runtime.api.util.Pair) DOMAIN(org.mule.runtime.core.api.config.bootstrap.ArtifactType.DOMAIN) Collectors.toSet(java.util.stream.Collectors.toSet) XmlConfigurationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) MULE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_DOMAIN_IDENTIFIER) POLICY(org.mule.runtime.core.api.config.bootstrap.ArtifactType.POLICY) ImmutableSet(com.google.common.collect.ImmutableSet) IMPORT_ELEMENT(org.mule.runtime.config.api.dsl.CoreDslConstants.IMPORT_ELEMENT) ObjectProvider(org.mule.runtime.api.ioc.ObjectProvider) OBJECT_MULE_CONTEXT(org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONTEXT) String.format(java.lang.String.format) AbstractRefreshableConfigApplicationContext(org.springframework.context.support.AbstractRefreshableConfigApplicationContext) BeanPostProcessor(org.springframework.beans.factory.config.BeanPostProcessor) List(java.util.List) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) AutoIdUtils.uniqueValue(org.mule.runtime.config.internal.parsers.generic.AutoIdUtils.uniqueValue) Optional(java.util.Optional) OBJECT_MULE_CONFIGURATION(org.mule.runtime.core.api.config.MuleProperties.OBJECT_MULE_CONFIGURATION) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) Converter(org.mule.runtime.core.api.transformer.Converter) ComponentBuildingDefinitionRegistry(org.mule.runtime.config.api.dsl.model.ComponentBuildingDefinitionRegistry) UrlResource(org.springframework.core.io.UrlResource) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) MuleContext(org.mule.runtime.core.api.MuleContext) ImmutableList(com.google.common.collect.ImmutableList) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) XmlApplicationServiceRegistry(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry) DiscardedOptionalBeanPostProcessor(org.mule.runtime.config.internal.processor.DiscardedOptionalBeanPostProcessor) RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) IOUtils(org.mule.runtime.core.api.util.IOUtils) ROOT_CONTAINER_NAME_KEY(org.mule.runtime.api.component.AbstractComponent.ROOT_CONTAINER_NAME_KEY) Logger(org.slf4j.Logger) Collections.emptySet(java.util.Collections.emptySet) Optional.ofNullable(java.util.Optional.ofNullable) PropertyValue(org.springframework.beans.PropertyValue) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.schemaValidatingDocumentLoader) LifecycleStatePostProcessor(org.mule.runtime.config.internal.processor.LifecycleStatePostProcessor) Collectors.toList(java.util.stream.Collectors.toList) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) ConfigurationClassPostProcessor(org.springframework.context.annotation.ConfigurationClassPostProcessor) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) RequiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) CONFIGURATION_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.CONFIGURATION_IDENTIFIER) Comparator(java.util.Comparator) InputStream(java.io.InputStream) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) ImmutableList(com.google.common.collect.ImmutableList) InputStream(java.io.InputStream) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) IOException(java.io.IOException) Document(org.w3c.dom.Document) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) ImmutableSet(com.google.common.collect.ImmutableSet) RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) Pair(org.mule.runtime.api.util.Pair)

Example 2 with SimpleConfigAttribute

use of org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute in project mule by mulesoft.

the class DefaultXmlArtifactDeclarationLoader method declareElement.

private void declareElement(final ConfigLine configLine, final ArtifactDeclarer artifactDeclarer) {
    final ExtensionModel ownerExtension = getExtensionModel(configLine);
    final ElementDeclarer extensionElementsDeclarer = forExtension(ownerExtension.getName());
    final DslSyntaxResolver dsl = resolvers.get(getNamespace(configLine));
    Reference<Boolean> alreadyDeclared = new Reference<>(false);
    new ExtensionWalker() {

        @Override
        protected void onConstruct(HasConstructModels owner, ConstructModel model) {
            declareComponentModel(configLine, model, extensionElementsDeclarer::newConstruct).ifPresent(declarer -> {
                getDeclaredName(configLine).ifPresent(((ConstructElementDeclarer) declarer)::withRefName);
                artifactDeclarer.withGlobalElement((GlobalElementDeclaration) declarer.getDeclaration());
                alreadyDeclared.set(true);
                stop();
            });
        }

        @Override
        protected void onConfiguration(ConfigurationModel model) {
            final DslElementSyntax elementDsl = dsl.resolve(model);
            if (elementDsl.getElementName().equals(configLine.getIdentifier())) {
                ConfigurationElementDeclarer configurationDeclarer = extensionElementsDeclarer.newConfiguration(model.getName());
                getDeclaredName(configLine).ifPresent(configurationDeclarer::withRefName);
                Map<String, SimpleConfigAttribute> attributes = configLine.getConfigAttributes().values().stream().filter(a -> !a.getName().equals(NAME_ATTRIBUTE_NAME)).collect(toMap(SimpleConfigAttribute::getName, a -> a));
                List<ConfigLine> configComplexParameters = configLine.getChildren().stream().filter(config -> declareAsConnectionProvider(ownerExtension, model, configurationDeclarer, config, extensionElementsDeclarer)).collect(toList());
                declareParameterizedComponent(model, elementDsl, configurationDeclarer, attributes, configComplexParameters);
                artifactDeclarer.withGlobalElement(configurationDeclarer.getDeclaration());
                alreadyDeclared.set(true);
                stop();
            }
        }
    }.walk(ownerExtension);
    if (!alreadyDeclared.get()) {
        ownerExtension.getTypes().stream().filter(type -> dsl.resolve(type).map(typeDsl -> typeDsl.getElementName().equals(configLine.getIdentifier())).orElse(false)).findFirst().ifPresent(type -> {
            TopLevelParameterDeclarer topLevelParameter = extensionElementsDeclarer.newGlobalParameter(configLine.getIdentifier());
            getDeclaredName(configLine).ifPresent(topLevelParameter::withRefName);
            type.accept(getParameterDeclarerVisitor(configLine, dsl.resolve(type).get(), value -> topLevelParameter.withValue((ParameterObjectValue) value)));
            artifactDeclarer.withGlobalElement(topLevelParameter.getDeclaration());
        });
    }
}
Also used : Arrays(java.util.Arrays) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) TLS_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TLS_PARAMETER_NAME) MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) EXPIRATION_POLICY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.EXPIRATION_POLICY_ELEMENT_IDENTIFIER) REDELIVERY_POLICY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.REDELIVERY_POLICY_ELEMENT_IDENTIFIER) ArrayType(org.mule.metadata.api.model.ArrayType) Document(org.w3c.dom.Document) Map(java.util.Map) ParameterSimpleValue(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue) ParameterGroupElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer) MetadataTypeUtils.getLocalPart(org.mule.metadata.api.utils.MetadataTypeUtils.getLocalPart) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) RECONNECT_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.RECONNECT_ELEMENT_IDENTIFIER) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) ObjectType(org.mule.metadata.api.model.ObjectType) ElementDeclarer.newObjectValue(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newObjectValue) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) POOLING_PROFILE_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.POOLING_PROFILE_PARAMETER_NAME) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) NON_REPEATABLE_BYTE_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.NON_REPEATABLE_BYTE_STREAM_ALIAS) XmlArtifactDeclarationLoader(org.mule.runtime.config.internal.dsl.model.XmlArtifactDeclarationLoader) ExtensionModelUtils.isInfrastructure(org.mule.runtime.extension.api.util.ExtensionModelUtils.isInfrastructure) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) CONFIG_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.CONFIG_ATTRIBUTE_NAME) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_FILE_STORE_BYTES_STREAM_ALIAS) RouteElementDeclaration(org.mule.runtime.app.declaration.api.RouteElementDeclaration) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) ParameterSimpleValue.cdata(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue.cdata) ConfigurationElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConfigurationElementDeclarer) ParameterListValue(org.mule.runtime.app.declaration.api.fluent.ParameterListValue) ParameterSimpleValue.plain(org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue.plain) EXPIRATION_POLICY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.EXPIRATION_POLICY_PARAMETER_NAME) ConnectionElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConnectionElementDeclarer) ElementDeclarer.newListValue(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newListValue) XmlConfigurationDocumentLoader.noValidationDocumentLoader(org.mule.runtime.config.api.XmlConfigurationDocumentLoader.noValidationDocumentLoader) ConstructElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConstructElementDeclarer) GlobalElementDeclaration(org.mule.runtime.app.declaration.api.GlobalElementDeclaration) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ParameterValue(org.mule.runtime.app.declaration.api.ParameterValue) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) RECONNECTION_CONFIG_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.RECONNECTION_CONFIG_PARAMETER_NAME) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) STREAMING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.STREAMING_STRATEGY_PARAMETER_NAME) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) Reference(org.mule.runtime.api.util.Reference) ParameterizedBuilder(org.mule.runtime.app.declaration.api.fluent.ParameterizedBuilder) ComponentElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer) ElementDeclarer.forExtension(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.forExtension) ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) TLS_REVOCATION_CHECK_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.TLS_REVOCATION_CHECK_ELEMENT_IDENTIFIER) RECONNECT_FOREVER_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.RECONNECT_FOREVER_ELEMENT_IDENTIFIER) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) HasNestedComponentDeclarer(org.mule.runtime.app.declaration.api.fluent.HasNestedComponentDeclarer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ComposableModel(org.mule.runtime.api.meta.model.ComposableModel) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) Collectors.toMap(java.util.stream.Collectors.toMap) XmlApplicationParser(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser) ArtifactDeclarer(org.mule.runtime.app.declaration.api.fluent.ArtifactDeclarer) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS(org.mule.runtime.extension.api.declaration.type.StreamingStrategyTypeBuilder.REPEATABLE_IN_MEMORY_BYTES_STREAM_ALIAS) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) TLS_CONTEXT_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.TLS_CONTEXT_ELEMENT_IDENTIFIER) REDELIVERY_POLICY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.REDELIVERY_POLICY_PARAMETER_NAME) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) CONNECTION(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.CONNECTION) RECONNECTION_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.RECONNECTION_STRATEGY_PARAMETER_NAME) NAME_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.NAME_ATTRIBUTE_NAME) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) Optional(java.util.Optional) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) POOLING_PROFILE_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.POOLING_PROFILE_ELEMENT_IDENTIFIER) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) RouteElementDeclarer(org.mule.runtime.app.declaration.api.fluent.RouteElementDeclarer) HashMap(java.util.HashMap) Function(java.util.function.Function) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) XmlApplicationServiceRegistry(org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry) ParameterObjectValue(org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) ElementDeclarer.newParameterGroup(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer.newParameterGroup) ParameterizedElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ParameterizedElementDeclarer) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) TopLevelParameterDeclarer(org.mule.runtime.app.declaration.api.fluent.TopLevelParameterDeclarer) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) IS_CDATA(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler.IS_CDATA) ComponentElementDeclaration(org.mule.runtime.app.declaration.api.ComponentElementDeclaration) ExtensibleTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.ExtensibleTypeAnnotation) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) InputStream(java.io.InputStream) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ConfigurationElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConfigurationElementDeclarer) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) Reference(org.mule.runtime.api.util.Reference) TopLevelParameterDeclarer(org.mule.runtime.app.declaration.api.fluent.TopLevelParameterDeclarer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) ConstructElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConstructElementDeclarer) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) ParameterGroupElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ParameterGroupElementDeclarer) ElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ElementDeclarer) ConfigurationElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConfigurationElementDeclarer) ConnectionElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConnectionElementDeclarer) ConstructElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ConstructElementDeclarer) ComponentElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ComponentElementDeclarer) RouteElementDeclarer(org.mule.runtime.app.declaration.api.fluent.RouteElementDeclarer) ParameterizedElementDeclarer(org.mule.runtime.app.declaration.api.fluent.ParameterizedElementDeclarer) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) HasConstructModels(org.mule.runtime.api.meta.model.construct.HasConstructModels) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GlobalElementDeclaration(org.mule.runtime.app.declaration.api.GlobalElementDeclaration) Map(java.util.Map) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) Collectors.toMap(java.util.stream.Collectors.toMap) HashMap(java.util.HashMap)

Example 3 with SimpleConfigAttribute

use of org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute in project mule by mulesoft.

the class DefaultXmlArtifactDeclarationLoader method createMapValue.

private void createMapValue(ParameterObjectValue.Builder objectValue, ConfigLine config) {
    config.getChildren().stream().map(ConfigLine::getConfigAttributes).forEach(entry -> {
        SimpleConfigAttribute entryKey = entry.get(KEY_ATTRIBUTE_NAME);
        SimpleConfigAttribute entryValue = entry.get(VALUE_ATTRIBUTE_NAME);
        if (entryKey != null && entryValue != null) {
            objectValue.withParameter(entryKey.getValue(), entryValue.getValue());
        }
    });
}
Also used : SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute)

Example 4 with SimpleConfigAttribute

use of org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute in project mule by mulesoft.

the class ComponentModelReader method extractComponentDefinitionModel.

public ComponentModel extractComponentDefinitionModel(ConfigLine configLine, String configFileName) {
    String namespace = configLine.getNamespace() == null ? CORE_PREFIX : configLine.getNamespace();
    ComponentModel.Builder builder = new ComponentModel.Builder().setIdentifier(builder().namespace(namespace).name(configLine.getIdentifier()).build()).setTextContent(resolveValueIfIsPlaceHolder(configLine.getTextContent())).setConfigFileName(configFileName).setLineNumber(configLine.getLineNumber());
    to(builder).addNode(from(configLine).getNode());
    for (SimpleConfigAttribute simpleConfigAttribute : configLine.getConfigAttributes().values()) {
        builder.addParameter(simpleConfigAttribute.getName(), resolveValueIfIsPlaceHolder(simpleConfigAttribute.getValue()), simpleConfigAttribute.isValueFromSchema());
    }
    List<ComponentModel> componentModels = configLine.getChildren().stream().map(childConfigLine -> extractComponentDefinitionModel(childConfigLine, configFileName)).collect(Collectors.toList());
    componentModels.stream().forEach(componentDefinitionModel -> builder.addChildComponentModel(componentDefinitionModel));
    ConfigLine parent = configLine.getParent();
    if (parent != null && isConfigurationTopComponent(parent)) {
        builder.markAsRootComponent();
    }
    ComponentModel componentModel = builder.build();
    for (ComponentModel innerComponentModel : componentModel.getInnerComponents()) {
        innerComponentModel.setParent(componentModel);
    }
    return componentModel;
}
Also used : Properties(java.util.Properties) XmlCustomAttributeHandler.from(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler.from) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) MULE_ROOT_ELEMENT(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_ROOT_ELEMENT) MULE_DOMAIN_ROOT_ELEMENT(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_DOMAIN_ROOT_ELEMENT) Collectors(java.util.stream.Collectors) ConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesResolver) XmlCustomAttributeHandler.to(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler.to) POLICY_ROOT_ELEMENT(org.mule.runtime.config.internal.model.ApplicationModel.POLICY_ROOT_ELEMENT) List(java.util.List) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) SimpleConfigAttribute(org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine)

Aggregations

SimpleConfigAttribute (org.mule.runtime.config.api.dsl.processor.SimpleConfigAttribute)4 List (java.util.List)3 ConfigLine (org.mule.runtime.config.api.dsl.processor.ConfigLine)3 CORE_PREFIX (org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX)3 InputStream (java.io.InputStream)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 Collectors.toList (java.util.stream.Collectors.toList)2 DslResolvingContext (org.mule.runtime.api.dsl.DslResolvingContext)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 ArtifactDeclaration (org.mule.runtime.app.declaration.api.ArtifactDeclaration)2 XmlConfigurationDocumentLoader.noValidationDocumentLoader (org.mule.runtime.config.api.XmlConfigurationDocumentLoader.noValidationDocumentLoader)2 XmlApplicationParser (org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationParser)2 XmlApplicationServiceRegistry (org.mule.runtime.config.api.dsl.processor.xml.XmlApplicationServiceRegistry)2 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)2 SpiServiceRegistry (org.mule.runtime.core.api.registry.SpiServiceRegistry)2 Document (org.w3c.dom.Document)2