use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel 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.api.meta.model.parameter.ParameterGroupModel 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);
});
}
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.
the class MetadataOperationTestCase method operationReceivesExclusiveOptionalParameterGroup.
@Test
public void operationReceivesExclusiveOptionalParameterGroup() throws Exception {
location = Location.builder().globalName("inputHasExclusiveOptionalParameterGroup").addProcessorsPart().addIndexPart(0).build();
MetadataResult<ComponentMetadataDescriptor<OperationModel>> operationMetadata = metadataService.getOperationMetadata(location);
ParameterGroupModel dessert = getParameterGroup(operationMetadata.get().getModel(), "dessert");
assertThat(dessert.getName(), is("dessert"));
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.
the class InjectedFieldsModelValidator method validate.
@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
final Set<Class<?>> validatedTypes = new HashSet<>();
// TODO - MULE-14401 - Make InjectedFieldsModelValidator work in AST Mode
Boolean isASTMode = !extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class).map(mp -> mp.getType().getDeclaringClass().isPresent()).orElse(false);
if (!isASTMode) {
extensionModel.getModelProperty(ClassLoaderModelProperty.class).ifPresent(classLoaderModelProperty -> {
new ExtensionWalker() {
@Override
protected void onSource(HasSourceModels owner, SourceModel model) {
validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
}
@Override
protected void onConfiguration(ConfigurationModel model) {
validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), RefName.class);
}
@Override
protected void onOperation(HasOperationModels owner, OperationModel model) {
validateArguments(model, model.getModelProperty(ExtensionOperationDescriptorModelProperty.class), DefaultEncoding.class);
}
@Override
protected void onConnectionProvider(HasConnectionProviderModels owner, ConnectionProviderModel model) {
validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), RefName.class);
}
@Override
protected void onParameter(ParameterizedModel owner, ParameterGroupModel groupModel, ParameterModel model) {
if (model.getType().getMetadataFormat().equals(JAVA)) {
model.getType().accept(new MetadataTypeVisitor() {
@Override
public void visitObject(ObjectType objectType) {
if (!objectType.getAnnotation(InfrastructureTypeAnnotation.class).isPresent()) {
try {
Class<?> type = getType(objectType, classLoaderModelProperty.getClassLoader());
if (validatedTypes.add(type)) {
validateType(model, type, DefaultEncoding.class);
}
} catch (Exception e) {
problemsReporter.addWarning(new Problem(model, "Could not validate Class: " + e.getMessage()));
}
}
}
});
}
}
private void validateArguments(NamedObject model, Optional<ExtensionOperationDescriptorModelProperty> modelProperty, Class<? extends Annotation> annotationClass) {
modelProperty.ifPresent(operationDescriptorModelProperty -> {
MethodElement operation = operationDescriptorModelProperty.getOperationMethod();
int size = operation.getParametersAnnotatedWith(annotationClass).size();
if (size == 0) {
return;
} else if (size > 1) {
problemsReporter.addError(new Problem(model, format("Operation method '%s' has %d arguments annotated with @%s. Only one argument may carry that annotation", operation.getName(), size, annotationClass.getSimpleName())));
}
ExtensionParameter argument = operation.getParametersAnnotatedWith(annotationClass).get(0);
if (!argument.getType().isSameType(String.class)) {
problemsReporter.addError(new Problem(model, format("Operation method '%s' declares an argument '%s' which is annotated with @%s and is of type '%s'. Only " + "arguments of type String are allowed to carry such annotation", operation.getName(), argument.getName(), annotationClass.getSimpleName(), argument.getType().getName())));
}
});
}
private void validateFields(NamedObject model, Optional<ImplementingTypeModelProperty> modelProperty, Class<? extends Annotation> annotationClass) {
modelProperty.ifPresent(implementingTypeModelProperty -> {
validateType(model, implementingTypeModelProperty.getType(), annotationClass);
});
}
private void validateType(NamedObject model, Class<?> type, Class<? extends Annotation> annotationClass) {
List<Field> fields = getAnnotatedFields(type, annotationClass);
if (fields.isEmpty()) {
return;
} else if (fields.size() > 1) {
problemsReporter.addError(new Problem(model, format("Class '%s' has %d fields annotated with @%s. Only one field may carry that annotation", type.getName(), fields.size(), annotationClass.getSimpleName())));
}
Field field = fields.get(0);
if (!String.class.equals(field.getType())) {
problemsReporter.addError(new Problem(model, format("Class '%s' declares the field '%s' which is annotated with @%s and is of type '%s'. Only " + "fields of type String are allowed to carry such annotation", type.getName(), field.getName(), annotationClass.getSimpleName(), field.getType().getName())));
}
}
}.walk(extensionModel);
});
}
}
use of org.mule.runtime.api.meta.model.parameter.ParameterGroupModel in project mule by mulesoft.
the class ParametersResolver method getParametersAsHashedResolverSet.
/**
* Constructs a {@link ResolverSet} from the parameters, using {@link #toValueResolver(Object, Set)} to process the values.
*
* @return a {@link ResolverSet}
*/
public ResolverSet getParametersAsHashedResolverSet(ParameterizedModel model, MuleContext muleContext) throws ConfigurationException {
List<ParameterGroupModel> inlineGroups = getInlineGroups(model.getParameterGroupModels());
ResolverSet resolverSet = getParametersAsHashedResolverSet(model, getFlatParameters(inlineGroups, model.getAllParameterModels()), muleContext);
for (ParameterGroupModel group : inlineGroups) {
getInlineGroupResolver(group, resolverSet, muleContext);
}
return resolverSet;
}
Aggregations