Search in sources :

Example 1 with CORE_PREFIX

use of org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX in project mule by mulesoft.

the class PollingSourceDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ClassTypeLoader loader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
    ExtensionDeclarer extensionDeclarer = extensionLoadingContext.getExtensionDeclarer();
    Reference<Boolean> thereArePollingSources = new Reference<>(false);
    new IdempotentDeclarationWalker() {

        @Override
        protected void onSource(SourceDeclaration source) {
            extractType(source).ifPresent(type -> {
                if (type.isAssignableTo(PollingSource.class)) {
                    source.setRunsOnPrimaryNodeOnly(true);
                    ParameterDeclaration parameter = new ParameterDeclaration(SCHEDULING_STRATEGY_PARAMETER_NAME);
                    parameter.setDescription(SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION);
                    parameter.setRequired(true);
                    parameter.setType(loader.load(Scheduler.class), false);
                    parameter.setExpressionSupport(NOT_SUPPORTED);
                    parameter.addModelProperty(new InfrastructureParameterModelProperty(10));
                    parameter.addModelProperty(new QNameModelProperty(new QName(CORE_NAMESPACE, SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER, CORE_PREFIX)));
                    parameter.setDslConfiguration(ParameterDslConfiguration.builder().allowsInlineDefinition(true).allowsReferences(false).allowTopLevelDefinition(false).build());
                    thereArePollingSources.set(true);
                    source.getParameterGroup(DEFAULT_GROUP_NAME).addParameter(parameter);
                }
            });
        }
    }.walk(extensionDeclarer.getDeclaration());
    if (thereArePollingSources.get() && !isSchedulerAlreadyImported(extensionDeclarer.getDeclaration())) {
        ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
        extensionDeclarer.withImportedType(new ImportedTypeModel((ObjectType) typeLoader.load(Scheduler.class)));
    }
}
Also used : InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) CORE_NAMESPACE(org.mule.runtime.internal.dsl.DslConstants.CORE_NAMESPACE) DEFAULT_GROUP_NAME(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel.DEFAULT_GROUP_NAME) MetadataTypeUtils.getTypeId(org.mule.metadata.api.utils.MetadataTypeUtils.getTypeId) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) ParameterDslConfiguration(org.mule.runtime.api.meta.model.ParameterDslConfiguration) SCHEDULING_STRATEGY_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.SCHEDULING_STRATEGY_PARAMETER_NAME) ObjectType(org.mule.metadata.api.model.ObjectType) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) STRUCTURE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.STRUCTURE) SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION(org.mule.runtime.extension.api.ExtensionConstants.SCHEDULING_STRATEGY_PARAMETER_DESCRIPTION) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) Reference(org.mule.runtime.api.util.Reference) MetadataType(org.mule.metadata.api.model.MetadataType) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) QName(javax.xml.namespace.QName) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER(org.mule.runtime.internal.dsl.DslConstants.SCHEDULING_STRATEGY_ELEMENT_IDENTIFIER) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) Reference(org.mule.runtime.api.util.Reference) QName(javax.xml.namespace.QName) Scheduler(org.mule.runtime.core.api.source.scheduler.Scheduler) PollingSource(org.mule.runtime.extension.api.runtime.source.PollingSource) InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) ObjectType(org.mule.metadata.api.model.ObjectType) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ParameterDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Example 2 with CORE_PREFIX

use of org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX in project mule by mulesoft.

the class ApplicationModel method convertArtifactDeclarationToComponentModel.

