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)));
}
}
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);
}
}
}
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());
}
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;
}
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;
}
Aggregations