use of org.mule.runtime.module.extension.api.loader.java.type.FieldElement in project mule by mulesoft.
the class RouterModelLoaderDelegate method declareRoutes.
private void declareRoutes(ConstructDeclarer router, List<ExtensionParameter> routes) {
routes.forEach(route -> {
NestedRouteDeclarer routeDeclarer = router.withRoute(route.getAlias()).describedAs(route.getDescription()).withMinOccurs(route.isRequired() ? 1 : 0);
route.getType().getDeclaringClass().ifPresent(clazz -> routeDeclarer.withModelProperty(new ImplementingTypeModelProperty(clazz)));
final List<FieldElement> parameters = route.getType().getAnnotatedFields(Parameter.class);
loader.getFieldParametersLoader().declare(routeDeclarer, parameters, new ParameterDeclarationContext(CONSTRUCT, router.getDeclaration()));
});
}
use of org.mule.runtime.module.extension.api.loader.java.type.FieldElement in project mule by mulesoft.
the class ValueProvidersParameterDeclarationEnricher method enrichWithConfiguration.
/**
* Introspects the given {@link ParameterizableTypeWrapper parameterizableComponent} looking if this ones uses a
* {@link Config}, if this is true this method will indicate to the {@link ValueProviderFactoryModelPropertyBuilder}
* that the correspondent {@link ValueProvider} will require a config.
*
* @param modelPropertyBuilder Options Resolver Model Property Builder
* @param parameterizableComponent component to introspect
*/
private Optional<Field> enrichWithConfiguration(ValueProviderFactoryModelPropertyBuilder modelPropertyBuilder, ParameterizableTypeWrapper parameterizableComponent) {
List<FieldElement> configFields = parameterizableComponent.getAnnotatedFields(Config.class);
if (!configFields.isEmpty()) {
Field field = configFields.get(0).getField().get();
modelPropertyBuilder.withConfig(field);
return of(field);
}
return empty();
}
use of org.mule.runtime.module.extension.api.loader.java.type.FieldElement in project mule by mulesoft.
the class ValueProvidersParameterDeclarationEnricher method enrichWithConnection.
/**
* Introspects the given {@link ParameterizableTypeWrapper parameterizableComponent} looking if this ones uses a
* {@link Connection}, if this is true this method will indicate to the {@link ValueProviderFactoryModelPropertyBuilder}
* that the correspondent {@link ValueProvider} will require a connection.
*
* @param modelPropertyBuilder Options Resolver Model Property Builder
* @param parameterizableComponent component to introspect
*/
private Optional<Field> enrichWithConnection(ValueProviderFactoryModelPropertyBuilder modelPropertyBuilder, ParameterizableTypeWrapper parameterizableComponent) {
List<FieldElement> connectionFields = parameterizableComponent.getAnnotatedFields(Connection.class);
if (!connectionFields.isEmpty()) {
Field field = connectionFields.get(0).getField().get();
modelPropertyBuilder.withConnection(field);
return of(field);
}
return empty();
}
use of org.mule.runtime.module.extension.api.loader.java.type.FieldElement in project mule by mulesoft.
the class IntrospectionUtilsTestCase method getProperties.
@Test
public void getProperties() {
Set<Field> fields = IntrospectionUtils.getFieldsWithGetters(SomePojo.class, reflectionCache);
Type somePojo = typeSupplier.apply(SomePojo.class);
List<FieldElement> fieldsWithGetters = IntrospectionUtils.getFieldsWithGetters(somePojo);
assertThat(fieldsWithGetters.size(), is(fields.size()));
}
use of org.mule.runtime.module.extension.api.loader.java.type.FieldElement in project mule by mulesoft.
the class ParameterModelsLoaderDelegate method declaredAsGroup.
private List<ParameterDeclarer> declaredAsGroup(HasParametersDeclarer component, ParameterDeclarationContext declarationContext, ExtensionParameter groupParameter) throws IllegalParameterModelDefinitionException {
ParameterGroup groupAnnotation = groupParameter.getAnnotation(ParameterGroup.class).orElse(null);
if (groupAnnotation == null) {
return emptyList();
}
final String groupName = groupAnnotation.name();
if (DEFAULT_GROUP_NAME.equals(groupName)) {
throw new IllegalParameterModelDefinitionException(format("%s '%s' defines parameter group of name '%s' which is the default one. " + "@%s cannot be used with the default group name", getComponentDeclarationTypeName(((Declarer) component).getDeclaration()), ((NamedDeclaration) ((Declarer) component).getDeclaration()).getName(), groupName, ParameterGroup.class.getSimpleName()));
}
final Type type = groupParameter.getType();
final List<FieldElement> nestedGroups = type.getAnnotatedFields(ParameterGroup.class);
if (!nestedGroups.isEmpty()) {
throw new IllegalParameterModelDefinitionException(format("Class '%s' is used as a @%s but contains fields which also hold that annotation. Nesting groups is not allowed. " + "Offending fields are: [%s]", type.getName(), ParameterGroup.class.getSimpleName(), nestedGroups.stream().map(element -> element.getName()).collect(joining(","))));
}
if (groupParameter.isAnnotatedWith(org.mule.runtime.extension.api.annotation.param.Optional.class)) {
throw new IllegalParameterModelDefinitionException(format("@%s can not be applied alongside with @%s. Affected parameter is [%s].", org.mule.runtime.extension.api.annotation.param.Optional.class.getSimpleName(), ParameterGroup.class.getSimpleName(), groupParameter.getName()));
}
ParameterGroupDeclarer declarer = component.onParameterGroup(groupName);
if (declarer.getDeclaration().getModelProperty(ParameterGroupModelProperty.class).isPresent()) {
throw new IllegalParameterModelDefinitionException(format("Parameter group '%s' has already been declared on %s '%s'", groupName, getComponentDeclarationTypeName(((Declarer) component).getDeclaration()), ((NamedDeclaration) ((Declarer) component).getDeclaration()).getName()));
} else {
declarer.withModelProperty(new ParameterGroupModelProperty(new ParameterGroupDescriptor(groupName, type, groupParameter.getType().asMetadataType(), // TODO: Eliminate dependency to Annotated Elements
groupParameter.getDeclaringElement().orElse(null), groupParameter)));
}
final List<FieldElement> annotatedParameters = type.getAnnotatedFields(Parameter.class);
type.getAnnotation(ExclusiveOptionals.class).ifPresent(annotation -> {
Set<String> optionalParamNames = annotatedParameters.stream().filter(f -> !f.isRequired()).map(WithAlias::getAlias).collect(toSet());
declarer.withExclusiveOptionals(optionalParamNames, annotation.isOneRequired());
});
declarer.withDslInlineRepresentation(groupAnnotation.showInDsl());
groupParameter.getAnnotation(DisplayName.class).ifPresent(displayName -> declarer.withDisplayModel(DisplayModel.builder().displayName(displayName.value()).build()));
parseLayoutAnnotations(groupParameter, LayoutModel.builder()).ifPresent(declarer::withLayout);
declarer.withModelProperty(new ExtensionParameterDescriptorModelProperty(groupParameter));
if (!annotatedParameters.isEmpty()) {
return declare(component, annotatedParameters, declarationContext, declarer);
} else {
return declare(component, getFieldsWithGetters(type), declarationContext, declarer);
}
}
Aggregations