use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker 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.util.IdempotentExtensionWalker in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method blockingExecutionTypes.
@Test
public void blockingExecutionTypes() {
final List<String> nonBlockingOperations = Arrays.asList("killMany", "executeAnything", "alwaysFailsWrapper", "getChain", "exceptionOnCallbacks", "neverFailsWrapper", "payloadModifier");
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
Reference<Boolean> cpuIntensive = new Reference<>(false);
Reference<Boolean> blocking = new Reference<>(false);
new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel operation) {
String operationName = operation.getName();
assertThat(operation.isBlocking(), is(!nonBlockingOperations.contains(operationName)));
if (operationName.equals("approve")) {
assertThat(operation.getExecutionType(), is(CPU_INTENSIVE));
cpuIntensive.set(true);
} else if (operation.requiresConnection()) {
assertThat(operation.getExecutionType(), is(BLOCKING));
blocking.set(true);
} else {
assertThat(operation.getExecutionType(), is(CPU_LITE));
}
}
}.walk(extensionModel);
assertThat(cpuIntensive.get(), is(true));
assertThat(blocking.get(), is(true));
}
use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker in project mule by mulesoft.
the class DefaultExtensionModelFactoryTestCase method exportedLibraries.
@Test
public void exportedLibraries() {
ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
assertExternalLibraries(extensionModel);
new IdempotentExtensionWalker() {
@Override
protected void onConfiguration(ConfigurationModel model) {
assertExternalLibraries(model);
}
@Override
protected void onConnectionProvider(ConnectionProviderModel model) {
assertExternalLibraries(model);
}
}.walk(extensionModel);
}
use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker in project mule by mulesoft.
the class ExtensionErrorsRegistrant method registerErrors.
/**
* Registers the found {@link ErrorModel} from each {@link OperationModel} into the {@link ErrorTypeRepository} and creates an
* {@link ExceptionMapper} for each {@link OperationModel} that declares {@link ErrorModel}s.
*
* @param extensionModel from where get the {@link ErrorModel} from each {@link OperationModel}
*/
void registerErrors(ExtensionModel extensionModel) {
Set<ErrorModel> errorTypes = extensionModel.getErrorModels();
String extensionNamespace = extensionModel.getXmlDslModel().getPrefix();
String errorExtensionNamespace = MuleExtensionUtils.getExtensionsNamespace(extensionModel);
DslSyntaxResolver syntaxResolver = DslSyntaxResolver.getDefault(extensionModel, new SingleExtensionImportTypesStrategy());
ErrorModel connectivityErrorModel = newError(CONNECTIVITY_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build();
ErrorModel retryExhaustedError = newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
errorTypes.forEach(errorModel -> getErrorType(errorModel, extensionModel));
ExtensionWalker extensionWalker = new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel model) {
registerErrors(model);
}
@Override
protected void onConstruct(ConstructModel model) {
registerErrors(model);
}
private void registerErrors(ComponentModel model) {
if (!errorTypes.isEmpty()) {
ExceptionMapper.Builder builder = ExceptionMapper.builder();
builder.addExceptionMapping(ConnectionException.class, getErrorType(connectivityErrorModel, extensionModel));
builder.addExceptionMapping(RetryPolicyExhaustedException.class, getErrorType(retryExhaustedError, extensionModel));
String elementName = syntaxResolver.resolve(model).getElementName();
errorTypeLocator.addComponentExceptionMapper(createIdentifier(elementName, extensionNamespace), builder.build());
}
}
};
extensionWalker.walk(extensionModel);
}
Aggregations