Search in sources :

Example 6 with ExplicitGroup

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

the class OperationSchemaDelegate method registerOperationType.

ExtensionType registerOperationType(String name, ComponentModel operationModel, DslElementSyntax dslSyntax, boolean hasImplicitConfig) {
    ExtensionType componentType = createExecutableType(name, MULE_ABSTRACT_OPERATOR_TYPE, dslSyntax, hasImplicitConfig);
    initialiseSequence(componentType);
    ExplicitGroup sequence = componentType.getSequence();
    builder.addInfrastructureParameters(componentType, operationModel, sequence);
    operationModel.getParameterGroupModels().forEach(group -> registerParameterGroup(componentType, group));
    return componentType;
}
Also used : 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 7 with ExplicitGroup

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

the class SchemaBuilder method addInlineParameterGroup.

void addInlineParameterGroup(ParameterGroupModel group, ExplicitGroup parentSequence) {
    DslElementSyntax groupDsl = dslResolver.resolveInline(group);
    LocalComplexType complexType = objectTypeDelegate.createTypeExtension(MULE_ABSTRACT_EXTENSION_TYPE);
    ExplicitGroup groupSequence = new ExplicitGroup();
    List<ParameterModel> groupParameters = group.getParameterModels();
    List<TopLevelElement> parameterElements = registerParameters(complexType.getComplexContent().getExtension(), groupParameters);
    addParameterToSequence(parameterElements, groupSequence);
    BigInteger minOccurs = ExtensionModelUtils.isRequired(group) ? ONE : ZERO;
    TopLevelElement groupElement = createTopLevelElement(groupDsl.getElementName(), minOccurs, MAX_ONE);
    groupElement.setComplexType(complexType);
    complexType.getComplexContent().getExtension().setSequence(groupSequence);
    parentSequence.getParticle().add(objectFactory.createElement(groupElement));
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) BigInteger(java.math.BigInteger) 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 8 with ExplicitGroup

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

the class SchemaBuilder method createTypeRefChoiceLocalOrGlobal.

/**
 * Creates a {@link ExplicitGroup Choice} group that supports {@code refs} to both the {@code global} and {@code local} abstract
 * elements for the given {@code type}. This is required in order to allow subtypes that support top-level declaration along
 * with other subtypes that support only local declarations as childs.
 * <p/>
 * For example, a resulting choice group for a type of name {@code TypeName} will look like:
 * <p>
 * <xs:complexType> <xs:choice minOccurs="1" maxOccurs="1">
 * <xs:element minOccurs="0" maxOccurs="1" ref="ns:abstract-type-name"></xs:element>
 * <xs:element minOccurs="0" maxOccurs="1" ref="ns:global-abstract-type-name"></xs:element> </xs:choice> </xs:complexType>
 * <p/>
 *
 * @param typeDsl {@link DslElementSyntax} of the referenced type
 * @param type the {@link MetadataType type} of the base element that will be referenced
 * @param minOccurs {@link BigInteger#ZERO} if the {@code group} is optional or {@link BigInteger#ONE} if required
 * @param maxOccurs the maximum number of occurrences for this group
 * @return a {@link ExplicitGroup Choice} group with the necessary options for this case
 */