private void convertArtifactDeclarationToComponentModel(Set<ExtensionModel> extensionModels, ArtifactDeclaration artifactDeclaration) {
    if (artifactDeclaration != null && !extensionModels.isEmpty()) {
        ExtensionModel muleModel = MuleExtensionModelProvider.getExtensionModel();
        if (!extensionModels.contains(muleModel)) {
            extensionModels = new HashSet<>(extensionModels);
            extensionModels.add(muleModel);
        }
        DslElementModelFactory elementFactory = DslElementModelFactory.getDefault(DslResolvingContext.getDefault(extensionModels));
        ComponentModel rootComponent = new ComponentModel.Builder().setIdentifier(ComponentIdentifier.builder().namespace(CORE_PREFIX).name(CORE_PREFIX).build()).build();
        AtomicBoolean atLeastOneComponentAdded = new AtomicBoolean(false);
        artifactDeclaration.getGlobalElements().stream().map(e -> elementFactory.create((ElementDeclaration) e)).filter(Optional::isPresent).map(e -> e.get().getConfiguration()).forEach(config -> config.ifPresent(c -> {
            atLeastOneComponentAdded.set(true);
            ComponentModel componentModel = convertComponentConfiguration(c, true);
            componentModel.setParent(rootComponent);
            rootComponent.getInnerComponents().add(componentModel);
        }));
        if (atLeastOneComponentAdded.get()) {
            this.muleComponentModels.add(rootComponent);
        }
    }
}
Also used : ResourceProvider(org.mule.runtime.config.api.dsl.model.ResourceProvider) MacroExpansionModulesModel(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModulesModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) MULE_ROOT_ELEMENT(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_ROOT_ELEMENT) Optional.of(java.util.Optional.of) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ConfigurationProperty(org.mule.runtime.config.api.dsl.model.properties.ConfigurationProperty) Collections.singletonList(java.util.Collections.singletonList) ClassUtils(org.apache.commons.lang3.ClassUtils) DefaultConfigurationParameters(org.mule.runtime.config.internal.dsl.model.DefaultConfigurationParameters) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) MULE_EE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_EE_DOMAIN_IDENTIFIER) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) DslElementModelFactory(org.mule.runtime.config.api.dsl.model.DslElementModelFactory) ERROR_HANDLER_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.ERROR_HANDLER_IDENTIFIER) ComponentModelReader(org.mule.runtime.config.internal.dsl.model.ComponentModelReader) CompositeConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.CompositeConfigurationPropertiesProvider) PropertiesResolverConfigurationProperties(org.mule.runtime.config.internal.dsl.model.config.PropertiesResolverConfigurationProperties) EnvironmentPropertiesConfigurationProvider(org.mule.runtime.config.internal.dsl.model.config.EnvironmentPropertiesConfigurationProvider) MULE_DOMAIN_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_DOMAIN_IDENTIFIER) DEFAULT_EXPRESSION_PREFIX(org.mule.runtime.core.api.el.ExpressionManager.DEFAULT_EXPRESSION_PREFIX) ImmutableSet(com.google.common.collect.ImmutableSet) ComponentModelHelper.resolveComponentType(org.mule.runtime.config.internal.dsl.spring.ComponentModelHelper.resolveComponentType) MapConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.MapConfigurationPropertiesProvider) TypedComponentIdentifier(org.mule.runtime.api.component.TypedComponentIdentifier) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) UNKNOWN(org.mule.runtime.api.component.TypedComponentIdentifier.ComponentType.UNKNOWN) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ServiceLoader(java.util.ServiceLoader) SOURCE_TYPE(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory.SOURCE_TYPE) NameValidationUtil.verifyStringDoesNotContainsReservedCharacters(org.mule.runtime.internal.util.NameValidationUtil.verifyStringDoesNotContainsReservedCharacters) String.format(java.lang.String.format) FileConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.FileConfigurationPropertiesProvider) ERROR_HANDLER(org.mule.runtime.config.api.dsl.CoreDslConstants.ERROR_HANDLER) I18nMessageFactory(org.mule.runtime.api.i18n.I18nMessageFactory) XmlCustomAttributeHandler(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) List(java.util.List) ElementDeclaration(org.mule.runtime.app.declaration.api.ElementDeclaration) GlobalPropertyConfigurationPropertiesProvider(org.mule.runtime.config.internal.dsl.model.config.GlobalPropertyConfigurationPropertiesProvider) Optional(java.util.Optional) QName(javax.xml.namespace.QName) MuleExtensionModelProvider(org.mule.runtime.core.api.extension.MuleExtensionModelProvider) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) Optional.empty(java.util.Optional.empty) ComponentBuildingDefinitionRegistry(org.mule.runtime.config.api.dsl.model.ComponentBuildingDefinitionRegistry) DefaultComponentLocation(org.mule.runtime.dsl.api.component.config.DefaultComponentLocation) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) LifecycleUtils.initialiseIfNeeded(org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) ComponentConfiguration(org.mule.runtime.dsl.api.component.config.ComponentConfiguration) ComponentLocationVisitor(org.mule.runtime.config.internal.dsl.model.ComponentLocationVisitor) NameUtils.pluralize(org.mule.runtime.extension.api.util.NameUtils.pluralize) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) MULE_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.MULE_IDENTIFIER) ConfigurationPropertiesProvider(org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProvider) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) Component(org.mule.runtime.api.component.Component) Node(org.w3c.dom.Node) BiConsumer(java.util.function.BiConsumer) FLOW_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.FLOW_IDENTIFIER) RuntimeConfigurationException(org.mule.runtime.config.internal.dsl.model.config.RuntimeConfigurationException) ConfigLine(org.mule.runtime.config.api.dsl.processor.ConfigLine) ConfigFile(org.mule.runtime.config.api.dsl.processor.ConfigFile) DefaultConfigurationProperty(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationProperty) LinkedList(java.util.LinkedList) Collections.emptyMap(java.util.Collections.emptyMap) Collections.emptySet(java.util.Collections.emptySet) ConfigurationException(org.mule.runtime.core.api.config.ConfigurationException) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) NameUtils.hyphenize(org.mule.runtime.extension.api.util.NameUtils.hyphenize) ConfigurationParameters(org.mule.runtime.config.api.dsl.model.ConfigurationParameters) ExtensionModelHelper(org.mule.runtime.config.internal.dsl.model.ExtensionModelHelper) ArtifactConfig(org.mule.runtime.config.api.dsl.processor.ArtifactConfig) DefaultConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.DefaultConfigurationPropertiesResolver) Joiner.on(com.google.common.base.Joiner.on) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ConfigurationPropertiesResolver(org.mule.runtime.config.internal.dsl.model.config.ConfigurationPropertiesResolver) FLOW_REF_IDENTIFIER(org.mule.runtime.config.api.dsl.CoreDslConstants.FLOW_REF_IDENTIFIER) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) ConfigurationPropertiesProviderFactory(org.mule.runtime.config.api.dsl.model.properties.ConfigurationPropertiesProviderFactory) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) CollectionUtils.disjunction(org.apache.commons.collections.CollectionUtils.disjunction) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ANY_IDENTIFIER(org.mule.runtime.core.api.exception.Errors.Identifiers.ANY_IDENTIFIER) DslElementModelFactory(org.mule.runtime.config.api.dsl.model.DslElementModelFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Optional(java.util.Optional) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel)

