use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class AbstractXmlExtensionMuleArtifactFunctionalTestCase method addBuilders.
@Override
protected void addBuilders(List<ConfigurationBuilder> builders) {
super.addBuilders(builders);
builders.add(new AbstractConfigurationBuilder() {
@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
ExtensionManager extensionManager;
if (muleContext.getExtensionManager() == null) {
extensionManager = createDefaultExtensionManager();
muleContext.setExtensionManager(extensionManager);
initialiseIfNeeded(extensionManager, muleContext);
}
extensionManager = muleContext.getExtensionManager();
registerXmlExtensions(extensionManager);
}
private void registerXmlExtensions(ExtensionManager extensionManager) {
// take all the plugins loaded by org.mule.test.runner.api.IsolatedClassLoaderExtensionsManagerConfigurationBuilder in the extension manager
final Set<ExtensionModel> extensions = new HashSet<>(extensionManager.getExtensions());
for (String modulePath : getModulePaths()) {
Map<String, Object> params = new HashMap<>();
params.put(XmlExtensionModelLoader.RESOURCE_XML, modulePath);
params.put(XmlExtensionModelLoader.VALIDATE_XML, shouldValidateXml());
operationsOutputPath().ifPresent(path -> params.put(XmlExtensionModelLoader.RESOURCE_DECLARATION, path));
final DslResolvingContext dslResolvingContext = getDefault(extensions);
final ExtensionModel extensionModel = new XmlExtensionModelLoader().loadExtensionModel(getClass().getClassLoader(), dslResolvingContext, params);
extensions.add(extensionModel);
}
for (ExtensionModel extension : extensions) {
extensionManager.registerExtension(extension);
}
}
});
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class ModuleDelegatingEntityResolver method generateFromExtensions.
private InputSource generateFromExtensions(String publicId, String systemId) {
InputSource inputSource = null;
// TODO(fernandezlautaro): MULE-11024 once implemented, remove the extensionSchemaFactory.isPresent() from the `if` statement
if (extensionSchemaFactory.isPresent()) {
Optional<ExtensionModel> extensionModel = extensions.stream().filter(em -> systemId.equals(em.getXmlDslModel().getSchemaLocation())).findAny();
if (extensionModel.isPresent()) {
InputStream schema = getSchemaFromExtension(extensionModel.get());
inputSource = new InputSource(schema);
inputSource.setPublicId(publicId);
inputSource.setSystemId(systemId);
}
}
return inputSource;
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method createIdentifiedElement.
private DslElementModel createIdentifiedElement(ComponentConfiguration configuration) {
final ComponentIdentifier identifier = configuration.getIdentifier();
Optional<Map.Entry<ExtensionModel, DslSyntaxResolver>> entry = resolvers.entrySet().stream().filter(e -> e.getKey().getXmlDslModel().getPrefix().equals(identifier.getNamespace())).findFirst();
if (!entry.isPresent()) {
return null;
}
currentExtension = entry.get().getKey();
dsl = entry.get().getValue();
Reference<DslElementModel> elementModel = new Reference<>();
new ExtensionWalker() {
@Override
protected void onConfiguration(ConfigurationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
DslElementModel.Builder<ConfigurationModel> element = createElementModel(model, elementDsl, configuration);
addConnectionProvider(model, dsl, element, configuration);
elementModel.set(element.build());
stop();
}
});
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
}.walk(currentExtension);
if (elementModel.get() == null) {
resolveBasedOnTypes(configuration).ifPresent(elementModel::set);
}
return elementModel.get();
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createComponentElement.
private DslElementModel<? extends ComponentModel> createComponentElement(ComponentModel model, ComponentElementDeclaration<?> componentDeclaration) {
DslElementSyntax configDsl = dsl.resolve(model);
InternalComponentConfiguration.Builder configuration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(configDsl));
if (componentDeclaration instanceof ReferableElementDeclaration) {
configuration.withParameter(NAME_ATTRIBUTE_NAME, ((ReferableElementDeclaration) componentDeclaration).getRefName());
}
if (componentDeclaration.getConfigRef() != null) {
configuration.withParameter(CONFIG_ATTRIBUTE_NAME, componentDeclaration.getConfigRef());
}
DslElementModel.Builder<? extends ComponentModel> componentElement = createParameterizedElementModel(model, configDsl, componentDeclaration, configuration);
ExtensionModel componentsOwner = currentExtension;
DslSyntaxResolver componentsDslResolver = dsl;
componentDeclaration.getComponents().forEach(nestedComponentDeclaration -> {
if (nestedComponentDeclaration instanceof RouteElementDeclaration) {
if (model instanceof ComposableModel) {
((ComposableModel) model).getNestedComponents().stream().filter(nestedModel -> nestedModel instanceof NestedRouteModel && nestedModel.getName().equals(nestedComponentDeclaration.getName())).findFirst().ifPresent(nestedRouteModel -> componentElement.containing(crateRouteElement((NestedRouteModel) nestedRouteModel, (RouteElementDeclaration) nestedComponentDeclaration)));
}
} else {
create(nestedComponentDeclaration).ifPresent(nestedComponentElement -> {
nestedComponentElement.getConfiguration().ifPresent(configuration::withNestedComponent);
componentElement.containing(nestedComponentElement);
});
}
currentExtension = componentsOwner;
dsl = componentsDslResolver;
});
return componentElement.withConfig(configuration.build()).build();
}
use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method crateRouteElement.
private DslElementModel<? extends NestedRouteModel> crateRouteElement(NestedRouteModel model, RouteElementDeclaration routeDeclaration) {
DslElementSyntax routeDsl = dsl.resolve(model);
InternalComponentConfiguration.Builder routeConfiguration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(routeDsl));
DslElementModel.Builder<? extends NestedRouteModel> routeElement = createParameterizedElementModel(model, routeDsl, routeDeclaration, routeConfiguration);
ExtensionModel routerOwner = currentExtension;
DslSyntaxResolver routerDslResolver = dsl;
routeDeclaration.getComponents().forEach(componentDeclaration -> {
create(componentDeclaration).ifPresent(componentElement -> {
componentElement.getConfiguration().ifPresent(routeConfiguration::withNestedComponent);
routeElement.containing(componentElement);
});
currentExtension = routerOwner;
dsl = routerDslResolver;
});
return routeElement.withConfig(routeConfiguration.build()).build();
}
Aggregations