use of org.mule.runtime.app.declaration.api.TopLevelParameterDeclaration 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.TopLevelParameterDeclaration in project mule by mulesoft.
the class DeclarationElementModelFactoryTestCase method testGlobalParameterDeclarationToElement.
@Test
public void testGlobalParameterDeclarationToElement() {
ElementDeclarer ext = ElementDeclarer.forExtension(EXTENSION_NAME);
final ParameterObjectValue.Builder value = newObjectValue().withParameter(BEHAVIOUR_NAME, "additional").withParameter(CONTENT_NAME, "#[{field: value}]");
getId(complexType).ifPresent(value::ofType);
TopLevelParameterDeclaration declaration = ext.newGlobalParameter(SOURCE_NAME).withRefName("globalParameter").withValue(value.build()).getDeclaration();
DslElementModel<MetadataType> element = create(declaration);
assertThat(element.getModel(), is(complexType));
assertThat(element.getContainedElements().size(), is(2));
assertThat(element.findElement(BEHAVIOUR_NAME).isPresent(), is(true));
assertThat(element.findElement("myCamelCaseName").get().getValue().get(), is("#[{field: value}]"));
assertThat(element.getConfiguration().get().getParameters().get(BEHAVIOUR_NAME), is("additional"));
}
Aggregations