use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker in project mule by mulesoft.
the class DefaultExtensionBuildingDefinitionProvider method registerExtensionParsers.
private void registerExtensionParsers(ExtensionModel extensionModel) {
XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
final ExtensionParsingContext parsingContext = createParsingContext(extensionModel);
final Builder definitionBuilder = new Builder().withNamespace(xmlDslModel.getPrefix());
final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, DslResolvingContext.getDefault(extensions));
if (extensionModel.getModelProperty(CustomBuildingDefinitionProviderModelProperty.class).isPresent()) {
return;
}
if (extensionModel.getModelProperty(XmlExtensionModelProperty.class).isPresent()) {
registerXmlExtensionParsers(definitionBuilder, extensionModel, dslSyntaxResolver);
} else {
final ClassLoader extensionClassLoader = getClassLoader(extensionModel);
withContextClassLoader(extensionClassLoader, () -> {
ReflectionCache reflectionCache = new ReflectionCache();
new IdempotentExtensionWalker() {
@Override
public void onConfiguration(ConfigurationModel model) {
parseWith(new ConfigurationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
protected void onConstruct(ConstructModel model) {
parseWith(new ConstructDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
public void onOperation(OperationModel model) {
parseWith(new OperationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
public void onConnectionProvider(ConnectionProviderModel model) {
parseWith(new ConnectionProviderDefinitionParser(definitionBuilder, model, extensionModel, dslSyntaxResolver, parsingContext));
}
@Override
public void onSource(SourceModel model) {
parseWith(new SourceDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
protected void onParameter(ParameterGroupModel groupModel, ParameterModel model) {
registerTopLevelParameter(model.getType(), definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
}
}.walk(extensionModel);
registerExportedTypesTopLevelParsers(extensionModel, definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
registerSubTypes(definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
});
}
}
use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker in project mule by mulesoft.
the class ConnectionProviderModelValidator method validateGlobalConnectionTypes.
private void validateGlobalConnectionTypes(ExtensionModel extensionModel, Set<ConnectionProviderModel> globalConnectionProviders, ProblemsReporter problemsReporter) {
if (globalConnectionProviders.isEmpty()) {
return;
}
for (ConnectionProviderModel connectionProviderModel : globalConnectionProviders) {
final Type connectionType = MuleExtensionUtils.getConnectionType(connectionProviderModel);
new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel operationModel) {
validateConnectionTypes(connectionProviderModel, operationModel, connectionType, problemsReporter);
}
@Override
protected void onSource(SourceModel sourceModel) {
validateConnectionTypes(connectionProviderModel, sourceModel, connectionType, problemsReporter);
}
}.walk(extensionModel);
}
}
use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker in project mule by mulesoft.
the class InputParametersTypeModelValidator method validate.
@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problems) {
final Set<Class<?>> validatedTypes = new HashSet<>();
new IdempotentExtensionWalker() {
@Override
public void onOperation(OperationModel model) {
model.getAllParameterModels().forEach(parameterModel -> validateJavaType(model, parameterModel.getType(), problems, validatedTypes));
}
@Override
public void onSource(SourceModel model) {
validateCallback(model, model.getSuccessCallback());
validateCallback(model, model.getErrorCallback());
validateCallback(model, model.getTerminateCallback());
}
private void validateCallback(SourceModel model, Optional<SourceCallbackModel> callback) {
callback.ifPresent(cb -> cb.getAllParameterModels().forEach(parameterModel -> validateJavaType(model, parameterModel.getType(), problems, validatedTypes)));
}
}.walk(extensionModel);
extensionModel.getSubTypes().forEach(subTypesModel -> getClassForValidation(subTypesModel.getBaseType()).filter(validatedTypes::contains).ifPresent(type -> {
subTypesModel.getSubTypes().forEach(subtype -> validateSubtypesHaveGetters(extensionModel, subtype, problems, validatedTypes));
}));
}
use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker in project mule by mulesoft.
the class DefaultExtensionsClient method findOperation.
private OperationModel findOperation(ExtensionModel extensionModel, String operationName) {
Reference<OperationModel> operation = new Reference<>();
ExtensionWalker walker = new IdempotentExtensionWalker() {
@Override
protected void onOperation(OperationModel operationModel) {
if (operationName.equals(operationModel.getName())) {
operation.set(operationModel);
stop();
}
}
};
walker.walk(extensionModel);
if (operation.get() == null) {
throw new MuleRuntimeException(createStaticMessage("No Operation [" + operationName + "] Found"));
}
return operation.get();
}
use of org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker in project mule by mulesoft.
the class MuleExtensionUtils method supportsOAuth.
/**
* Whether at least one {@link ConnectionProviderModel} in the given {@cod extensionModel} supports OAuth authentication
*
* @param extensionModel a {@link ExtensionModel}
* @return {@code true} if a {@link ConnectionProviderModel} exist which is OAuth enabled
*/
public static boolean supportsOAuth(ExtensionModel extensionModel) {
Reference<ConnectionProviderModel> connectionProvider = new Reference<>();
new IdempotentExtensionWalker() {
@Override
protected void onConnectionProvider(ConnectionProviderModel model) {
if (model.getModelProperty(OAuthModelProperty.class).isPresent()) {
connectionProvider.set(model);
stop();
}
}
}.walk(extensionModel);
return connectionProvider.get() != null;
}
Aggregations