use of org.mule.runtime.config.api.dsl.processor.ConfigLine in project mule by mulesoft.
the class XmlApplicationParser method configLineFromElement.
private Optional<ConfigLine> configLineFromElement(Node node, ConfigLineProvider parentProvider) {
if (!isValidType(node)) {
return Optional.empty();
}
String identifier = parseIdentifier(node);
String namespace = parseNamespace(node);
ConfigLine.Builder builder = new ConfigLine.Builder().setIdentifier(identifier).setNamespace(namespace).setNode(node).setParent(parentProvider);
XmlMetadataAnnotations userData = (XmlMetadataAnnotations) node.getUserData(XmlMetadataAnnotations.METADATA_ANNOTATIONS_KEY);
int lineNumber = userData.getLineNumber();
builder.setLineNumber(lineNumber);
to(builder).addNode(node);
Element element = (Element) node;
NamedNodeMap attributes = element.getAttributes();
if (element.hasAttributes()) {
for (int i = 0; i < attributes.getLength(); i++) {
Node attribute = attributes.item(i);
Attr attributeNode = element.getAttributeNode(attribute.getNodeName());
boolean isFromXsd = !attributeNode.getSpecified();
builder.addConfigAttribute(attribute.getNodeName(), attribute.getNodeValue(), isFromXsd);
}
}
if (node.hasChildNodes()) {
NodeList children = node.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (isTextContent(child)) {
builder.setTextContent(child.getNodeValue());
if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
builder.addCustomAttribute(IS_CDATA, Boolean.TRUE);
break;
}
} else {
configLineFromElement(child, builder::build).ifPresent(builder::addChild);
}
}
}
return Optional.of(builder.build());
}
use of org.mule.runtime.config.api.dsl.processor.ConfigLine in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method createWrappedObject.
private void createWrappedObject(ObjectType objectType, ParameterObjectValue.Builder objectValue, ConfigLine config) {
ConfigLine wrappedConfig = config.getChildren().get(0);
DslSyntaxResolver wrappedElementResolver = resolvers.get(getNamespace(wrappedConfig));
Set<ObjectType> subTypes = context.getTypeCatalog().getSubTypes(objectType);
if (!subTypes.isEmpty()) {
subTypes.stream().filter(subType -> wrappedElementResolver.resolve(subType).map(dsl -> dsl.getElementName().equals(wrappedConfig.getIdentifier())).orElse(false)).findFirst().ifPresent(subType -> createObjectValueFromType(subType, objectValue, wrappedConfig, wrappedElementResolver.resolve(subType).get()));
} else if (objectType.getAnnotation(ExtensibleTypeAnnotation.class).isPresent()) {
createObjectValueFromType(objectType, objectValue, wrappedConfig, wrappedElementResolver.resolve(objectType).get());
}
}
use of org.mule.runtime.config.api.dsl.processor.ConfigLine in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareChildParameters.
private void declareChildParameters(ParameterizedModel model, DslElementSyntax modelDsl, List<ConfigLine> children, ParameterizedElementDeclarer declarer) {
model.getParameterGroupModels().forEach(group -> {
if (group.isShowInDsl()) {
modelDsl.getChild(group.getName()).ifPresent(groupDsl -> children.stream().filter(c -> c.getIdentifier().equals(groupDsl.getElementName())).findFirst().ifPresent(groupConfig -> declareInlineGroup(group, groupDsl, groupConfig, declarer)));
} else {
ParameterGroupElementDeclarer groupDeclarer = newParameterGroup(group.getName());
group.getParameterModels().forEach(param -> modelDsl.getChild(param.getName()).ifPresent(paramDsl -> {
if (isInfrastructure(param)) {
handleInfrastructure(param, children, declarer);
} else {
children.stream().filter(c -> c.getIdentifier().equals(paramDsl.getElementName())).findFirst().ifPresent(paramConfig -> param.getType().accept(getParameterDeclarerVisitor(paramConfig, paramDsl, value -> groupDeclarer.withParameter(param.getName(), value))));
}
}));
if (!groupDeclarer.getDeclaration().getParameters().isEmpty()) {
declarer.withParameterGroup(groupDeclarer.getDeclaration());
}
}
});
}
use of org.mule.runtime.config.api.dsl.processor.ConfigLine in project mule by mulesoft.
the class ApplicationModel method resolveConfigurationParameters.
private ConfigurationParameters resolveConfigurationParameters(DefaultConfigurationParameters.Builder configurationParametersBuilder, ConfigLine componentConfigLine, ConfigurationPropertiesResolver localResolver) {
componentConfigLine.getConfigAttributes().forEach((key, value) -> configurationParametersBuilder.withSimpleParameter(key, localResolver.resolveValue(value.getValue())));
for (ConfigLine childConfigLine : componentConfigLine.getChildren()) {
DefaultConfigurationParameters.Builder childParametersBuilder = DefaultConfigurationParameters.builder();
configurationParametersBuilder.withComplexParameter(ComponentIdentifier.builder().name(childConfigLine.getIdentifier()).namespace(childConfigLine.getNamespace()).build(), resolveConfigurationParameters(childParametersBuilder, childConfigLine, localResolver));
}
return configurationParametersBuilder.build();
}
use of org.mule.runtime.config.api.dsl.processor.ConfigLine in project mule by mulesoft.
the class ApplicationModel method getConfigurationPropertiesProvidersFromComponents.
private List<ConfigurationPropertiesProvider> getConfigurationPropertiesProvidersFromComponents(ArtifactConfig artifactConfig, ConfigurationPropertiesResolver localResolver) {
Map<ComponentIdentifier, ConfigurationPropertiesProviderFactory> providerFactoriesMap = new HashMap<>();
ServiceLoader<ConfigurationPropertiesProviderFactory> providerFactories = java.util.ServiceLoader.load(ConfigurationPropertiesProviderFactory.class);
providerFactories.forEach(service -> {
ComponentIdentifier componentIdentifier = service.getSupportedComponentIdentifier();
if (providerFactoriesMap.containsKey(componentIdentifier)) {
throw new MuleRuntimeException(createStaticMessage("Multiple configuration providers for component: " + componentIdentifier));
}
providerFactoriesMap.put(componentIdentifier, service);
});
List<ConfigurationPropertiesProvider> configConfigurationPropertiesProviders = new ArrayList<>();
artifactConfig.getConfigFiles().stream().forEach(configFile -> configFile.getConfigLines().stream().forEach(configLine -> {
for (ConfigLine componentConfigLine : configLine.getChildren()) {
if (componentConfigLine.getNamespace() == null) {
continue;
}
ComponentIdentifier componentIdentifier = ComponentIdentifier.builder().namespace(componentConfigLine.getNamespace()).name(componentConfigLine.getIdentifier()).build();
if (!providerFactoriesMap.containsKey(componentIdentifier)) {
continue;
}
DefaultConfigurationParameters.Builder configurationParametersBuilder = DefaultConfigurationParameters.builder();
ConfigurationParameters configurationParameters = resolveConfigurationParameters(configurationParametersBuilder, componentConfigLine, localResolver);
ConfigurationPropertiesProvider provider = providerFactoriesMap.get(componentIdentifier).createProvider(configurationParameters, externalResourceProvider);
if (provider instanceof Component) {
Component providerComponent = (Component) provider;
TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(UNKNOWN).identifier(componentIdentifier).build();
DefaultComponentLocation.DefaultLocationPart locationPart = new DefaultComponentLocation.DefaultLocationPart(componentIdentifier.getName(), of(typedComponentIdentifier), of(configFile.getFilename()), of(configLine.getLineNumber()));
providerComponent.setAnnotations(ImmutableMap.<QName, Object>builder().put(AbstractComponent.LOCATION_KEY, new DefaultComponentLocation(of(componentIdentifier.getName()), singletonList(locationPart))).build());
}
configConfigurationPropertiesProviders.add(provider);
try {
initialiseIfNeeded(provider);
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
}
}));
return configConfigurationPropertiesProviders;
}
Aggregations