use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class ObjectTypeVisitorTestCase method testFailsIfTypeIsNotOfCheckedClass.
@Test
public void testFailsIfTypeIsNotOfCheckedClass() throws ClassNotFoundException {
exception.expect(MuleRuntimeException.class);
exception.expectMessage("is not the same nor inherits from");
ComponentModel componentModel = new SpringComponentModel();
componentModel.setParameter("type", this.getClass().getName());
ObjectTypeVisitor visitor = new ObjectTypeVisitor(componentModel);
TypeDefinition typeDefinition = fromConfigurationAttribute("type").checkingThatIsClassOrInheritsFrom(ReferenceProcessor.class);
typeDefinition.visit(visitor);
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method extractOperationExtension.
private void extractOperationExtension(HasOperationDeclarer declarer, ComponentModel operationModel, DirectedGraph<String, DefaultEdge> directedGraph, XmlDslModel xmlDslModel) {
String operationName = operationModel.getNameAttribute();
OperationDeclarer operationDeclarer = declarer.withOperation(operationName);
ComponentModel bodyComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_BODY_IDENTIFIER)).findFirst().orElseThrow(() -> new IllegalArgumentException(format("The operation '%s' is missing the <body> statement", operationName)));
directedGraph.addVertex(operationName);
fillGraphWithTnsReferences(directedGraph, operationName, bodyComponentModel.getInnerComponents());
operationDeclarer.withModelProperty(new OperationComponentModelModelProperty(operationModel, bodyComponentModel));
operationDeclarer.describedAs(getDescription(operationModel));
operationDeclarer.getDeclaration().setDisplayModel(getDisplayModel(operationModel));
extractOperationParameters(operationDeclarer, operationModel);
extractOutputType(operationDeclarer.withOutput(), OPERATION_OUTPUT_IDENTIFIER, operationModel, getDeclarationOutputFor(operationName));
extractOutputType(operationDeclarer.withOutputAttributes(), OPERATION_OUTPUT_ATTRIBUTES_IDENTIFIER, operationModel, getDeclarationOutputAttributesFor(operationName));
declareErrorModels(operationDeclarer, xmlDslModel, operationName, operationModel);
}
use of org.mule.runtime.config.internal.model.ComponentModel 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.config.internal.model.ComponentModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method loadPropertiesFrom.
private Optional<ConfigurationDeclarer> loadPropertiesFrom(ExtensionDeclarer declarer, ComponentModel moduleModel, Set<ExtensionModel> extensions) {
List<ComponentModel> globalElementsComponentModel = extractGlobalElementsFrom(moduleModel);
List<ComponentModel> configurationProperties = extractProperties(moduleModel);
List<ComponentModel> connectionProperties = extractConnectionProperties(moduleModel);
validateProperties(configurationProperties, connectionProperties);
if (!configurationProperties.isEmpty() || !connectionProperties.isEmpty() || !globalElementsComponentModel.isEmpty()) {
declarer.withModelProperty(new NoReconnectionStrategyModelProperty());
ConfigurationDeclarer configurationDeclarer = declarer.withConfig(CONFIG_NAME);
configurationDeclarer.withModelProperty(new GlobalElementComponentModelModelProperty(globalElementsComponentModel));
configurationProperties.stream().forEach(param -> extractProperty(configurationDeclarer, param));
addConnectionProvider(configurationDeclarer, connectionProperties, globalElementsComponentModel, extensions);
return of(configurationDeclarer);
}
return empty();
}
use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method loadModuleExtension.
private void loadModuleExtension(ExtensionDeclarer declarer, URL resource, Document moduleDocument, Set<ExtensionModel> extensions, boolean comesFromTNS) {
final ComponentModel moduleModel = getModuleComponentModel(resource, moduleDocument);
if (!moduleModel.getIdentifier().equals(MODULE_IDENTIFIER)) {
throw new MuleRuntimeException(createStaticMessage(format("The root element of a module must be '%s', but found '%s'", MODULE_IDENTIFIER.toString(), moduleModel.getIdentifier().toString())));
}
final String name = moduleModel.getParameters().get(MODULE_NAME);
// TODO(fernandezlautaro): MULE-11010 remove version from ExtensionModel
final String version = "4.0.0";
final String category = moduleModel.getParameters().get(CATEGORY);
final String vendor = moduleModel.getParameters().get(VENDOR);
final XmlDslModel xmlDslModel = getXmlDslModel(moduleModel, name, version);
final String description = getDescription(moduleModel);
final String xmlnsTnsValue = moduleModel.getParameters().get(XMLNS_TNS);
if (xmlnsTnsValue != null && !xmlDslModel.getNamespace().equals(xmlnsTnsValue)) {
throw new MuleRuntimeException(createStaticMessage(format("The %s attribute value of the module must be '%s', but found '%s'", XMLNS_TNS, xmlDslModel.getNamespace(), xmlnsTnsValue)));
}
fillDeclarer(declarer, name, version, category, vendor, xmlDslModel, description);
declarer.withModelProperty(getXmlExtensionModelProperty(moduleModel, xmlDslModel));
DirectedGraph<String, DefaultEdge> directedGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
// loading public operations
final Optional<ConfigurationDeclarer> configurationDeclarer = loadPropertiesFrom(declarer, moduleModel, extensions);
final HasOperationDeclarer hasOperationDeclarer = configurationDeclarer.isPresent() ? configurationDeclarer.get() : declarer;
loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PUBLIC);
// loading private operations
if (comesFromTNS) {
// when parsing for the TNS, we need the <operation/>s to be part of the extension model to validate the XML properly
loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
} else {
// when parsing for the macro expansion, the <operation/>s will be left in the PrivateOperationsModelProperty model property
final ExtensionDeclarer temporalDeclarer = new ExtensionDeclarer();
fillDeclarer(temporalDeclarer, name, version, category, vendor, xmlDslModel, description);
loadOperationsFrom(temporalDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
final ExtensionModel result = createExtensionModel(temporalDeclarer);
declarer.withModelProperty(new PrivateOperationsModelProperty(result.getOperationModels()));
}
final CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(directedGraph);
final Set<String> cycles = cycleDetector.findCycles();
if (!cycles.isEmpty()) {
throw new MuleRuntimeException(createStaticMessage(format(CYCLIC_OPERATIONS_ERROR, new TreeSet(cycles))));
}
}
Aggregations