use of cn.taketoday.web.handler.method.NamedValueInfo in project today-framework by TAKETODAY.
the class AbstractNamedValueResolvingStrategy method resolveParameter.
@Nullable
@Override
public final Object resolveParameter(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
MethodParameter methodParameter = resolvable.getParameter();
NamedValueInfo namedValueInfo = resolvable.getNamedValueInfo();
MethodParameter nestedParameter = methodParameter.nestedIfOptional();
Object arg;
if (namedValueInfo.nameEmbedded) {
Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
if (resolvedName == null) {
throw new IllegalArgumentException("Specified name must not resolve to null: [" + namedValueInfo.name + "]");
}
arg = resolveName(resolvedName.toString(), resolvable, context);
} else {
arg = resolveName(namedValueInfo.name, resolvable, context);
}
if (arg == null) {
if (namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
} else if (namedValueInfo.required && !nestedParameter.isOptional()) {
handleMissingValue(namedValueInfo.name, nestedParameter, context);
}
arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());
} else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
}
if (configurableBeanFactory != null) {
ConversionService conversionService = configurableBeanFactory.getConversionService();
if (conversionService != null) {
try {
arg = conversionService.convert(arg, resolvable.getTypeDescriptor());
} catch (ConversionException e) {
throw new ParameterConversionException(methodParameter, arg, e);
}
// Check for null value after conversion of incoming argument value
if (arg == null && namedValueInfo.defaultValue == null && namedValueInfo.required && !nestedParameter.isOptional()) {
handleMissingValueAfterConversion(namedValueInfo.name, nestedParameter, context);
}
}
}
handleResolvedValue(arg, namedValueInfo.name, resolvable, context);
return arg;
}
use of cn.taketoday.web.handler.method.NamedValueInfo in project today-framework by TAKETODAY.
the class ExpressionValueMethodArgumentResolver method getNamedValueInfo.
@Override
protected NamedValueInfo getNamedValueInfo(ResolvableMethodParameter resolvable) {
if (resolvable.hasNamedValueInfo()) {
return resolvable.getNamedValueInfo();
}
Value annotation = resolvable.getParameterAnnotation(Value.class);
NamedValueInfo namedValueInfo = resolvable.getNamedValueInfo();
resolvable.withNamedValueInfo(new NamedValueInfo(namedValueInfo, annotation.value()));
return resolvable.getNamedValueInfo();
}
use of cn.taketoday.web.handler.method.NamedValueInfo in project today-framework by TAKETODAY.
the class AbstractNamedValueResolvingStrategy method resolveArgument.
@Nullable
@Override
public final Object resolveArgument(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
MethodParameter methodParameter = resolvable.getParameter();
NamedValueInfo namedValueInfo = getNamedValueInfo(resolvable);
MethodParameter nestedParameter = methodParameter.nestedIfOptional();
Object arg;
if (namedValueInfo.nameEmbedded) {
Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
if (resolvedName == null) {
throw new IllegalArgumentException("Specified name must not resolve to null: [" + namedValueInfo.name + "]");
}
arg = resolveName(resolvedName.toString(), resolvable, context);
} else {
arg = resolveName(namedValueInfo.name, resolvable, context);
}
if (arg == null) {
if (namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
} else if (namedValueInfo.required && !nestedParameter.isOptional()) {
handleMissingValue(namedValueInfo.name, nestedParameter, context);
}
arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());
} else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
}
BindingContext bindingContext = context.getBindingContext();
if (bindingContext != null) {
WebDataBinder binder = bindingContext.createBinder(context, namedValueInfo.name);
try {
arg = binder.convertIfNecessary(arg, methodParameter.getParameterType(), methodParameter);
} catch (ConversionNotSupportedException ex) {
throw new MethodArgumentConversionNotSupportedException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
} catch (TypeMismatchException ex) {
throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
}
// Check for null value after conversion of incoming argument value
if (arg == null && namedValueInfo.defaultValue == null && namedValueInfo.required && !nestedParameter.isOptional()) {
handleMissingValueAfterConversion(namedValueInfo.name, nestedParameter, context);
}
}
handleResolvedValue(arg, namedValueInfo.name, resolvable, context);
return arg;
}
use of cn.taketoday.web.handler.method.NamedValueInfo in project today-infrastructure by TAKETODAY.
the class ExpressionValueMethodArgumentResolver method getNamedValueInfo.
@Override
protected NamedValueInfo getNamedValueInfo(ResolvableMethodParameter resolvable) {
if (resolvable.hasNamedValueInfo()) {
return resolvable.getNamedValueInfo();
}
Value annotation = resolvable.getParameterAnnotation(Value.class);
NamedValueInfo namedValueInfo = resolvable.getNamedValueInfo();
resolvable.withNamedValueInfo(new NamedValueInfo(namedValueInfo, annotation.value()));
return resolvable.getNamedValueInfo();
}
use of cn.taketoday.web.handler.method.NamedValueInfo in project today-infrastructure by TAKETODAY.
the class AbstractNamedValueResolvingStrategy method resolveArgument.
@Nullable
@Override
public final Object resolveArgument(RequestContext context, ResolvableMethodParameter resolvable) throws Throwable {
MethodParameter methodParameter = resolvable.getParameter();
NamedValueInfo namedValueInfo = getNamedValueInfo(resolvable);
MethodParameter nestedParameter = methodParameter.nestedIfOptional();
Object arg;
if (namedValueInfo.nameEmbedded) {
Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
if (resolvedName == null) {
throw new IllegalArgumentException("Specified name must not resolve to null: [" + namedValueInfo.name + "]");
}
arg = resolveName(resolvedName.toString(), resolvable, context);
} else {
arg = resolveName(namedValueInfo.name, resolvable, context);
}
if (arg == null) {
if (namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
} else if (namedValueInfo.required && !nestedParameter.isOptional()) {
handleMissingValue(namedValueInfo.name, nestedParameter, context);
}
arg = handleNullValue(namedValueInfo.name, arg, nestedParameter.getNestedParameterType());
} else if ("".equals(arg) && namedValueInfo.defaultValue != null) {
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
}
BindingContext bindingContext = context.getBindingContext();
if (bindingContext != null) {
WebDataBinder binder = bindingContext.createBinder(context, namedValueInfo.name);
try {
arg = binder.convertIfNecessary(arg, methodParameter.getParameterType(), methodParameter);
} catch (ConversionNotSupportedException ex) {
throw new MethodArgumentConversionNotSupportedException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
} catch (TypeMismatchException ex) {
throw new MethodArgumentTypeMismatchException(arg, ex.getRequiredType(), namedValueInfo.name, methodParameter, ex.getCause());
}
// Check for null value after conversion of incoming argument value
if (arg == null && namedValueInfo.defaultValue == null && namedValueInfo.required && !nestedParameter.isOptional()) {
handleMissingValueAfterConversion(namedValueInfo.name, nestedParameter, context);
}
}
handleResolvedValue(arg, namedValueInfo.name, resolvable, context);
return arg;
}
Aggregations