Java 类org.springframework.web.bind.annotation.ValueConstants 实例源码

项目:FastBootWeixin    文件:WxApiParamContributor.java   
@Override
public void contributeMethodArgument(MethodParameter parameter, Object value, UriComponentsBuilder builder, Map<String, Object> uriVariables, ConversionService conversionService) {
    Class<?> paramType = parameter.getNestedParameterType();
    if (Map.class.isAssignableFrom(paramType)) {
        return;
    }
    WxApiParam wxApiParam = parameter.getParameterAnnotation(WxApiParam.class);
    String name = (wxApiParam == null || StringUtils.isEmpty(wxApiParam.name()) ? parameter.getParameterName() : wxApiParam.name());
    WxAppAssert.notNull(name, "请添加编译器的-parameter或者为参数添加注解名称");
    if (value == null) {
        if (wxApiParam != null) {
            if (!wxApiParam.required() || !wxApiParam.defaultValue().equals(ValueConstants.DEFAULT_NONE)) {
                return;
            }
        }
        builder.queryParam(name);
    } else if (value instanceof Collection) {
        for (Object element : (Collection<?>) value) {
            element = formatUriValue(conversionService, TypeDescriptor.nested(parameter, 1), element);
            builder.queryParam(name, element);
        }
    } else {
        builder.queryParam(name, formatUriValue(conversionService, new TypeDescriptor(parameter), value));
    }
}
项目:lams    文件:AbstractNamedValueMethodArgumentResolver.java   
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
    String name = info.name;
    if (info.name.length() == 0) {
        name = parameter.getParameterName();
        Assert.notNull(name, "Name for argument type [" + parameter.getParameterType().getName()
                    + "] not available, and parameter name information not found in class file either.");
    }
    String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
    return new NamedValueInfo(name, info.required, defaultValue);
}
项目:dooo    文件:RequestParamResolveBean.java   
public RequestParamResolveBean(Class<?> clazz, String paraName, boolean required, String defaultValue, DataConverter dataConverter) {
    this.clazz = clazz;
    this.paraName = paraName;
    this.required = required;
    if (ValueConstants.DEFAULT_NONE.equals(defaultValue)) {
        this.defaultValue = dataConverter.defaultValue();
    } else if (StringUtils.isNotEmpty(defaultValue)) {
        this.defaultValue = dataConverter.toObject(defaultValue);
    } else {
        this.defaultValue = dataConverter.defaultValue();
    }
    this.dataConverter = dataConverter;
    this.isReference = dataConverter instanceof ReferenceDataConverter;
}
项目:FastBootWeixin    文件:WxApiMethodInfo.java   
private String getMethodWxApiRequestPath(Method method) {
    WxApiRequest wxApiRequest = AnnotatedElementUtils.findMergedAnnotation(method, WxApiRequest.class);
    if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.path()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.path())) {
        // 默认情况下取方法名为变量名,尝试从环境变量中获取信息
        return WxContextUtils.resolveStringValue("${" + this.wxApiTypeInfo.getPropertyPrefix() + "." + method.getName() + "}");
    }
    return wxApiRequest.path();
}
项目:FastBootWeixin    文件:WxApiExecutor.java   
/**
 * 要发送文件,使用这种方式,请查看源码:FormHttpMessageConverter
 *
 * @param wxApiMethodInfo
 * @param args
 * @return dummy
 */