Example 3 with CORE_PREFIX

use of org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX 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 4 with CORE_PREFIX

use of org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX in project mule by mulesoft.

the class MacroExpansionModuleModel method createModuleOperationChain.

/**
 * Takes a one liner call to any given message processor, expand it to creating a "module-operation-chain" scope which has the
 * set of properties, the set of parameters and the list of message processors to execute.
 *
 * @param operationRefModel message processor that will be replaced by a scope element named "module-operation-chain".
 * @param operationModel operation that provides both the <parameter/>s and content of the <body/>
 * @param moduleGlobalElementsNames collection with the global components names (such as <http:config name="a"../>, <file:config
 *        name="b"../>, <file:matcher name="c"../> and so on) that are contained within the <module/> that will be macro
 *        expanded
 * @param configRefParentTnsName parent reference to the global element if exists (it might not be global elements in the
 *        current module). Useful when replacing {@link #TNS_PREFIX} operations, as the references to the global elements will
 *        be those of the rootest element of the operations consumed by the app.
 * @param containerName name of the container that contains the operation to be macro expanded. Not null nor empty.
 * @return a new component model that represents the old placeholder but expanded with the content of the <body/>
 */
private ComponentModel createModuleOperationChain(ComponentModel operationRefModel, OperationModel operationModel, Set<String> moduleGlobalElementsNames, Optional<String> configRefParentTnsName, String containerName) {
    final OperationComponentModelModelProperty operationComponentModelModelProperty = operationModel.getModelProperty(OperationComponentModelModelProperty.class).get();
    final ComponentModel operationModuleComponentModel = operationComponentModelModelProperty.getBodyComponentModel();
    List<ComponentModel> bodyProcessors = operationModuleComponentModel.getInnerComponents();
    Optional<String> configRefName = referencesOperationsWithinModule(operationRefModel) ? configRefParentTnsName : Optional.ofNullable(operationRefModel.getParameters().get(MODULE_OPERATION_CONFIG_REF));
    ComponentModel.Builder processorChainBuilder = new ComponentModel.Builder();
    processorChainBuilder.setIdentifier(builder().namespace(CORE_PREFIX).name("module-operation-chain").build());
    processorChainBuilder.addParameter("moduleName", extensionModel.getXmlDslModel().getPrefix(), false);
    processorChainBuilder.addParameter("moduleOperation", operationModel.getName(), false);
    Map<String, String> propertiesMap = extractProperties(configRefName);
    Map<String, String> parametersMap = extractParameters(operationRefModel, operationModel.getAllParameterModels());
    ComponentModel propertiesComponentModel = getParameterChild(propertiesMap, "module-operation-properties", "module-operation-property-entry");
    ComponentModel parametersComponentModel = getParameterChild(parametersMap, "module-operation-parameters", "module-operation-parameter-entry");
    processorChainBuilder.addChildComponentModel(propertiesComponentModel);
    processorChainBuilder.addChildComponentModel(parametersComponentModel);
    for (ComponentModel bodyProcessor : bodyProcessors) {
        ComponentModel childMPcomponentModel = lookForTNSOperation(bodyProcessor).map(tnsOperation -> createModuleOperationChain(bodyProcessor, tnsOperation, moduleGlobalElementsNames, configRefName, containerName)).orElseGet(() -> copyOperationComponentModel(bodyProcessor, configRefName, moduleGlobalElementsNames, getLiteralParameters(propertiesMap, parametersMap), containerName));
        processorChainBuilder.addChildComponentModel(childMPcomponentModel);
    }
    copyErrorMappings(operationRefModel, processorChainBuilder);
    for (Map.Entry<String, Object> customAttributeEntry : operationRefModel.getCustomAttributes().entrySet()) {
        processorChainBuilder.addCustomAttribute(customAttributeEntry.getKey(), customAttributeEntry.getValue());
    }
    processorChainBuilder.addCustomAttribute(ROOT_MACRO_EXPANDED_FLOW_CONTAINER_NAME, containerName);
    ComponentModel processorChainModel = processorChainBuilder.build();
    for (ComponentModel processorChainModelChild : processorChainModel.getInnerComponents()) {
        processorChainModelChild.setParent(processorChainModel);
    }
    operationRefModel.getConfigFileName().ifPresent(processorChainBuilder::setConfigFileName);
    operationRefModel.getLineNumber().ifPresent(processorChainBuilder::setLineNumber);
    processorChainBuilder.addCustomAttribute(ORIGINAL_IDENTIFIER, operationRefModel.getIdentifier());
    return processorChainModel;
}
Also used : IntStream(java.util.stream.IntStream) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ParameterRole(org.mule.runtime.api.meta.model.parameter.ParameterRole) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) HashMap(java.util.HashMap) Processor(org.mule.runtime.core.api.processor.Processor) ArrayList(java.util.ArrayList) CommonBeanDefinitionCreator(org.mule.runtime.config.internal.dsl.spring.CommonBeanDefinitionCreator) MODULE_OPERATION_CHAIN(org.mule.runtime.config.internal.model.ApplicationModel.MODULE_OPERATION_CHAIN) KEY_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.KEY_ATTRIBUTE_NAME) Map(java.util.Map) NAME_ATTRIBUTE(org.mule.runtime.config.internal.model.ApplicationModel.NAME_ATTRIBUTE) Collectors.toSet(java.util.stream.Collectors.toSet) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) Collections.emptyMap(java.util.Collections.emptyMap) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MODULE_CONNECTION_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONNECTION_GLOBAL_ELEMENT_NAME) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) Set(java.util.Set) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) GlobalElementComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty) VARS(org.mule.runtime.api.el.BindingContextUtils.VARS) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) TestConnectionGlobalElementModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.TestConnectionGlobalElementModelProperty) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) ComponentIdentifier.builder(org.mule.runtime.api.component.ComponentIdentifier.builder) MODULE_CONFIG_GLOBAL_ELEMENT_NAME(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder.MODULE_CONFIG_GLOBAL_ELEMENT_NAME) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) OperationComponentModelModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 5 with CORE_PREFIX

use of org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX 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

CORE_PREFIX (org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX)5 List (java.util.List)4 String.format (java.lang.String.format)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)3 ComponentIdentifier.builder (org.mule.runtime.api.component.ComponentIdentifier.builder)3 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)3 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 ConfigLine (org.mule.runtime.config.api.dsl.processor.ConfigLine)3 ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Arrays.asList (java.util.Arrays.asList)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.emptySet (java.util.Collections.emptySet)2 HashMap (java.util.HashMap)2 Optional.empty (java.util.Optional.empty)2