use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ObjectTypeSchemaDelegate method getComplexTypeBase.
/**
* @return the {@link QName} of the {@code base} type for which the new {@link ComplexType} declares an {@code extension}
*/
private QName getComplexTypeBase(ObjectType type, ObjectType baseType) {
Optional<QName> customBaseQName = getBaseType(type).map(customDsl -> new QName(builder.getNamespaceUri(customDsl.getPrefix()), customDsl.getType(), customDsl.getPrefix()));
if (customBaseQName.isPresent()) {
// baseType was redefined by the user
return customBaseQName.get();
}
Optional<DslElementSyntax> baseDsl = builder.getDslResolver().resolve(baseType);
if (baseDsl.isPresent()) {
return new QName(baseDsl.get().getNamespace(), getBaseTypeName(baseType), baseDsl.get().getPrefix());
}
return MULE_ABSTRACT_EXTENSION_TYPE;
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax 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.extension.api.dsl.syntax.DslElementSyntax 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.extension.api.dsl.syntax.DslElementSyntax 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.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method createIdentifiedElement.
private DslElementModel createIdentifiedElement(ComponentConfiguration configuration) {
final ComponentIdentifier identifier = configuration.getIdentifier();
Optional<Map.Entry<ExtensionModel, DslSyntaxResolver>> entry = resolvers.entrySet().stream().filter(e -> e.getKey().getXmlDslModel().getPrefix().equals(identifier.getNamespace())).findFirst();
if (!entry.isPresent()) {
return null;
}
currentExtension = entry.get().getKey();
dsl = entry.get().getValue();
Reference<DslElementModel> elementModel = new Reference<>();
new ExtensionWalker() {
@Override
protected void onConfiguration(ConfigurationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
DslElementModel.Builder<ConfigurationModel> element = createElementModel(model, elementDsl, configuration);
addConnectionProvider(model, dsl, element, configuration);
elementModel.set(element.build());
stop();
}
});
}
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
getIdentifier(elementDsl).ifPresent(elementId -> {
if (elementId.equals(identifier)) {
elementModel.set(createElementModel(model, elementDsl, configuration).build());
stop();
}
});
}
}.walk(currentExtension);
if (elementModel.get() == null) {
resolveBasedOnTypes(configuration).ifPresent(elementModel::set);
}
return elementModel.get();
}
Aggregations