use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class ExtensionDefinitionParser method parseCollectionParameter.
/**
* Registers a definition for a {@link ParameterModel} which represents an {@link ArrayType}
*
* @param key the key that the parsed value should have on the parsed parameter's map
* @param name the parameter's name
* @param arrayType the parameter's {@link ArrayType}
* @param defaultValue the parameter's default value
* @param expressionSupport the parameter's {@link ExpressionSupport}
* @param required whether the parameter is required
*/
protected void parseCollectionParameter(String key, String name, ArrayType arrayType, Object defaultValue, ExpressionSupport expressionSupport, boolean required, DslElementSyntax parameterDsl, Set<ModelProperty> modelProperties) {
parseAttributeParameter(key, name, arrayType, defaultValue, expressionSupport, required, modelProperties);
Class<?> collectionType = ExtensionMetadataTypeUtils.getType(arrayType).orElse(null);
if (Set.class.equals(collectionType)) {
collectionType = HashSet.class;
} else if (Collection.class.equals(collectionType) || Iterable.class.equals(collectionType) || collectionType == null) {
collectionType = List.class;
}
final String collectionElementName = parameterDsl.getElementName();
addParameter(getChildKey(key), fromChildConfiguration(collectionType).withWrapperIdentifier(collectionElementName));
addDefinition(baseDefinitionBuilder.withIdentifier(collectionElementName).withTypeDefinition(fromType(collectionType)).build());
Optional<DslElementSyntax> collectionItemDsl = parameterDsl.getGeneric(arrayType.getType());
if (parameterDsl.supportsChildDeclaration() && collectionItemDsl.isPresent()) {
String itemIdentifier = collectionItemDsl.get().getElementName();
String itemNamespace = collectionItemDsl.get().getPrefix();
arrayType.getType().accept(new BasicTypeMetadataVisitor() {
private void addBasicTypeDefinition(MetadataType metadataType) {
Builder itemDefinitionBuilder = baseDefinitionBuilder.withIdentifier(itemIdentifier).withNamespace(itemNamespace).withTypeDefinition(fromType(ExtensionMetadataTypeUtils.getType(metadataType).orElse(Object.class))).withTypeConverter(value -> resolverOf(name, metadataType, value, getDefaultValue(metadataType).orElse(null), getExpressionSupport(metadataType), false, emptySet()));
addDefinition(itemDefinitionBuilder.build());
}
@Override
protected void visitBasicType(MetadataType metadataType) {
addBasicTypeDefinition(metadataType);
}
@Override
public void visitDate(DateType dateType) {
addBasicTypeDefinition(dateType);
}
@Override
public void visitDateTime(DateTimeType dateTimeType) {
addBasicTypeDefinition(dateTimeType);
}
@Override
public void visitObject(ObjectType objectType) {
if (isMap(objectType)) {
return;
}
DslElementSyntax itemDsl = collectionItemDsl.get();
if ((itemDsl.supportsTopLevelDeclaration() || itemDsl.supportsChildDeclaration()) && !parsingContext.isRegistered(itemDsl.getElementName(), itemDsl.getPrefix())) {
try {
parsingContext.registerObjectType(itemDsl.getElementName(), itemDsl.getPrefix(), objectType);
new ObjectTypeParameterParser(baseDefinitionBuilder, objectType, getContextClassLoader(), dslResolver, parsingContext).parse().forEach(definition -> addDefinition(definition));
} catch (ConfigurationException e) {
throw new MuleRuntimeException(createStaticMessage("Could not create parser for collection complex type"), e);
}
}
}
});
}
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class AnonymousInlineParameterGroupParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(name).withNamespace(namespace).asNamed().withTypeDefinition(fromType(Map.class)).withObjectFactoryType(AnonymousGroupObjectFactory.class).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withConstructorParameterDefinition(fromFixedValue(group).build());
this.parseParameters(group.getParameterModels());
return finalBuilder;
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class TypedInlineParameterGroupParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(name).withNamespace(namespace).asNamed().withTypeDefinition(fromType(ValueResolver.class)).withObjectFactoryType(InlineParameterGroupObjectFactory.class).withConstructorParameterDefinition(fromFixedValue(metadataType).build()).withConstructorParameterDefinition(fromFixedValue(classLoader).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build());
parseFields(metadataType, groupDsl, parametersRole);
return finalBuilder;
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class SourceDefinitionParser method doParse.
@Override
protected Builder doParse(Builder definitionBuilder) throws ConfigurationException {
Builder finalBuilder = definitionBuilder.withIdentifier(sourceDsl.getElementName()).withTypeDefinition(fromType(ExtensionMessageSource.class)).withObjectFactoryType(ExtensionSourceObjectFactory.class).withConstructorParameterDefinition(fromFixedValue(extensionModel).build()).withConstructorParameterDefinition(fromFixedValue(sourceModel).build()).withConstructorParameterDefinition(fromReferenceObject(MuleContext.class).build()).withSetterParameterDefinition("retryPolicyTemplate", fromChildConfiguration(RetryPolicyTemplate.class).build()).withSetterParameterDefinition("primaryNodeOnly", fromSimpleParameter(PRIMARY_NODE_ONLY_PARAMETER_NAME).build()).withSetterParameterDefinition(CONFIG_PROVIDER_ATTRIBUTE_NAME, fromSimpleReferenceParameter(CONFIG_ATTRIBUTE_NAME).build()).withSetterParameterDefinition(CURSOR_PROVIDER_FACTORY_FIELD_NAME, fromChildConfiguration(CursorProviderFactory.class).build()).withSetterParameterDefinition("backPressureStrategy", fromSimpleParameter(BACK_PRESSURE_STRATEGY_PARAMETER_NAME, v -> toBackPressureStrategy((String) v)).build());
List<ParameterGroupModel> inlineGroups = getInlineGroups(sourceModel);
sourceModel.getErrorCallback().ifPresent(cb -> inlineGroups.addAll(getInlineGroups(cb)));
sourceModel.getSuccessCallback().ifPresent(cb -> inlineGroups.addAll(getInlineGroups(cb)));
parseParameters(getFlatParameters(inlineGroups, sourceModel.getAllParameterModels()));
for (ParameterGroupModel group : inlineGroups) {
parseInlineParameterGroup(group);
}
return finalBuilder;
}
use of org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder in project mule by mulesoft.
the class DefaultExtensionBuildingDefinitionProvider method registerExtensionParsers.
private void registerExtensionParsers(ExtensionModel extensionModel) {
XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
final ExtensionParsingContext parsingContext = createParsingContext(extensionModel);
final Builder definitionBuilder = new Builder().withNamespace(xmlDslModel.getPrefix());
final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, DslResolvingContext.getDefault(extensions));
if (extensionModel.getModelProperty(CustomBuildingDefinitionProviderModelProperty.class).isPresent()) {
return;
}
if (extensionModel.getModelProperty(XmlExtensionModelProperty.class).isPresent()) {
registerXmlExtensionParsers(definitionBuilder, extensionModel, dslSyntaxResolver);
} else {
final ClassLoader extensionClassLoader = getClassLoader(extensionModel);
withContextClassLoader(extensionClassLoader, () -> {
ReflectionCache reflectionCache = new ReflectionCache();
new IdempotentExtensionWalker() {
@Override
public void onConfiguration(ConfigurationModel model) {
parseWith(new ConfigurationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
protected void onConstruct(ConstructModel model) {
parseWith(new ConstructDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
public void onOperation(OperationModel model) {
parseWith(new OperationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
public void onConnectionProvider(ConnectionProviderModel model) {
parseWith(new ConnectionProviderDefinitionParser(definitionBuilder, model, extensionModel, dslSyntaxResolver, parsingContext));
}
@Override
public void onSource(SourceModel model) {
parseWith(new SourceDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
}
@Override
protected void onParameter(ParameterGroupModel groupModel, ParameterModel model) {
registerTopLevelParameter(model.getType(), definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
}
}.walk(extensionModel);
registerExportedTypesTopLevelParsers(extensionModel, definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
registerSubTypes(definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
});
}
}
Aggregations