Search in sources :

Example 1 with TopLevelComplexType

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

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

the class ObjectTypeSchemaDelegate method registerPojoComplexType.

/**
 * Registers the {@link TopLevelComplexType} associated to the given {@link ObjectType} in the current namespace
 *
 * @param type the {@link ObjectType} that will be represented by the registered {@link ComplexType}
 * @param baseType the {@code base} for the {@link ComplexType} {@code extension} declaration
 * @param description
 * @return a new {@link ComplexType} declaration for the given {@link ObjectType}
 */
private ComplexType registerPojoComplexType(ObjectType type, ObjectType baseType, String description) {
    String typeId = getId(type);
    if (registeredComplexTypesHolders.get(typeId) != null) {
        return registeredComplexTypesHolders.get(typeId).getComplexType();
    }
    QName base = getComplexTypeBase(type, baseType);
    Collection<ObjectFieldType> fields;
    if (baseType == null) {
        fields = type.getFields();
    } else {
        fields = type.getFields().stream().filter(field -> !baseType.getFields().stream().anyMatch(other -> other.getKey().getName().getLocalPart().equals(field.getKey().getName().getLocalPart()))).collect(toList());
    }
    ComplexType complexType = declarePojoAsType(type, base, description, fields);
    builder.getSchema().getSimpleTypeOrComplexTypeOrGroup().add(complexType);
    return complexType;
}
Also used : QName(javax.xml.namespace.QName) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) ComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexType) TopLevelComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelComplexType) LocalComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType)

Example 3 with TopLevelComplexType

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

the class ExecutableTypeSchemaDelegate method createExecutableType.

protected ExtensionType createExecutableType(String name, QName base, DslElementSyntax dslSyntax, boolean hasImplicitConfig) {
    TopLevelComplexType complexType = new TopLevelComplexType();
    complexType.setName(name);
    ComplexContent complexContent = new ComplexContent();
    complexType.setComplexContent(complexContent);
    final ExtensionType complexContentExtension = new ExtensionType();
    complexContentExtension.setBase(base);
    complexContent.setExtension(complexContentExtension);
    if (dslSyntax.requiresConfig()) {
        Attribute configAttr = builder.createAttribute(CONFIG_ATTRIBUTE_NAME, CONFIG_ATTRIBUTE_DESCRIPTION, hasImplicitConfig, SUBSTITUTABLE_NAME);
        complexContentExtension.getAttributeOrAttributeGroup().add(configAttr);
    }
    this.builder.getSchema().getSimpleTypeOrComplexTypeOrGroup().add(complexType);
    return complexContentExtension;
}
Also used : TopLevelComplexType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelComplexType) Attribute(org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute) ExtensionType(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType) ComplexContent(org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexContent)

Aggregations

TopLevelComplexType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelComplexType)3 ComplexContent (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexContent)2 ExtensionType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExtensionType)2 LinkedList (java.util.LinkedList)1 QName (javax.xml.namespace.QName)1 ObjectFieldType (org.mule.metadata.api.model.ObjectFieldType)1 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)1 Attribute (org.mule.runtime.module.extension.internal.capability.xml.schema.model.Attribute)1 ComplexType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ComplexType)1 ExplicitGroup (org.mule.runtime.module.extension.internal.capability.xml.schema.model.ExplicitGroup)1 LocalComplexType (org.mule.runtime.module.extension.internal.capability.xml.schema.model.LocalComplexType)1 TopLevelElement (org.mule.runtime.module.extension.internal.capability.xml.schema.model.TopLevelElement)1