Search in sources :

Example 26 with TopLevelElement

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);
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) QName(javax.xml.namespace.QName) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)

Example 27 with TopLevelElement

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;
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement)

Example 28 with TopLevelElement

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;
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement)

Example 29 with TopLevelElement

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;
}
Also used : ObjectType(org.mule.metadata.api.model.ObjectType) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MetadataType(org.mule.metadata.api.model.MetadataType) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 30 with TopLevelElement

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);
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) QName(javax.xml.namespace.QName) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) Element(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Element)

Aggregations

TopLevelElement (org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement)30 ExplicitGroup (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)11 QName (javax.xml.namespace.QName)10 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)10 LocalComplexType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType)10 ExtensionType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType)5 BigInteger (java.math.BigInteger)4 LinkedList (java.util.LinkedList)4 MetadataType (org.mule.metadata.api.model.MetadataType)4 Element (org.mule.runtime.module.extension.internal.capability.xml.schema.model.Element)4 Optional (java.util.Optional)3 ObjectType (org.mule.metadata.api.model.ObjectType)3 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)3 ComplexContent (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexContent)3 ArrayType (org.mule.metadata.api.model.ArrayType)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 String.format (java.lang.String.format)1 ONE (java.math.BigInteger.ONE)1 ZERO (java.math.BigInteger.ZERO)1