private Object getFormBody(WxApiMethodInfo wxApiMethodInfo, Object[] args) {
    MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
    wxApiMethodInfo.getMethodParameters().stream()
            .filter(p -> !BeanUtils.isSimpleValueType(p.getParameterType()) || p.hasParameterAnnotation(WxApiForm.class) || p.hasParameterAnnotation(WxApiBody.class))
            .forEach(p -> {
                // 为空则直接返回不加这个参数
                if (args[p.getParameterIndex()] == null) {
                    return;
                }
                WxApiForm wxApiForm = p.getParameterAnnotation(WxApiForm.class);
                String paramName;
                Object param;
                if (wxApiForm == null || ValueConstants.DEFAULT_NONE.equals(wxApiForm.value())) {
                    paramName = p.getParameterName();
                } else {
                    paramName = wxApiForm.value();
                }
                // 加入Assert
                WxAppAssert.notNull(paramName, "请添加编译器的-parameter或者为参数添加注解名称");
                if (WxWebUtils.isMutlipart(p.getParameterType())) {
                    param = getFormResource(args[p.getParameterIndex()]);
                } else {
                    param = args[p.getParameterIndex()];
                }
                params.add(paramName, param);
            });
    return params;
}
项目:spring4-understanding    文件:AbstractNamedValueMethodArgumentResolver.java   
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
    String name = info.name;
    if (info.name.length() == 0) {
        name = parameter.getParameterName();
        if (name == null) {
            throw new IllegalArgumentException("Name for argument type [" + parameter.getParameterType().getName() +
                    "] not available, and parameter name information not found in class file either.");
        }
    }
    String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
    return new NamedValueInfo(name, info.required, defaultValue);
}
项目:spring4-understanding    文件:MockHttpServletRequestBuilder.java   
/**
 * Update the contextPath, servletPath, and pathInfo of the request.
 */
private void updatePathRequestProperties(MockHttpServletRequest request, String requestUri) {
    Assert.isTrue(requestUri.startsWith(this.contextPath),
            "requestURI [" + requestUri + "] does not start with contextPath [" + this.contextPath + "]");
    request.setContextPath(this.contextPath);
    request.setServletPath(this.servletPath);
    if (ValueConstants.DEFAULT_NONE.equals(this.pathInfo)) {
        Assert.isTrue(requestUri.startsWith(this.contextPath + this.servletPath),
                "Invalid servletPath [" + this.servletPath + "] for requestURI [" + requestUri + "]");
        String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
        this.pathInfo = (StringUtils.hasText(extraPath)) ? extraPath : null;
    }
    request.setPathInfo(this.pathInfo);
}
项目:onetwo    文件:ApiClientMethod.java   
protected void handleArg(MultiValueMap<String, Object> values, ApiClientMethodParameter mp, final Object pvalue, boolean flatable){
        Object paramValue = pvalue;
        if(mp.hasParameterAnnotation(RequestParam.class)){
            RequestParam params = mp.getParameterAnnotation(RequestParam.class);
            if(pvalue==null && params.required() && (paramValue=params.defaultValue())==ValueConstants.DEFAULT_NONE){
                throw new BaseException("parameter["+params.name()+"] must be required : " + mp.getParameterName());
            }
        }

        if(flatable){
            beanToMapConvertor.flatObject(mp.getParameterName(), paramValue, (k, v, ctx)->{
                if(v instanceof Enum){
                    Enum<?> e = (Enum<?>)v;
                    if(e instanceof ValueEnum){
                        v = ((ValueEnum<?>)e).getValue();
                    }else{//默认使用name
                        v = e.name();
                    }
                }
                if(ctx!=null){
//                  System.out.println("ctx.getName():"+ctx.getName());
                    values.add(ctx.getName(), v.toString());
                }else{
                    values.add(k, v.toString());
                }
    //          values.put(k, v);
            });
        }else{
            values.add(mp.getParameterName(), pvalue);
        }
    }
项目:class-guard    文件:MockHttpServletRequestBuilder.java   
/**
 * Update the contextPath, servletPath, and pathInfo of the request.
 */
