Search in sources :

Example 11 with ExplicitGroup

use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup in project mule by mulesoft.

the class MapSchemaDelegate method generateMapComplexType.

private LocalComplexType generateMapComplexType(DslElementSyntax mapDsl, final ObjectType metadataType) {
    final MetadataType valueType = metadataType.getOpenRestriction().get();
    final LocalComplexType entryComplexType = new LocalComplexType();
    final Attribute keyAttribute = builder.createAttribute(KEY_ATTRIBUTE_NAME, keyType, true, REQUIRED);
    entryComplexType.getAttributeOrAttributeGroup().add(keyAttribute);
    final LocalComplexType mapComplexType = new LocalComplexType();
    final ExplicitGroup mapEntrySequence = new ExplicitGroup();
    mapComplexType.setSequence(mapEntrySequence);
    DslElementSyntax entryValueDsl = mapDsl.getGeneric(valueType).orElseThrow(() -> new IllegalArgumentException("Illegal DslSyntax definition of the given DictionaryType. The DslElementSyntax for the entry is required"));
    final TopLevelElement mapEntryElement = new TopLevelElement();
    mapEntryElement.setName(entryValueDsl.getElementName());
    mapEntryElement.setMinOccurs(ZERO);
    mapEntryElement.setMaxOccurs(UNBOUNDED);
    valueType.accept(new MetadataTypeVisitor() {

        /**
         * For a Map with an {@link ObjectType} as value. The resulting {@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 map's value is another map, then a value attribute is created for the value map.
         *
         * @param objectType the item's type
         */
        @Override
        public void visitObject(ObjectType objectType) {
            Optional<DslElementSyntax> containedElement = entryValueDsl.getContainedElement(VALUE_ATTRIBUTE_NAME);
            if (isMap(objectType) || !containedElement.isPresent()) {
                defaultVisit(objectType);
                return;
            }
            final boolean shouldGenerateChildElement = containedElement.get().supportsChildDeclaration() || containedElement.get().isWrapped();
            entryComplexType.getAttributeOrAttributeGroup().add(builder.createAttribute(VALUE_ATTRIBUTE_NAME, valueType, !shouldGenerateChildElement, SUPPORTED));
            if (shouldGenerateChildElement) {
                DslElementSyntax typeDsl = builder.getDslResolver().resolve(objectType).orElseThrow(() -> new IllegalArgumentException(format("The given type [%s] cannot be represented as a child element in Map entries", getId(objectType))));
                if (typeDsl.isWrapped()) {
                    ExplicitGroup choice = builder.createTypeRefChoiceLocalOrGlobal(typeDsl, objectType, ZERO, UNBOUNDED);
                    entryComplexType.setChoice(choice);
                } else {
                    ExplicitGroup singleItemSequence = new ExplicitGroup();
                    singleItemSequence.setMaxOccurs("1");
                    TopLevelElement mapItemElement = builder.createTypeRef(typeDsl, objectType, false);
                    singleItemSequence.getParticle().add(objectFactory.createElement(mapItemElement));
                    entryComplexType.setSequence(singleItemSequence);
                }
            }
        }

        @Override
        public void visitArrayType(ArrayType arrayType) {
            entryComplexType.getAttributeOrAttributeGroup().add(builder.createAttribute(VALUE_ATTRIBUTE_NAME, valueType, false, SUPPORTED));
            entryComplexType.setSequence(new ExplicitGroup());
            LocalComplexType itemComplexType = new LocalComplexType();
            MetadataType itemType = arrayType.getType();
            itemComplexType.getAttributeOrAttributeGroup().add(builder.createAttribute(VALUE_ATTRIBUTE_NAME, itemType, true, REQUIRED));
            DslElementSyntax itemDsl = entryValueDsl.getGeneric(itemType).orElseThrow(() -> new IllegalArgumentException("Illegal DslSyntax definition of the given ArrayType. The DslElementSyntax for the item is required"));
            TopLevelElement itemElement = builder.createTopLevelElement(itemDsl.getElementName(), ZERO, UNBOUNDED, itemComplexType);
            entryComplexType.getSequence().getParticle().add(objectFactory.createElement(itemElement));
        }

        @Override
        protected void defaultVisit(MetadataType metadataType) {
            entryComplexType.getAttributeOrAttributeGroup().add(builder.createValueAttribute(valueType));
        }
    });
    mapEntryElement.setComplexType(entryComplexType);
    mapEntrySequence.getParticle().add(objectFactory.createElement(mapEntryElement));
    return mapComplexType;
}
Also used : ArrayType(org.mule.metadata.api.model.ArrayType) ObjectType(org.mule.metadata.api.model.ObjectType) Optional(java.util.Optional) Attribute(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute) 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 12 with ExplicitGroup

