use of org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createWrappedObject.
private void createWrappedObject(ParameterObjectValue objectValue, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
DslElementModel.Builder<ParameterModel> wrapperElement = DslElementModel.<ParameterModel>builder().withModel(parameterModel).withDsl(paramDsl);
InternalComponentConfiguration.Builder wrapperConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
Reference<DslSyntaxResolver> customDsl = new Reference<>(dsl);
ObjectType nestedElementType;
if (objectValue.getTypeId() == null || objectValue.getTypeId().trim().isEmpty() || getId(parameterModel.getType()).map(id -> id.equals(objectValue.getTypeId())).orElse(false)) {
nestedElementType = (ObjectType) parameterModel.getType();
} else {
nestedElementType = lookupType(objectValue);
context.getTypeCatalog().getDeclaringExtension(objectValue.getTypeId()).ifPresent(owner -> context.getExtension(owner).ifPresent(extensionModel -> customDsl.set(resolvers.get(extensionModel))));
}
customDsl.get().resolve(nestedElementType).ifPresent(typeDsl -> createObject(objectValue, typeDsl, nestedElementType, nestedElementType, wrapperConfig, wrapperElement));
ComponentConfiguration result = wrapperConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(wrapperElement.withConfig(result).build());
}
use of org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver 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.extension.api.dsl.syntax.resolver.DslSyntaxResolver in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method getComponentDeclaringWalker.
private ExtensionWalker getComponentDeclaringWalker(final Consumer<ComponentElementDeclaration> declarationConsumer, final ConfigLine line, final ElementDeclarer extensionElementsDeclarer) {
final DslSyntaxResolver dsl = resolvers.get(getNamespace(line));
return new ExtensionWalker() {
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
if (!model.getName().equals(TRANSFORM_IDENTIFIER)) {
declareComponentModel(line, model, extensionElementsDeclarer::newOperation).ifPresent(declarer -> {
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
} else {
declareTransform(model);
}
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
declareComponentModel(line, model, extensionElementsDeclarer::newSource).ifPresent(declarer -> {
final DslElementSyntax elementDsl = dsl.resolve(model);
model.getSuccessCallback().ifPresent(cb -> declareParameterizedComponent(cb, elementDsl, declarer, line.getConfigAttributes(), line.getChildren()));
model.getErrorCallback().ifPresent(cb -> declareParameterizedComponent(cb, elementDsl, declarer, line.getConfigAttributes(), line.getChildren()));
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
declareComponentModel(line, model, extensionElementsDeclarer::newConstruct).ifPresent(declarer -> {
declarationConsumer.accept((ComponentElementDeclaration) declarer.getDeclaration());
stop();
});
}
private void declareTransform(ComponentModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
if (model.getName().equals(TRANSFORM_IDENTIFIER) && elementDsl.getElementName().equals(line.getIdentifier())) {
ComponentElementDeclarer transform = extensionElementsDeclarer.newOperation(TRANSFORM_IDENTIFIER);
line.getChildren().stream().filter(c -> c.getIdentifier().equals("message")).findFirst().ifPresent(messageConfig -> {
ParameterGroupElementDeclarer messageGroup = newParameterGroup("Message");
messageConfig.getChildren().stream().filter(c -> c.getIdentifier().equals("set-payload")).findFirst().ifPresent(payloadConfig -> {
ParameterObjectValue.Builder payload = newObjectValue();
populateTransformScriptParameter(payloadConfig, payload);
messageGroup.withParameter("setPayload", payload.build());
});
messageConfig.getChildren().stream().filter(c -> c.getIdentifier().equals("set-attributes")).findFirst().ifPresent(attributesConfig -> {
ParameterObjectValue.Builder attributes = newObjectValue();
populateTransformScriptParameter(attributesConfig, attributes);
messageGroup.withParameter("setAttributes", attributes.build());
});
transform.withParameterGroup(messageGroup.getDeclaration());
});
line.getChildren().stream().filter(c -> c.getIdentifier().equals("variables")).findFirst().ifPresent(variablesConfig -> {
ParameterGroupElementDeclarer variablesGroup = newParameterGroup("Set Variables");
ParameterListValue.Builder variables = newListValue();
variablesConfig.getChildren().forEach(variableConfig -> {
ParameterObjectValue.Builder variable = newObjectValue();
variable.withParameter(TRANSFORM_VARIABLE_NAME, variableConfig.getConfigAttributes().get(TRANSFORM_VARIABLE_NAME).getValue());
populateTransformScriptParameter(variableConfig, variable);
variables.withValue(variable.build());
});
transform.withParameterGroup(variablesGroup.withParameter("setVariables", variables.build()).getDeclaration());
});
line.getConfigAttributes().values().forEach(a -> transform.withCustomParameter(a.getName(), a.getValue()));
declarationConsumer.accept((ComponentElementDeclaration) transform.getDeclaration());
stop();
}
}
};
}
use of org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method findTestConnectionGlobalElementFrom.
/**
* Goes over all {@code globalElementsComponentModel} looking for the configuration and connection elements (parent and child),
* where if present looks for the {@link ExtensionModel}s validating if the element is in fact a {@link ConnectionProvider}.
* It heavily relies on the {@link DslSyntaxResolver}, as many elements in the XML do not match to the names of the model.
*
* @param globalElementsComponentModel global elements of the smart connector
* @param extensions set of extensions used to generate the current {@link ExtensionModel}
* @return a {@link ComponentModel} of the global element to do test connection, empty otherwise.
*/
private Optional<ComponentModel> findTestConnectionGlobalElementFrom(List<ComponentModel> globalElementsComponentModel, Set<ExtensionModel> extensions) {
Optional<ComponentModel> testConnectionGlobalElement;
final DslResolvingContext dslResolvingContext = DslResolvingContext.getDefault(extensions);
final Set<ComponentModel> testConnectionComponentModels = new HashSet<>();
for (ComponentModel globalElementComponentModel : globalElementsComponentModel) {
for (ComponentModel connectionProviderChildElement : globalElementComponentModel.getInnerComponents()) {
final String globalElementConfigurationModelName = globalElementComponentModel.getIdentifier().getName();
final String childConnectionProviderName = connectionProviderChildElement.getIdentifier().getName();
for (ExtensionModel extensionModel : extensions) {
final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, dslResolvingContext);
for (ConfigurationModel configurationModel : extensionModel.getConfigurationModels()) {
if (dslSyntaxResolver.resolve(configurationModel).getElementName().equals(globalElementConfigurationModelName)) {
for (ConnectionProviderModel connectionProviderModel : configurationModel.getConnectionProviders()) {
if (dslSyntaxResolver.resolve(connectionProviderModel).getElementName().equals(childConnectionProviderName)) {
testConnectionComponentModels.add(globalElementComponentModel);
}
}
}
}
}
}
}
if (testConnectionComponentModels.size() > 1) {
throw new MuleRuntimeException(createStaticMessage(format("There are [%d] global elements that can be potentially used for test connection when it should be just one. Mark any of them with the attribute [%s=\"true\"], offended global elements are: [%s]", testConnectionComponentModels.size(), MODULE_CONNECTION_MARKER_ATTRIBUTE, testConnectionComponentModels.stream().map(ComponentModel::getNameAttribute).sorted().collect(Collectors.joining(", ")))));
}
testConnectionGlobalElement = testConnectionComponentModels.stream().findFirst();
return testConnectionGlobalElement;
}
use of org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareAsConnectionProvider.
private boolean declareAsConnectionProvider(ExtensionModel ownerExtension, ConfigurationModel model, ConfigurationElementDeclarer configurationDeclarer, ConfigLine config, ElementDeclarer extensionElementsDeclarer) {
final DslSyntaxResolver dsl = resolvers.get(getNamespace(config));
Optional<ConnectionProviderModel> connectionProvider = model.getConnectionProviders().stream().filter(cp -> dsl.resolve(cp).getElementName().equals(config.getIdentifier())).findFirst();
if (!connectionProvider.isPresent()) {
connectionProvider = ownerExtension.getConnectionProviders().stream().filter(cp -> dsl.resolve(cp).getElementName().equals(config.getIdentifier())).findFirst();
}
if (!connectionProvider.isPresent()) {
return true;
}
ConnectionProviderModel providerModel = connectionProvider.get();
ConnectionElementDeclarer connectionDeclarer = extensionElementsDeclarer.newConnection(providerModel.getName());
declareParameterizedComponent(providerModel, dsl.resolve(providerModel), connectionDeclarer, config.getConfigAttributes(), config.getChildren());
configurationDeclarer.withConnection(connectionDeclarer.getDeclaration());
return false;
}
Aggregations