private void updatePathRequestProperties(MockHttpServletRequest request, String requestUri) {
    Assert.isTrue(requestUri.startsWith(this.contextPath),
            "requestURI [" + requestUri + "] does not start with contextPath [" + this.contextPath + "]");
    request.setContextPath(this.contextPath);
    request.setServletPath(this.servletPath);
    if (ValueConstants.DEFAULT_NONE.equals(this.pathInfo)) {
        Assert.isTrue(requestUri.startsWith(this.contextPath + this.servletPath),
                "Invalid servletPath [" + this.servletPath + "] for requestURI [" + requestUri + "]");
        String extraPath = requestUri.substring(this.contextPath.length() + this.servletPath.length());
        this.pathInfo = (StringUtils.hasText(extraPath)) ? extraPath : null;
    }
    request.setPathInfo(this.pathInfo);
}
项目:class-guard    文件:AbstractNamedValueMethodArgumentResolver.java   
/**
 * Create a new NamedValueInfo based on the given NamedValueInfo with sanitized values.
 */
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {
    String name = info.name;
    if (info.name.length() == 0) {
        name = parameter.getParameterName();
        Assert.notNull(name, "Name for argument type [" + parameter.getParameterType().getName()
                    + "] not available, and parameter name information not found in class file either.");
    }
    String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);
    return new NamedValueInfo(name, info.required, defaultValue);
}
项目:wadl-tools    文件:ParamFromRequestParamBuilder.java   
@Override
public Param build(Method javaMethod, int paramIndex, Annotation paramAnnotation) {
    final RequestParam requestParam = (RequestParam) paramAnnotation;
    final Param param = new Param()
            .withName(discoverParamName(javaMethod, paramIndex, requestParam.value()))
            .withStyle(ParamStyle.QUERY)
            .withRequired(requestParam.required())
            .withType(grammarsDiscoverer.discoverQNameFor(new ClassMetadataFromParam(javaMethod, paramIndex)));

    if (!ValueConstants.DEFAULT_NONE.equals(requestParam.defaultValue())) {
        param.setDefault(requestParam.defaultValue());
    }
    return param;
}
项目:lams    文件:RequestParamMethodArgumentResolver.java   
public RequestParamNamedValueInfo() {
    super("", false, ValueConstants.DEFAULT_NONE);
}
项目:lams    文件:HandlerMethodInvoker.java   
protected String parseDefaultValueAttribute(String value) {
    return (ValueConstants.DEFAULT_NONE.equals(value) ? null : value);
}
项目:FastBootWeixin    文件:WxArgumentResolver.java   
public RequestParamNamedValueInfo() {
    super("", false, ValueConstants.DEFAULT_NONE);
}
项目:FastBootWeixin    文件:WxApiTypeInfo.java   
private String getTypeWxApiHost(WxApiRequest wxApiRequest, String defaultHost) {
    if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.host()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.host())) {
        return defaultHost;
    }
    return wxApiRequest.host();
}
项目:FastBootWeixin    文件:WxApiTypeInfo.java   
private String getTypeWxApiPropertyPrefix(WxApiRequest wxApiRequest) {
    if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.prefix()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.prefix())) {
        return WX_API_PROPERTY_PREFIX;
    }
    return wxApiRequest.prefix();
}
项目:FastBootWeixin    文件:WxApiTypeInfo.java   
private String getTypeWxApiRequestPath(WxApiRequest wxApiRequest) {
    if (wxApiRequest == null || StringUtils.isEmpty(wxApiRequest.path()) || ValueConstants.DEFAULT_NONE.equals(wxApiRequest.path())) {
        return "/";
    }
    return wxApiRequest.path();
}
项目:spring4-understanding    文件:MatrixVariableMethodArgumentResolver.java   
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {

    @SuppressWarnings("unchecked")
    Map<String, MultiValueMap<String, String>> pathParameters =
        (Map<String, MultiValueMap<String, String>>) request.getAttribute(
                HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

    if (CollectionUtils.isEmpty(pathParameters)) {
        return null;
    }

    String pathVar = parameter.getParameterAnnotation(MatrixVariable.class).pathVar();
    List<String> paramValues = null;

    if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
        if (pathParameters.containsKey(pathVar)) {
            paramValues = pathParameters.get(pathVar).get(name);
        }
    }
    else {
        boolean found = false;
        paramValues = new ArrayList<String>();
        for (MultiValueMap<String, String> params : pathParameters.values()) {
            if (params.containsKey(name)) {
                if (found) {
                    String paramType = parameter.getParameterType().getName();
                    throw new ServletRequestBindingException(
                            "Found more than one match for URI path parameter '" + name +
                            "' for parameter type [" + paramType + "]. Use pathVar attribute to disambiguate.");
                }
                paramValues.addAll(params.get(name));
                found = true;
            }
        }
    }

    if (CollectionUtils.isEmpty(paramValues)) {
        return null;
    }
    else if (paramValues.size() == 1) {
        return paramValues.get(0);
    }
    else {
        return paramValues;
    }
}
项目:spring4-understanding    文件:PathVariableMethodArgumentResolver.java   
public PathVariableNamedValueInfo(PathVariable annotation) {
    super(annotation.value(), true, ValueConstants.DEFAULT_NONE);
}
项目:spring4-understanding    文件:RequestParamMethodArgumentResolver.java   
public RequestParamNamedValueInfo() {
    super("", false, ValueConstants.DEFAULT_NONE);
}
项目:spring4-understanding    文件:HandlerMethodInvoker.java   
protected String parseDefaultValueAttribute(String value) {
    return (ValueConstants.DEFAULT_NONE.equals(value) ? null : value);
}
项目:leopard    文件:PrimitiveMethodArgumentResolver.java   
public RequestParamNamedValueInfo() {
    super("", false, ValueConstants.DEFAULT_NONE);
}
项目:leopard    文件:AbstractNamedValueMethodArgumentResolver.java   
public RequestParamNamedValueInfo() {
    super("", false, ValueConstants.DEFAULT_NONE);
}
项目:nanorest    文件:IdPathArgumentResolver.java   
public IdPathVariableNamedValueInfo(MethodParameter parameter) {
    super(parameter.getParameterName(), true, ValueConstants.DEFAULT_NONE);
}
项目:spring-auto-restdocs    文件:AbstractParameterSnippet.java   
protected boolean isCustomDefaultValue(final String defaultValue) {
    return defaultValue != null && !ValueConstants.DEFAULT_NONE.equals(defaultValue);
}
项目:spring-auto-restdocs    文件:RequestParametersSnippet.java   
private static boolean hasDefaultValue(RequestParam annot) {
    return !ValueConstants.DEFAULT_NONE.equals(annot.defaultValue());
}
项目:class-guard    文件:MatrixVariableMethodArgumentResolver.java   
@Override
protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception {

    @SuppressWarnings("unchecked")
    Map<String, MultiValueMap<String, String>> pathParameters =
        (Map<String, MultiValueMap<String, String>>) request.getAttribute(
                HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST);

    if (CollectionUtils.isEmpty(pathParameters)) {
        return null;
    }

    String pathVar = parameter.getParameterAnnotation(MatrixVariable.class).pathVar();
    List<String> paramValues = null;

    if (!pathVar.equals(ValueConstants.DEFAULT_NONE)) {
        if (pathParameters.containsKey(pathVar)) {
            paramValues = pathParameters.get(pathVar).get(name);
        }
    }
    else {
        boolean found = false;
        paramValues = new ArrayList<String>();
        for (MultiValueMap<String, String> params : pathParameters.values()) {
            if (params.containsKey(name)) {
                if (found) {
                    String paramType = parameter.getParameterType().getName();
                    throw new ServletRequestBindingException(
                            "Found more than one match for URI path parameter '" + name +
                            "' for parameter type [" + paramType + "]. Use pathVar attribute to disambiguate.");
                }
                paramValues.addAll(params.get(name));
                found = true;
            }
        }
    }

    if (CollectionUtils.isEmpty(paramValues)) {
        return null;
    }
    else if (paramValues.size() == 1) {
        return paramValues.get(0);
    }
    else {
        return paramValues;
    }
}
项目:class-guard    文件:PathVariableMethodArgumentResolver.java   
private PathVariableNamedValueInfo(PathVariable annotation) {
    super(annotation.value(), true, ValueConstants.DEFAULT_NONE);
}
项目:class-guard    文件:RequestParamMethodArgumentResolver.java   
private RequestParamNamedValueInfo() {
    super("", false, ValueConstants.DEFAULT_NONE);
}
项目:class-guard    文件:HandlerMethodInvoker.java   
protected String parseDefaultValueAttribute(String value) {
    return (ValueConstants.DEFAULT_NONE.equals(value) ? null : value);
}