Search in sources :

Example 1 with ExplicitGroup

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

the class ConfigurationSchemaDelegate method registerConfigElement.

void registerConfigElement(Schema schema, final ConfigurationModel configurationModel, DslElementSyntax dslConfigElement) {
    this.schema = schema;
    ExtensionType config = registerExtension(dslConfigElement.getElementName());
    config.getAttributeOrAttributeGroup().add(builder.createNameAttribute(true));
    config.setAnnotation(builder.createDocAnnotation(configurationModel.getDescription()));
    Optional<TopLevelElement> connectionElement = addConnectionProviderElement(configurationModel);
    if (connectionElement.isPresent() || !configurationModel.getParameterGroupModels().isEmpty()) {
        final ExplicitGroup sequence = new ExplicitGroup();
        sequence.setMinOccurs(ZERO);
        sequence.setMaxOccurs(MAX_ONE);
        connectionElement.ifPresent(connection -> {
            sequence.getParticle().add(objectFactory.createElement(connection));
            if (builder.isRequired(connection)) {
                sequence.setMinOccurs(ONE);
            }
        });
        builder.addInfrastructureParameters(config, configurationModel, sequence);
        configurationModel.getParameterGroupModels().forEach(group -> {
            if (!group.isShowInDsl()) {
                List<TopLevelElement> parameters = builder.registerParameters(config, group.getParameterModels());
                builder.addParameterToSequence(parameters, sequence);
            } else {
                builder.addInlineParameterGroup(group, sequence);
            }
        });
        config.setSequence(sequence);
    }
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 2 with ExplicitGroup

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

the class ConnectionProviderSchemaDelegate method registerConnectionProviderElement.

void registerConnectionProviderElement(ConnectionProviderModel providerModel, DslElementSyntax elementSyntax) {
    Element providerElement = new TopLevelElement();
    providerElement.setName(elementSyntax.getElementName());
    providerElement.setSubstitutionGroup(MULE_CONNECTION_PROVIDER_ELEMENT);
    LocalComplexType complexType = new LocalComplexType();
    providerElement.setComplexType(complexType);
    ExtensionType providerType = new ExtensionType();
    providerType.setBase(MULE_CONNECTION_PROVIDER_TYPE);
    ComplexContent complexContent = new ComplexContent();
    complexContent.setExtension(providerType);
    complexType.setComplexContent(complexContent);
    builder.getSchema().getSimpleTypeOrComplexTypeOrGroup().add(providerElement);
    final ExplicitGroup sequence = new ExplicitGroup();
    sequence.setMinOccurs(ZERO);
    sequence.setMaxOccurs(MAX_ONE);
    builder.addInfrastructureParameters(providerType, providerModel, sequence);
    providerModel.getParameterGroupModels().forEach(group -> {
        if (!group.isShowInDsl()) {
            builder.addParameterToSequence(builder.registerParameters(providerType, group.getParameterModels()), sequence);
        } else {
            builder.addInlineParameterGroup(group, sequence);
        }
    });
    providerType.setSequence(sequence);
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) Element(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Element) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) ComplexContent(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexContent) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 3 with ExplicitGroup

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

the class ExecutableTypeSchemaDelegate method initialiseSequence.

protected void initialiseSequence(ExtensionType type) {
    if (type.getSequence() == null) {
        ExplicitGroup sequence = new ExplicitGroup();
        sequence.setMinOccurs(ZERO);
        sequence.setMaxOccurs(MAX_ONE);
        type.setSequence(sequence);
    }
}
Also used : ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 4 with ExplicitGroup

use of org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup 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;
}
Also used : TopLevelComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelComplexType) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) ComplexContent(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexContent) LinkedList(java.util.LinkedList) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 5 with ExplicitGroup

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

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