Example usage for org.springframework.web.method.support CompositeUriComponentsContributor contributeMethodArgument

List of usage examples for org.springframework.web.method.support CompositeUriComponentsContributor contributeMethodArgument

Introduction

In this page you can find the example usage for org.springframework.web.method.support CompositeUriComponentsContributor contributeMethodArgument.

Prototype

public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder,
        Map<String, Object> uriVariables) 

Source Link

Document

An overloaded method that uses the ConversionService created at construction.

Usage

From source file:org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.java

private static UriComponents applyContributors(UriComponentsBuilder builder, Method method, Object... args) {
    CompositeUriComponentsContributor contributor = getConfiguredUriComponentsContributor();
    if (contributor == null) {
        logger.debug("Using default CompositeUriComponentsContributor");
        contributor = defaultUriComponentsContributor;
    }/*from  w w w  .j  a v  a 2 s  . co m*/

    int paramCount = method.getParameterCount();
    int argCount = args.length;
    if (paramCount != argCount) {
        throw new IllegalArgumentException("Number of method parameters " + paramCount
                + " does not match number of argument values " + argCount);
    }

    final Map<String, Object> uriVars = new HashMap<>();
    for (int i = 0; i < paramCount; i++) {
        MethodParameter param = new SynthesizingMethodParameter(method, i);
        param.initParameterNameDiscovery(parameterNameDiscoverer);
        contributor.contributeMethodArgument(param, args[i], builder, uriVars);
    }

    // We may not have all URI var values, expand only what we have
    return builder.build().expand(new UriComponents.UriTemplateVariables() {
        @Override
        public Object getValue(@Nullable String name) {
            return uriVars.containsKey(name) ? uriVars.get(name)
                    : UriComponents.UriTemplateVariables.SKIP_VALUE;
        }
    });
}