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;
}
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;
}
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;
}
Aggregations