use of org.mule.runtime.api.meta.model.parameter.ParameterRole.BEHAVIOUR in project mule by mulesoft.
the class ExtensionDefinitionParser method parseField.
private void parseField(ObjectType type, DslElementSyntax typeDsl, ObjectFieldType objectField, Map<String, ParameterRole> parametersRole) {
final MetadataType fieldType = objectField.getValue();
final String fieldName = objectField.getKey().getName().getLocalPart();
final boolean acceptsReferences = ExtensionMetadataTypeUtils.acceptsReferences(objectField);
final Object defaultValue = getDefaultValue(fieldType).orElse(null);
final ExpressionSupport expressionSupport = getExpressionSupport(objectField);
Optional<DslElementSyntax> fieldDsl = typeDsl.getContainedElement(fieldName);
if (!fieldDsl.isPresent() && !isFlattenedParameterGroup(objectField)) {
return;
}
Optional<String> keyName = getInfrastructureParameterName(fieldType);
if (keyName.isPresent()) {
parseObject(fieldName, keyName.get(), (ObjectType) fieldType, defaultValue, expressionSupport, false, acceptsReferences, fieldDsl.get(), emptySet());
return;
}
final boolean isContent = isContent(parametersRole.getOrDefault(fieldName, BEHAVIOUR));
fieldType.accept(new MetadataTypeVisitor() {
@Override
protected void defaultVisit(MetadataType metadataType) {
if (!parseAsContent(isContent, metadataType)) {
parseAttributeParameter(fieldName, fieldName, metadataType, defaultValue, expressionSupport, false, emptySet());
}
}
@Override
public void visitString(StringType stringType) {
if (fieldDsl.get().supportsChildDeclaration()) {
String elementName = fieldDsl.get().getElementName();
addParameter(fieldName, fromChildConfiguration(String.class).withWrapperIdentifier(elementName));
addDefinition(baseDefinitionBuilder.withIdentifier(elementName).withTypeDefinition(fromType(String.class)).withTypeConverter(value -> resolverOf(elementName, stringType, value, defaultValue, expressionSupport, false, emptySet(), acceptsReferences)).build());
} else {
defaultVisit(stringType);
}
}
@Override
public void visitObject(ObjectType objectType) {
if (objectType.isOpen()) {
if (!parseAsContent(isContent, objectType)) {
parseMapParameters(fieldName, fieldName, objectType, defaultValue, expressionSupport, false, fieldDsl.get(), emptySet());
}
return;
}
if (isFlattenedParameterGroup(objectField)) {
dslResolver.resolve(objectType).ifPresent(objectDsl -> objectType.getFields().forEach(field -> parseField(objectType, objectDsl, field, parametersRole)));
return;
}
if (parseAsContent(isContent, objectType)) {
return;
}
DslElementSyntax dsl = fieldDsl.get();
if (!parsingContext.isRegistered(dsl.getElementName(), dsl.getPrefix())) {
parsingContext.registerObjectType(dsl.getElementName(), dsl.getPrefix(), type);
parseObjectParameter(fieldName, fieldName, objectType, defaultValue, expressionSupport, false, acceptsReferences, dsl, emptySet());
} else {
parseObject(fieldName, fieldName, objectType, defaultValue, expressionSupport, false, acceptsReferences, dsl, emptySet());
}
}
@Override
public void visitArrayType(ArrayType arrayType) {
if (!parseAsContent(isContent, arrayType)) {
parseCollectionParameter(fieldName, fieldName, arrayType, defaultValue, expressionSupport, false, fieldDsl.get(), emptySet());
}
}
private boolean parseAsContent(boolean isContent, MetadataType type) {
if (isContent) {
parseFromTextExpression(fieldName, fieldDsl.get(), () -> value -> resolverOf(fieldName, type, value, defaultValue, expressionSupport, false, emptySet(), false));
return true;
}
return false;
}
});
}
Aggregations