Search in sources :

Example 11 with TopLevelElement

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

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

the class SchemaBuilder method generateTextElement.

private TopLevelElement generateTextElement(DslElementSyntax paramDsl, String description, boolean isRequired) {
    TopLevelElement textElement = createTopLevelElement(paramDsl.getElementName(), isRequired ? ONE : ZERO, MAX_ONE);
    textElement.setAnnotation(createDocAnnotation(description));
    textElement.setType(STRING);
    return textElement;
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement)

Example 13 with TopLevelElement

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

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

the class SchemaBuilder method registerParameters.

List<TopLevelElement> registerParameters(ExtensionType type, Collection<ParameterModel> parameterModels) {
    List<TopLevelElement> all = new ArrayList<>(parameterModels.size());
    getSortedParameterModels(parameterModels).stream().filter(p -> !p.getModelProperty(QNameModelProperty.class).isPresent()).forEach(parameterModel -> {
        DslElementSyntax paramDsl = dslResolver.resolve(parameterModel);
        declareAsParameter(parameterModel.getType(), type, parameterModel, paramDsl, all);
    });
    return all;
}
Also used : InfrastructureParameterModelProperty(org.mule.runtime.extension.api.property.InfrastructureParameterModelProperty) SCHEDULING_STRATEGY_ELEMENT(org.mule.runtime.config.internal.dsl.SchemaConstants.SCHEDULING_STRATEGY_ELEMENT) CORE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.CORE_PREFIX) ENUM_TYPE_SUFFIX(org.mule.runtime.config.internal.dsl.SchemaConstants.ENUM_TYPE_SUFFIX) ImportedTypeModel(org.mule.runtime.api.meta.model.ImportedTypeModel) TLS_PARAMETER_NAME(org.mule.runtime.extension.api.ExtensionConstants.TLS_PARAMETER_NAME) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) ArrayType(org.mule.metadata.api.model.ArrayType) Union(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Union) BigInteger(java.math.BigInteger) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) StringUtils(org.mule.runtime.core.api.util.StringUtils) ParameterDslConfiguration(org.mule.runtime.api.meta.model.ParameterDslConfiguration) ExtensionModelUtils.isContent(org.mule.runtime.extension.api.util.ExtensionModelUtils.isContent) ExtensionMetadataTypeUtils.isMap(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.isMap) ObjectType(org.mule.metadata.api.model.ObjectType) ObjectStore(org.mule.runtime.api.store.ObjectStore) EE_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.EE_SCHEMA_LOCATION) SchemaConstants(org.mule.runtime.config.internal.dsl.SchemaConstants) Set(java.util.Set) OperationTransactionalAction(org.mule.runtime.extension.api.tx.OperationTransactionalAction) USE_OPTIONAL(org.mule.runtime.config.internal.dsl.SchemaConstants.USE_OPTIONAL) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) Attribute(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute) EnumAnnotation(org.mule.metadata.api.annotation.EnumAnnotation) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) StringType(org.mule.metadata.api.model.StringType) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType) USE_REQUIRED(org.mule.runtime.config.internal.dsl.SchemaConstants.USE_REQUIRED) ParameterModelComparator(org.mule.runtime.extension.api.util.ParameterModelComparator) SPRING_FRAMEWORK_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.SPRING_FRAMEWORK_SCHEMA_LOCATION) MetadataType(org.mule.metadata.api.model.MetadataType) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) Import(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Import) QName(javax.xml.namespace.QName) ZERO(java.math.BigInteger.ZERO) FormChoice(org.mule.runtime.module.extension.internal.capability.xml.schema.model.FormChoice) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) VALUE_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.VALUE_ATTRIBUTE_NAME) ObjectTypeSchemaDelegate.getAbstractElementName(org.mule.runtime.module.extension.internal.capability.xml.schema.builder.ObjectTypeSchemaDelegate.getAbstractElementName) CORE_NAMESPACE(org.mule.runtime.internal.dsl.DslConstants.CORE_NAMESPACE) TLS_CONTEXT_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.TLS_CONTEXT_TYPE) ArrayList(java.util.ArrayList) MULE_TLS_NAMESPACE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_TLS_NAMESPACE) SPRING_FRAMEWORK_NAMESPACE(org.mule.runtime.config.internal.dsl.SchemaConstants.SPRING_FRAMEWORK_NAMESPACE) MULE_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_SCHEMA_LOCATION) XML_NAMESPACE(org.mule.runtime.config.internal.dsl.SchemaConstants.XML_NAMESPACE) TopLevelSimpleType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelSimpleType) LinkedHashSet(java.util.LinkedHashSet) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ExplicitGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup) JAXBElement(javax.xml.bind.JAXBElement) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) TransactionType(org.mule.runtime.api.tx.TransactionType) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) STRING(org.mule.runtime.config.internal.dsl.SchemaConstants.STRING) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) Documentation(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Documentation) PRIVATE_OBJECT_STORE_ELEMENT(org.mule.runtime.config.internal.dsl.SchemaConstants.PRIVATE_OBJECT_STORE_ELEMENT) MULE_TLS_SCHEMA_LOCATION(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_TLS_SCHEMA_LOCATION) SubstitutionGroup(org.mule.runtime.extension.api.declaration.type.annotation.SubstitutionGroup) ExtensionMetadataTypeUtils.getId(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getId) ONE(java.math.BigInteger.ONE) MULE_TRANSACTION_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_TRANSACTION_TYPE) Restriction(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Restriction) QNameModelProperty(org.mule.runtime.extension.api.property.QNameModelProperty) MAX_ONE(org.mule.runtime.config.internal.dsl.SchemaConstants.MAX_ONE) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) Collections.singleton(java.util.Collections.singleton) ExtensionModelUtils.componentHasAnImplicitConfiguration(org.mule.runtime.extension.api.util.ExtensionModelUtils.componentHasAnImplicitConfiguration) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.SUPPORTED) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) Collection(java.util.Collection) String.format(java.lang.String.format) NAME_ATTRIBUTE_NAME(org.mule.runtime.internal.dsl.DslConstants.NAME_ATTRIBUTE_NAME) Objects(java.util.Objects) ExtensionMetadataTypeUtils.getSubstitutionGroup(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getSubstitutionGroup) List(java.util.List) NamedGroup(org.mule.runtime.module.extension.internal.capability.xml.schema.model.NamedGroup) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) Optional(java.util.Optional) EE_PREFIX(org.mule.runtime.internal.dsl.DslConstants.EE_PREFIX) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) EE_NAMESPACE(org.mule.runtime.internal.dsl.DslConstants.EE_NAMESPACE) Schema(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Schema) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ObjectFactory(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ObjectFactory) TypeCatalog(org.mule.runtime.api.meta.type.TypeCatalog) LOCAL(org.mule.runtime.api.tx.TransactionType.LOCAL) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) NoFixedFacet(org.mule.runtime.module.extension.internal.capability.xml.schema.model.NoFixedFacet) Comparator.comparing(java.util.Comparator.comparing) LocalSimpleType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalSimpleType) LinkedList(java.util.LinkedList) ExpressionSupport(org.mule.runtime.api.meta.ExpressionSupport) SchemaTypeConversion(org.mule.runtime.module.extension.internal.capability.xml.schema.model.SchemaTypeConversion) ExtensionModelUtils(org.mule.runtime.extension.api.util.ExtensionModelUtils) MULE_ABSTRACT_EXTENSION_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_ABSTRACT_EXTENSION_TYPE) ExtensionMetadataTypeUtils(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils) MULE_OPERATION_TRANSACTIONAL_ACTION_TYPE(org.mule.runtime.config.internal.dsl.SchemaConstants.MULE_OPERATION_TRANSACTIONAL_ACTION_TYPE) NameUtils.sanitizeName(org.mule.runtime.extension.api.util.NameUtils.sanitizeName) Annotation(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Annotation) TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) ArrayList(java.util.ArrayList)

Example 15 with TopLevelElement

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

the class SchemaBuilder method createRefElement.

TopLevelElement createRefElement(QName elementRef, boolean isRequired) {
    TopLevelElement element = new TopLevelElement();
    element.setRef(elementRef);
    element.setMinOccurs(isRequired ? ONE : ZERO);
    element.setMaxOccurs(MAX_ONE);
    return element;
}
Also used : TopLevelElement(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement)

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