use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType in project mule by mulesoft.
the class CollectionSchemaDelegate method generateCollectionComplexType.
private LocalComplexType generateCollectionComplexType(DslElementSyntax collectionDsl, final ArrayType metadataType) {
final LocalComplexType collectionComplexType = new LocalComplexType();
final ExplicitGroup sequence = new ExplicitGroup();
final MetadataType genericType = metadataType.getType();
DslElementSyntax itemDsl = collectionDsl.getGeneric(genericType).orElseThrow(() -> new IllegalArgumentException(format("Missing item's DSL information for collection [%s]", collectionDsl.getAttributeName())));
genericType.accept(new MetadataTypeVisitor() {
/**
* For a Collection with an {@link ObjectType} as generic. The generated {@link ComplexType} declares a sequence of either a
* {@code ref} or a {@code choice}.
* <p/>
* It creates an element {@code ref} to the concrete element whose {@code type} is the {@link ComplexType} associated to the
* {@code objectType}
* <p/>
* In the case of having a {@link DslElementSyntax#isWrapped wrapped} {@link ObjectType}, then a {@link ExplicitGroup
* Choice} group that can receive a {@code ref} to any subtype that this wrapped type might have, be it either a top-level
* element for the mule schema, or if it can only be declared as child of this element.
*
* If the collections's value is a map, then a value attribute is created for the value map.
*
* @param objectType the item's type
*/
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
defaultVisit(objectType);
return;
}
DslElementSyntax typeDsl = builder.getDslResolver().resolve(objectType).orElseThrow(() -> new IllegalArgumentException(format("The given type [%s] cannot be represented as a collection item", getId(objectType))));
if (typeDsl.isWrapped()) {
ExplicitGroup choice = builder.createTypeRefChoiceLocalOrGlobal(typeDsl, objectType, ZERO, UNBOUNDED);
sequence.getParticle().add(objectFactory.createChoice(choice));
} else {
TopLevelElement collectionItemElement = builder.createTypeRef(typeDsl, objectType, false);
collectionItemElement.setMaxOccurs(UNBOUNDED);
sequence.getParticle().add(objectFactory.createElement(collectionItemElement));
}
}
/**
* For a Collection with any other type as generic.
* The generated {@link ComplexType} declares a sequence of child elements with an inline declaration of the type
*
* @param metadataType the item's type
*/
@Override
protected void defaultVisit(MetadataType metadataType) {
final LocalComplexType complexType = new LocalComplexType();
complexType.getAttributeOrAttributeGroup().add(builder.createValueAttribute(genericType));
TopLevelElement collectionItemElement = builder.createTopLevelElement(itemDsl.getElementName(), ZERO, UNBOUNDED);
collectionItemElement.setComplexType(complexType);
sequence.getParticle().add(objectFactory.createElement(collectionItemElement));
}
});
collectionComplexType.setSequence(sequence);
return collectionComplexType;
}
Aggregations