ExplicitGroup createTypeRefChoiceLocalOrGlobal(DslElementSyntax typeDsl, MetadataType type, BigInteger minOccurs, String maxOccurs) {
    if (!isImported(type) && !OBJECT_STORE_TYPE.equals(type)) {
        objectTypeDelegate.registerPojoType(type, EMPTY);
        objectTypeDelegate.registerAbstractElement(type, typeDsl);
        if (typeDsl.supportsTopLevelDeclaration() || (typeDsl.supportsChildDeclaration() && typeDsl.isWrapped())) {
            objectTypeDelegate.registerConcreteGlobalElement(typeDsl, EMPTY, getAbstractElementName(typeDsl), objectTypeDelegate.getTypeQName(typeDsl, type));
        }
    }
    final ExplicitGroup choice = new ExplicitGroup();
    choice.setMinOccurs(minOccurs);
    choice.setMaxOccurs(maxOccurs);
    List<String> options = new LinkedList<>();
    if (type.equals(OBJECT_STORE_TYPE)) {
        QName refInternal = PRIVATE_OBJECT_STORE_ELEMENT;
        TopLevelElement internalAbstractElementRef = createRefElement(refInternal, true);
        choice.getParticle().add(objectFactory.createElement(internalAbstractElementRef));
        options.add(refInternal.toString());
    } else {
        QName refAbstract = new QName(typeDsl.getNamespace(), getAbstractElementName(typeDsl), typeDsl.getPrefix());
        TopLevelElement localAbstractElementRef = createRefElement(refAbstract, true);
        choice.getParticle().add(objectFactory.createElement(localAbstractElementRef));
        options.add(refAbstract.toString());
        QName refGlobal = new QName(typeDsl.getNamespace(), format(GLOBAL_ABSTRACT_ELEMENT_MASK, getAbstractElementName(typeDsl)), typeDsl.getPrefix());
        TopLevelElement topLevelElementRef = createRefElement(refGlobal, true);
        choice.getParticle().add(objectFactory.createElement(topLevelElementRef));
        options.add(refGlobal.toString());
    }
    typesMapping.getSubTypes((ObjectType) type).stream().filter(subtype -> dslResolver.resolve(subtype).map(DslElementSyntax::supportsChildDeclaration).orElse(false)).map(ExtensionMetadataTypeUtils::getSubstitutionGroup).filter(Optional::isPresent).map(Optional::get).forEach(customGroup -> {
        QName qName = resolveSubstitutionGroup(customGroup);
        if (!options.contains(qName.toString())) {
            TopLevelElement customGroupRef = createRefElement(qName, true);
            choice.getParticle().add(objectFactory.createElement(customGroupRef));
            options.add(customGroupRef.toString());
        }
    });
    return choice;
}
Also used : Optional(java.util.Optional) 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) LinkedList(java.util.LinkedList) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 9 with ExplicitGroup

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

the class ExecutableTypeSchemaDelegate method generateNestedProcessorElement.

private void generateNestedProcessorElement(ExtensionType type, NestedChainModel chainModel) {
    final ExplicitGroup choice = new ExplicitGroup();
    choice.setMinOccurs(chainModel.isRequired() ? ONE : ZERO);
    choice.setMaxOccurs(UNBOUNDED);
    chainModel.getAllowedStereotypes().forEach(stereotype -> {
        // We need this to support both message-processor and mixed-content-message-processor
        if (stereotype.equals(PROCESSOR)) {
            NamedGroup group = builder.createGroup(MULE_MESSAGE_PROCESSOR_TYPE, true);
            choice.getParticle().add(objectFactory.createGroup(group));
        } else {
            TopLevelElement localAbstractElementRef = builder.createRefElement(getSubstitutionGroup(stereotype), true);
            choice.getParticle().add(objectFactory.createElement(localAbstractElementRef));
        }
    });
    type.getSequence().getParticle().add(objectFactory.createChoice(choice));
    if (chainModel.isRequired()) {
        type.getSequence().setMinOccurs(ONE);
    }
}
Also used : NamedGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.NamedGroup) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)

Example 10 with ExplicitGroup

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

the class ExecutableTypeSchemaDelegate method generateNestedRouteElement.

private void generateNestedRouteElement(ExtensionType type, DslElementSyntax routeDsl, NestedRouteModel routeModel) {
    NestedChainModel chain = (NestedChainModel) routeModel.getNestedComponents().get(0);
    LocalComplexType complexType = builder.getObjectSchemaDelegate().createTypeExtension(MULE_ABSTRACT_EXTENSION_TYPE);
    ExplicitGroup routeSequence = new ExplicitGroup();
    complexType.getComplexContent().getExtension().setSequence(routeSequence);
    generateNestedProcessorElement(complexType.getComplexContent().getExtension(), chain);
    registerParameters(complexType.getComplexContent().getExtension(), routeModel.getAllParameterModels());
    TopLevelElement routeElement = builder.createTopLevelElement(routeDsl.getElementName(), BigInteger.valueOf(routeModel.getMinOccurs()), MAX_ONE);
    routeElement.setComplexType(complexType);
    type.getSequence().getParticle().add(objectFactory.createElement(routeElement));
    if (routeModel.getMinOccurs() > 0) {
        type.getSequence().setMinOccurs(ONE);
    }
}
Also used : NestedChainModel(org.mule.runtime.api.meta.model.nested.NestedChainModel) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) 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