use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ExtensionDefinitionParser method parseInlineParameterGroup.
protected void parseInlineParameterGroup(ParameterGroupModel group) throws ConfigurationException {
ParameterGroupDescriptor descriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(ParameterGroupModelProperty::getDescriptor).orElse(null);
DslElementSyntax dslElementSyntax = dslResolver.resolveInline(group);
if (descriptor != null) {
addParameter(getChildKey(getContainerName(descriptor.getContainer())), new DefaultObjectParsingDelegate().parse("", null, dslElementSyntax));
new TypedInlineParameterGroupParser(baseDefinitionBuilder, group, descriptor, getContextClassLoader(), dslElementSyntax, dslResolver, parsingContext).parse().forEach(this::addDefinition);
} else {
AttributeDefinition.Builder builder = fromChildConfiguration(Map.class);
if (dslElementSyntax.isWrapped()) {
builder.withWrapperIdentifier(dslElementSyntax.getElementName());
} else {
builder.withIdentifier(dslElementSyntax.getElementName());
}
addParameter(getChildKey(group.getName()), builder);
new AnonymousInlineParameterGroupParser(baseDefinitionBuilder, group, getContextClassLoader(), dslElementSyntax, dslResolver, parsingContext).parse().forEach(this::addDefinition);
}
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ExtensionDefinitionParser method parseObjectParameter.
/**
* Registers a definition for a {@link ParameterModel} which represents an {@link ObjectType}
*
* @param key the key that the parsed value should have on the parsed parameter's map
* @param name the parameter's name
* @param type an {@link ObjectType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required or not
* @param modelProperties parameter's {@link ModelProperty}s
*/
protected void parseObjectParameter(String key, String name, ObjectType type, Object defaultValue, ExpressionSupport expressionSupport, boolean required, boolean acceptsReferences, DslElementSyntax elementDsl, Set<ModelProperty> modelProperties) {
parseObject(key, name, type, defaultValue, expressionSupport, required, acceptsReferences, elementDsl, modelProperties);
final String elementNamespace = elementDsl.getPrefix();
final String elementName = elementDsl.getElementName();
if (elementDsl.supportsChildDeclaration() && !elementDsl.isWrapped() && modelProperties.stream().noneMatch(m -> m.getName().equals(InfrastructureParameterModelProperty.NAME))) {
try {
new ObjectTypeParameterParser(baseDefinitionBuilder, elementName, elementNamespace, type, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(this::addDefinition);
} catch (Exception e) {
throw new MuleRuntimeException(new ConfigurationException(e));
}
}
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ObjectTypeSchemaDelegate method declarePojoAsType.
private ComplexType declarePojoAsType(ObjectType metadataType, QName base, String description, Collection<ObjectFieldType> fields) {
final TopLevelComplexType complexType = new TopLevelComplexType();
registeredComplexTypesHolders.put(getId(metadataType), new ComplexTypeHolder(complexType, metadataType));
complexType.setName(sanitizeName(getId(metadataType)));
complexType.setAnnotation(builder.createDocAnnotation(description));
ComplexContent complexContent = new ComplexContent();
complexType.setComplexContent(complexContent);
final ExtensionType extension = new ExtensionType();
extension.setBase(base);
complexContent.setExtension(extension);
DslElementSyntax typeDsl = dsl.resolve(metadataType).get();
List<TopLevelElement> childElements = new LinkedList<>();
fields.forEach(field -> {
String fieldName = field.getKey().getName().getLocalPart();
DslElementSyntax fieldDsl = typeDsl.getContainedElement(fieldName).orElse(null);
if (isFlattenedParameterGroup(field)) {
declareGroupedFields(extension, childElements, field);
} else {
declareObjectField(fieldDsl, field, extension, childElements);
}
});
if (!childElements.isEmpty()) {
final ExplicitGroup all = new ExplicitGroup();
all.setMaxOccurs(MAX_ONE);
boolean requiredChilds = childElements.stream().anyMatch(builder::isRequired);
all.setMinOccurs(requiredChilds ? ONE : ZERO);
childElements.forEach(p -> all.getParticle().add(objectFactory.createElement(p)));
extension.setSequence(all);
}
return complexType;
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ObjectTypeSchemaDelegate method createComplexTypeWithAbstractElementRef.
private LocalComplexType createComplexTypeWithAbstractElementRef(MetadataType type) {
DslElementSyntax typeDsl = builder.getDslResolver().resolve(type).orElseThrow(() -> new IllegalArgumentException(format("No element ref can be created for the given type [%s]", getId(type))));
LocalComplexType complexType = new LocalComplexType();
if (typeDsl.isWrapped()) {
complexType.setChoice(builder.createTypeRefChoiceLocalOrGlobal(typeDsl, type, ONE, MAX_ONE));
} else {
ExplicitGroup sequence = new ExplicitGroup();
sequence.setMinOccurs(ONE);
sequence.setMaxOccurs(MAX_ONE);
sequence.getParticle().add(objectFactory.createElement(createRefToLocalElement(typeDsl, type)));
complexType.setSequence(sequence);
}
return complexType;
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ObjectTypeSchemaDelegate method registerAbstractElement.
private TopLevelElement registerAbstractElement(MetadataType type, QName typeQName, DslElementSyntax typeDsl, ObjectType baseType) {
TopLevelElement element = registeredGlobalElementTypes.get(typeDsl.getPrefix() + getAbstractElementName(typeDsl));
if (element != null) {
return element;
}
Optional<DslElementSyntax> baseDsl = builder.getDslResolver().resolve(baseType);
if (typeDsl.isWrapped()) {
createGlobalMuleExtensionAbstractElement(typeQName, typeDsl, baseDsl);
}
TopLevelElement abstractElement = new TopLevelElement();
abstractElement.setName(getAbstractElementName(typeDsl));
abstractElement.setAbstract(true);
if (!typeDsl.supportsTopLevelDeclaration()) {
abstractElement.setType(typeQName);
}
if (baseDsl.isPresent() || typeDsl.supportsTopLevelDeclaration()) {
QName substitutionGroup = getAbstractElementSubstitutionGroup(typeDsl, baseDsl);
abstractElement.setSubstitutionGroup(substitutionGroup);
}
// If user defined, substitutionGroup will be overridden
getSubstitutionGroup(type).ifPresent((substitutionGroup) -> abstractElement.setSubstitutionGroup(builder.resolveSubstitutionGroup(substitutionGroup)));
builder.getSchema().getSimpleTypeOrComplexTypeOrGroup().add(abstractElement);
registeredGlobalElementTypes.put(typeDsl.getPrefix() + getAbstractElementName(typeDsl), abstractElement);
return abstractElement;
}
Aggregations