use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement in project mule by mulesoft.
the class ObjectTypeSchemaDelegate method createGlobalMuleExtensionAbstractElement.
private void createGlobalMuleExtensionAbstractElement(QName typeQName, DslElementSyntax typeDsl, Optional<DslElementSyntax> baseDsl) {
QName globalSubGroup;
if (baseDsl.isPresent()) {
DslElementSyntax base = baseDsl.get();
globalSubGroup = new QName(base.getNamespace(), getGlobalAbstractName(base), base.getPrefix());
} else {
globalSubGroup = MULE_ABSTRACT_SHARED_EXTENSION;
}
TopLevelElement abstractElement = new TopLevelElement();
abstractElement.setName(getGlobalAbstractName(typeDsl));
abstractElement.setSubstitutionGroup(globalSubGroup);
abstractElement.setAbstract(true);
if (!typeDsl.supportsTopLevelDeclaration()) {
abstractElement.setType(typeQName);
}
builder.getSchema().getSimpleTypeOrComplexTypeOrGroup().add(abstractElement);
}
use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement in project mule by mulesoft.
the class SchemaBuilder method createTopLevelElement.
TopLevelElement createTopLevelElement(String name, BigInteger minOccurs, String maxOccurs) {
TopLevelElement element = new TopLevelElement();
element.setName(name);
element.setMinOccurs(minOccurs);
element.setMaxOccurs(maxOccurs);
return element;
}
use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement in project mule by mulesoft.
the class SchemaBuilder method createTopLevelElement.
TopLevelElement createTopLevelElement(String name, BigInteger minOccurs, String maxOccurs, LocalComplexType type) {
TopLevelElement element = createTopLevelElement(name, minOccurs, maxOccurs);
element.setComplexType(type);
return element;
}
use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement 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;
}
use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement in project mule by mulesoft.
the class SourceSchemaDelegate method registerSourceElement.
private void registerSourceElement(SourceModel sourceModel, String typeName, DslElementSyntax dslSyntax) {
Element element = new TopLevelElement();
element.setName(dslSyntax.getElementName());
element.setType(new QName(builder.getSchema().getTargetNamespace(), typeName));
element.setAnnotation(builder.createDocAnnotation(sourceModel.getDescription()));
element.setSubstitutionGroup(getSourceSubstitutionGroup(sourceModel));
builder.getSchema().getSimpleTypeOrComplexTypeOrGroup().add(element);
}
Aggregations