use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup in project mule by mulesoft.

the class ObjectTypeSchemaDelegate method addImportedTypeElement.

private void addImportedTypeElement(DslElementSyntax paramDsl, String description, MetadataType metadataType, List<TopLevelElement> all, boolean required) {
    DslElementSyntax typeDsl = builder.getDslResolver().resolve(metadataType).orElseThrow(() -> new IllegalArgumentException(format("The given type [%s] is not eligible for Import", getId(metadataType))));
    if (paramDsl.isWrapped()) {
        TopLevelElement objectElement = builder.createTopLevelElement(paramDsl.getElementName(), ZERO, MAX_ONE);
        objectElement.setComplexType(new LocalComplexType());
        objectElement.setAnnotation(builder.createDocAnnotation(description));
        if (typeDsl.isWrapped()) {
            objectElement.getComplexType().setChoice(builder.createTypeRefChoiceLocalOrGlobal(typeDsl, metadataType, ZERO, UNBOUNDED));
        } else {
            ExplicitGroup sequence = new ExplicitGroup();
            sequence.setMinOccurs(ONE);
            sequence.setMaxOccurs(MAX_ONE);
            QName refQName = new QName(paramDsl.getNamespace(), getAbstractElementName(typeDsl), paramDsl.getPrefix());
            sequence.getParticle().add(objectFactory.createElement(builder.createRefElement(refQName, false)));
            objectElement.getComplexType().setSequence(sequence);
        }
        all.add(objectElement);
    } else {
        QName extensionBase = new QName(typeDsl.getNamespace(), sanitizeName(getId(metadataType)), typeDsl.getPrefix());
        addChildElementTypeExtension(extensionBase, description, paramDsl.getElementName(), !paramDsl.supportsAttributeDeclaration() && required, all);
    }
}
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) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 13 with ExplicitGroup

use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup 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 14 with ExplicitGroup

use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup in project mule by mulesoft.

the class SourceSchemaDelegate method registerSourceType.

private void registerSourceType(String name, SourceModel sourceModel, DslElementSyntax dslSyntax, boolean hasImplicitConfig) {
    final ExtensionType sourceType = createExecutableType(name, MULE_ABSTRACT_MESSAGE_SOURCE_TYPE, dslSyntax, hasImplicitConfig);
    initialiseSequence(sourceType);
    ExplicitGroup sequence = sourceType.getSequence();
    builder.addInfrastructureParameters(sourceType, sourceModel, sequence);
    List<ParameterModel> visitedParameters = new LinkedList<>();
    sourceModel.getParameterGroupModels().forEach(group -> {
        registerParameterGroup(sourceType, group);
        visitedParameters.addAll(group.getParameterModels());
    });
    sourceModel.getSuccessCallback().map(ParameterizedModel::getParameterGroupModels).ifPresent(groups -> groups.forEach(group -> registerCallbackParameters(sourceType, visitedParameters, group)));
    sourceModel.getErrorCallback().map(ParameterizedModel::getParameterGroupModels).ifPresent(groups -> groups.forEach(group -> registerCallbackParameters(sourceType, visitedParameters, group)));
}
Also used : TYPE_SUFFIX(org.mule.runtime.config.internal.dsl.SchemaConstants.TYPE_SUFFIX) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) StringUtils.capitalize(org.apache.commons.lang3.StringUtils.capitalize) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) Element(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Element) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) MULE_ABSTRACT_MESSAGE_SOURCE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_ABSTRACT_MESSAGE_SOURCE) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) MULE_ABSTRACT_MESSAGE_SOURCE_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_ABSTRACT_MESSAGE_SOURCE_TYPE) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) SOURCE(org.mule.runtime.extension.api.stereotype.MuleStereotypes.SOURCE) QName(javax.xml.namespace.QName) LinkedList(java.util.LinkedList) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) LinkedList(java.util.LinkedList) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Aggregations

ExplicitGroup (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)14 TopLevelElement (org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement)11 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)8 LocalComplexType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType)7 ExtensionType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType)5 LinkedList (java.util.LinkedList)3 QName (javax.xml.namespace.QName)3 Optional (java.util.Optional)2 MetadataType (org.mule.metadata.api.model.MetadataType)2 ObjectType (org.mule.metadata.api.model.ObjectType)2 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)2 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)2 ComplexContent (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexContent)2 Element (org.mule.runtime.module.extension.internal.capability.xml.schema.model.Element)2 BigInteger (java.math.BigInteger)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 StringUtils.capitalize (org.apache.commons.lang3.StringUtils.capitalize)1 ArrayType (org.mule.metadata.api.model.ArrayType)1 NestedChainModel (org.mule.runtime.api.meta.model.nested.NestedChainModel)1