use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class IntrospectionUtilsTestCase method assertPagingProviderReturnType.
private void assertPagingProviderReturnType(String method) throws Exception {
MetadataType returnType = IntrospectionUtils.getMethodReturnType(getMethod(method));
assertThat(returnType, is(instanceOf(ArrayType.class)));
assertThat(((ArrayType) returnType).getType(), is(instanceOf(StringType.class)));
assertType(((ArrayType) returnType).getType(), String.class);
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method getComponentChildVisitor.
private MetadataTypeVisitor getComponentChildVisitor(final DslElementModel.Builder typeBuilder, final ComponentConfiguration configuration, final MetadataType model, final String name, final DslElementSyntax modelDsl, final Optional<String> defaultValue, Deque<String> typeResolvingStack) {
final Map<String, String> parameters = configuration.getParameters();
return new MetadataTypeVisitor() {
@Override
protected void defaultVisit(MetadataType metadataType) {
DslElementModel.Builder<MetadataType> elementBuilder = DslElementModel.<MetadataType>builder().withModel(model).withDsl(modelDsl);
Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
String value = parameters.get(name);
if (isBlank(value)) {
if (identifier.isPresent()) {
ComponentConfiguration nested = getSingleComponentConfiguration(getNestedComponents(configuration), identifier);
if (nested != null && nested.getValue().isPresent() && !isBlank(nested.getValue().get())) {
value = nested.getValue().get().trim();
}
} else if (defaultValue.isPresent()) {
value = defaultValue.get();
elementBuilder.isExplicitInDsl(false);
}
}
if (!isBlank(value)) {
typeBuilder.containing(elementBuilder.withValue(value).build());
}
}
@Override
public void visitArrayType(ArrayType arrayType) {
Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
if (identifier.isPresent()) {
ComponentConfiguration fieldComponent = getSingleComponentConfiguration(getNestedComponents(configuration), identifier);
if (fieldComponent != null) {
DslElementModel.Builder<Object> list = DslElementModel.builder().withModel(model).withDsl(modelDsl).withConfig(fieldComponent);
modelDsl.getGeneric(arrayType.getType()).ifPresent(itemdsl -> {
ComponentIdentifier itemIdentifier = getIdentifier(itemdsl).get();
fieldComponent.getNestedComponents().forEach(c -> {
if (c.getIdentifier().equals(itemIdentifier)) {
getComponentChildVisitor(list, c, arrayType.getType(), VALUE_ATTRIBUTE_NAME, itemdsl, defaultValue, typeResolvingStack);
}
});
});
typeBuilder.containing(list.build());
return;
}
}
defaultValue.ifPresent(s -> typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(defaultValue.get()).isExplicitInDsl(false).build()));
}
@Override
public void visitObject(ObjectType objectType) {
Optional<ComponentIdentifier> identifier = getIdentifier(modelDsl);
if (identifier.isPresent()) {
if (isMap(objectType)) {
typeBuilder.containing(createMapElement(objectType, modelDsl, configuration));
return;
}
Multimap<ComponentIdentifier, ComponentConfiguration> nestedComponents = getNestedComponents(configuration);
ComponentConfiguration fieldComponent = nestedComponents.containsKey(identifier.get()) ? nestedComponents.get(identifier.get()).iterator().next() : null;
fieldComponent = fieldComponent == null ? configuration : fieldComponent;
String value = fieldComponent.getParameters().get(modelDsl.getAttributeName());
if (!isBlank(value)) {
typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(value).build());
} else {
resolveBasedOnType(objectType, fieldComponent, typeResolvingStack).ifPresent(typeBuilder::containing);
}
return;
}
defaultValue.ifPresent(s -> typeBuilder.containing(DslElementModel.builder().withModel(model).withDsl(modelDsl).withValue(defaultValue.get()).isExplicitInDsl(false).build()));
}
};
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createTopLevelElement.
private DslElementModel createTopLevelElement(ObjectType model, TopLevelParameterDeclaration declaration) {
DslElementSyntax objectDsl = dsl.resolve(model).orElseThrow(() -> new IllegalArgumentException("Failed to resolve the DSL syntax for type '" + getId(model) + "'"));
DslElementModel.Builder<MetadataType> parentElement = DslElementModel.<MetadataType>builder().withModel(model).withDsl(objectDsl);
InternalComponentConfiguration.Builder configuration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(objectDsl)).withParameter(NAME_ATTRIBUTE_NAME, declaration.getRefName());
populateObjectElementFields(model, declaration.getValue(), objectDsl, configuration, parentElement);
return parentElement.withConfig(configuration.build()).build();
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createMapParameter.
private void createMapParameter(ParameterObjectValue objectValue, DslElementSyntax paramDsl, Object model, ObjectType mapType, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
InternalComponentConfiguration.Builder mapConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
DslElementModel.Builder mapElement = DslElementModel.builder().withModel(model).withDsl(paramDsl);
MetadataType valueType = mapType.getOpenRestriction().get();
paramDsl.getGeneric(valueType).ifPresent(entryDsl -> objectValue.getParameters().forEach((key, value) -> {
InternalComponentConfiguration.Builder entryConfigBuilder = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(entryDsl));
DslElementModel.Builder<MetadataType> entryElement = DslElementModel.<MetadataType>builder().withModel(valueType).withDsl(entryDsl);
entryDsl.getAttribute(KEY_ATTRIBUTE_NAME).ifPresent(keyDsl -> {
entryConfigBuilder.withParameter(KEY_ATTRIBUTE_NAME, key);
entryElement.containing(DslElementModel.builder().withModel(typeLoader.load(String.class)).withDsl(keyDsl).withValue(key).build());
});
entryDsl.getAttribute(VALUE_ATTRIBUTE_NAME).ifPresent(valueDsl -> value.accept(new ParameterValueVisitor() {
@Override
public void visitSimpleValue(ParameterSimpleValue text) {
entryConfigBuilder.withParameter(VALUE_ATTRIBUTE_NAME, text.getValue());
entryElement.containing(DslElementModel.builder().withModel(valueType).withDsl(valueDsl).withValue(text.getValue()).build());
}
@Override
public void visitListValue(ParameterListValue list) {
createList(list, valueDsl, valueType, (ArrayType) valueType, entryConfigBuilder, entryElement);
}
@Override
public void visitObjectValue(ParameterObjectValue objectValue) {
if (isMap(valueType)) {
createMapParameter(objectValue, valueDsl, valueType, (ObjectType) valueType, entryConfigBuilder, entryElement);
} else {
createObject(objectValue, valueDsl, valueType, (ObjectType) valueType, entryConfigBuilder, entryElement);
}
}
}));
ComponentConfiguration entryConfig = entryConfigBuilder.build();
mapConfig.withNestedComponent(entryConfig);
mapElement.containing(entryElement.withConfig(entryConfig).build());
}));
ComponentConfiguration result = mapConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(mapElement.withConfig(result).build());
}
use of org.mule.metadata.api.model.MetadataType in project mule by mulesoft.
the class DefaultXmlDslElementModelConverter method asXml.
/**
* {@inheritDoc}
*/
@Override
public Element asXml(DslElementModel elementModel) {
Object model = elementModel.getModel();
checkArgument(model instanceof ConfigurationModel || model instanceof ComponentModel || model instanceof MetadataType, "The element must be either a MetadataType, ConfigurationModel or a ComponentModel");
DslElementSyntax dsl = elementModel.getDsl();
Element componentRoot = createElement(dsl, elementModel.getConfiguration());
if (isEETransform(componentRoot)) {
return populateEETransform(elementModel);
}
writeApplicationElement(componentRoot, elementModel, componentRoot);
return componentRoot;
}
Aggregations