use of org.mule.runtime.module.extension.internal.runtime.resolver.HashedResolverSet in project mule by mulesoft.
the class ImplicitObjectUtils method buildImplicitResolverSet.
/**
* Creates a {@link ResolverSet} based on the default values for the {@link ParameterModel}s in the {@code parametrizedModel}.
* <p>
* If a {@link ParameterModel} returns {@code null} for {@link ParameterModel#getDefaultValue()} then it's ignored
*
* @param model a model holding the {@link ParameterModel}s to consider
* @param muleContext the Mule node.
* @return a {@link ResolverSet}
*/
public static ResolverSet buildImplicitResolverSet(ParameterizedModel model, ReflectionCache reflectionCache, MuleContext muleContext) {
ResolverSet resolverSet = new HashedResolverSet(muleContext);
ParametersResolver parametersResolver = ParametersResolver.fromDefaultValues(model, muleContext, reflectionCache);
for (ParameterGroupModel groupModel : model.getParameterGroupModels()) {
Optional<ParameterGroupDescriptor> descriptor = groupModel.getModelProperty(ParameterGroupModelProperty.class).map(ParameterGroupModelProperty::getDescriptor);
if (descriptor.isPresent() && groupModel.getParameterModels().stream().noneMatch(ParameterModel::isRequired)) {
String groupKey = getContainerName(descriptor.get().getContainer());
resolverSet.add(groupKey, NullSafeValueResolverWrapper.of(new StaticValueResolver<>(null), descriptor.get().getMetadataType(), reflectionCache, muleContext, parametersResolver));
} else {
groupModel.getParameterModels().forEach(parameterModel -> {
Object defaultValue = parameterModel.getDefaultValue();
ValueResolver<?> resolver;
if (defaultValue instanceof String) {
resolver = getExpressionBasedValueResolver((String) defaultValue, parameterModel.getType(), muleContext);
} else {
resolver = new StaticValueResolver<>(null);
}
if (parameterModel.getModelProperty(NullSafeModelProperty.class).isPresent()) {
MetadataType metadataType = parameterModel.getModelProperty(NullSafeModelProperty.class).get().defaultType();
resolver = NullSafeValueResolverWrapper.of(resolver, metadataType, reflectionCache, muleContext, parametersResolver);
}
resolverSet.add(parameterModel.getName(), resolver);
});
}
}
return resolverSet;
}
Aggregations