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