use of org.mule.runtime.api.meta.model.XmlDslModel in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method declareErrorModels.
private void declareErrorModels(OperationDeclarer operationDeclarer, XmlDslModel xmlDslModel, String operationName, ComponentModel operationModel) {
Optional<ComponentModel> optionalParametersComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERRORS_IDENTIFIER)).findAny();
optionalParametersComponentModel.ifPresent(componentModel -> componentModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERROR_IDENTIFIER)).forEach(param -> {
final String namespace = xmlDslModel.getPrefix().toUpperCase();
final String typeName = param.getParameters().get(ERROR_TYPE_ATTRIBUTE);
if (StringUtils.isBlank(typeName)) {
throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> with an empty 'type' attribute", operationName));
}
if (typeName.contains(NAMESPACE_SEPARATOR)) {
throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> [%s] that contains a reserved character [%s]", operationName, typeName, NAMESPACE_SEPARATOR));
}
operationDeclarer.withErrorModel(ErrorModelBuilder.newError(typeName, namespace).withParent(ErrorModelBuilder.newError(ANY).build()).build());
}));
}
use of org.mule.runtime.api.meta.model.XmlDslModel in project mule by mulesoft.
the class SchemaBuilder method registerExtensionImport.
private XmlDslModel registerExtensionImport(ExtensionModel extension) {
XmlDslModel languageModel = extension.getXmlDslModel();
Import schemaImport = new Import();
schemaImport.setNamespace(languageModel.getNamespace());
schemaImport.setSchemaLocation(languageModel.getSchemaLocation());
if (!schema.getIncludeOrImportOrRedefine().contains(schemaImport)) {
schema.getIncludeOrImportOrRedefine().add(schemaImport);
}
return languageModel;
}
use of org.mule.runtime.api.meta.model.XmlDslModel in project mule by mulesoft.
the class DefaultExtensionSchemaGenerator method generate.
/**
* {@inheritDoc}
*/
@Override
public String generate(ExtensionModel extensionModel, DslResolvingContext dslContext) {
XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
validate(extensionModel, xmlDslModel);
SchemaBuilder schemaBuilder = SchemaBuilder.newSchema(extensionModel, xmlDslModel, dslContext);
new IdempotentExtensionWalker() {
@Override
public void onConfiguration(ConfigurationModel model) {
schemaBuilder.registerConfigElement(model);
}
@Override
protected void onConstruct(ConstructModel model) {
schemaBuilder.registerOperation(model);
}
@Override
public void onOperation(OperationModel model) {
schemaBuilder.registerOperation(model);
}
@Override
public void onConnectionProvider(ConnectionProviderModel model) {
schemaBuilder.registerConnectionProviderElement(model);
}
@Override
public void onSource(SourceModel model) {
schemaBuilder.registerMessageSource(model);
}
}.walk(extensionModel);
schemaBuilder.registerEnums();
// Make sure the XML libs use the container classloader internally
return withContextClassLoader(DefaultExtensionSchemaGenerator.class.getClassLoader(), () -> renderSchema(schemaBuilder.build()));
}
use of org.mule.runtime.api.meta.model.XmlDslModel 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))));
}
}
use of org.mule.runtime.api.meta.model.XmlDslModel in project mule by mulesoft.
the class ExtensionErrorsRegistrantTestCase method setUp.
@Before
public void setUp() {
XmlDslModel.XmlDslModelBuilder builder = XmlDslModel.builder();
builder.setPrefix(EXTENSION_PREFIX);
XmlDslModel xmlDslModel = builder.build();
typeRepository = createDefaultErrorTypeRepository();
typeLocator = createDefaultErrorTypeLocator(typeRepository);
when(muleContext.getErrorTypeRepository()).thenReturn(typeRepository);
when(((PrivilegedMuleContext) muleContext).getErrorTypeLocator()).thenReturn(typeLocator);
errorsRegistrant = new ExtensionErrorsRegistrant(muleContext.getErrorTypeRepository(), ((PrivilegedMuleContext) muleContext).getErrorTypeLocator());
when(extensionModel.getOperationModels()).thenReturn(asList(operationWithError, operationWithoutErrors));
when(extensionModel.getXmlDslModel()).thenReturn(xmlDslModel);
when(extensionModel.getName()).thenReturn(TEST_EXTENSION_NAME);
when(operationWithError.getErrorModels()).thenReturn(singleton(extensionConnectivityError));
when(operationWithError.getName()).thenReturn(OPERATION_NAME);
when(operationWithError.getModelProperty(any())).thenReturn(empty());
when(operationWithoutErrors.getName()).thenReturn("operationWithoutError");
when(operationWithoutErrors.getErrorModels()).thenReturn(emptySet());
when(operationWithoutErrors.getModelProperty(any())).thenReturn(empty());
visitableMock(operationWithError, operationWithoutErrors);
}
Aggregations