use of org.mule.runtime.app.declaration.api.SourceElementDeclaration in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method create.
public <T> Optional<DslElementModel<T>> create(ElementDeclaration declaration) {
setupCurrentExtensionContext(declaration.getDeclaringExtension());
final Function<NamedObject, Boolean> equalsName = (named) -> named.getName().equals(declaration.getName());
if (declaration instanceof TopLevelParameterDeclaration) {
return createFromType((TopLevelParameterDeclaration) declaration);
}
Reference<DslElementModel> elementModel = new Reference<>();
new ExtensionWalker() {
@Override
protected void onConfiguration(ConfigurationModel model) {
if (equalsName.apply(model) && declaration instanceof ConfigurationElementDeclaration) {
elementModel.set(createConfigurationElement(model, (ConfigurationElementDeclaration) declaration));
stop();
}
}
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
if (equalsName.apply(model) && declaration instanceof OperationElementDeclaration) {
elementModel.set(createComponentElement(model, (OperationElementDeclaration) declaration));
stop();
}
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
if (equalsName.apply(model) && declaration instanceof ConstructElementDeclaration) {
elementModel.set(createComponentElement(model, (ConstructElementDeclaration) declaration));
stop();
}
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
if (equalsName.apply(model) && declaration instanceof SourceElementDeclaration) {
elementModel.set(createComponentElement(model, (SourceElementDeclaration) declaration));
stop();
}
}
}.walk(currentExtension);
if (LOGGER.isDebugEnabled() && elementModel.get() == null) {
LOGGER.debug(format("No model found with name [%s] of type [%s] for extension [%s]", declaration.getName(), declaration.getClass().getName(), declaration.getDeclaringExtension()));
}
return Optional.ofNullable(elementModel.get());
}
use of org.mule.runtime.app.declaration.api.SourceElementDeclaration in project mule by mulesoft.
the class DeclarationElementModelFactoryTestCase method testSourceDeclarationToElement.
@Test
public void testSourceDeclarationToElement() {
ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
SourceElementDeclaration declaration = ext.newSource(SOURCE_NAME).withConfig(CONFIGURATION_NAME).withParameterGroup(newParameterGroup().withParameter(BEHAVIOUR_NAME, "additional").withParameter(CONTENT_NAME, "#[{field: value}]").getDeclaration()).getDeclaration();
DslElementModel<SourceModel> element = create(declaration);
assertThat(element.getModel(), is(source));
assertThat(element.getContainedElements().size(), is(2));
assertThat(element.findElement(BEHAVIOUR_NAME).isPresent(), is(true));
assertThat(element.findElement(CONTENT_NAME).get().getConfiguration().get().getValue().get(), is("#[{field: value}]"));
assertThat(element.getConfiguration().get().getParameters().get(BEHAVIOUR_NAME), is("additional"));
}
Aggregations