Example usage for org.springframework.web.bind.annotation ValueConstants DEFAULT_NONE

List of usage examples for org.springframework.web.bind.annotation ValueConstants DEFAULT_NONE

Introduction

In this page you can find the example usage for org.springframework.web.bind.annotation ValueConstants DEFAULT_NONE.

Prototype

String DEFAULT_NONE

To view the source code for org.springframework.web.bind.annotation ValueConstants DEFAULT_NONE.

Click Source Link

Document

Constant defining a value for no default - as a replacement for null which we cannot use in annotation attributes.

Usage

From source file:com.art4ul.jcoon.handlers.RequestParamAnnotationBeforeHandler.java

@Override
public void doHandle(Context context, Annotation annotation, Object paramValue) {
    RequestParam requestParam = (RequestParam) annotation;
    if (requestParam.value() != null && !requestParam.value().isEmpty()) {

        // Check null and set default value
        String param;/*from  ww  w.  ja  v  a2 s . c o m*/
        if (paramValue == null) {
            if (requestParam.defaultValue() != ValueConstants.DEFAULT_NONE) {
                param = requestParam.defaultValue();
            } else {
                param = "";
            }
        } else {
            param = paramValue.toString();
        }

        context.addHttpParam(requestParam.value(), param);
    }

}

From source file:com.art4ul.jcoon.handlers.RequestBodyParamAnnotationBeforeHandler.java

@Override
public void doHandle(Context context, Annotation annotation, Object paramValue) {
    RequestBodyParam requestParam = (RequestBodyParam) annotation;
    if (requestParam.value() != null && !requestParam.value().isEmpty()) {

        // Check null and set default value
        String param;/*from   ww w.  j  av a2 s  .com*/
        if (paramValue == null) {
            if (requestParam.defaultValue() != ValueConstants.DEFAULT_NONE) {
                param = requestParam.defaultValue();
            } else {
                param = "";
            }
        } else {
            param = paramValue.toString();
        }
        context.addHttpBodyParam(requestParam.value(), param);
    }

}

From source file:springfox.documentation.spring.web.readers.parameter.ParameterDefaultReader.java

@Override
public void apply(ParameterContext context) {
    MethodParameter methodParameter = context.methodParameter();
    String defaultValue = findAnnotatedDefaultValue(methodParameter);
    boolean isSkip = ValueConstants.DEFAULT_NONE.equals(defaultValue);
    if (!isSkip) {
        context.parameterBuilder().defaultValue(defaultValue);
    }//from w  w w  .ja  v a2  s  .c o  m
}

From source file:springfox.documentation.swagger.readers.parameter.ParameterDefaultReader.java

@Override
public void apply(ParameterContext context) {
    MethodParameter methodParameter = context.methodParameter();
    String defaultValue = findAnnotatedDefaultValue(methodParameter);
    boolean isSkip = ValueConstants.DEFAULT_NONE.equals(defaultValue);
    if (!isSkip) {
        context.parameterBuilder().defaultValue(nullToEmpty(defaultValue));
    }//from   ww  w.  jav  a  2 s.  c om
}

From source file:com.autentia.web.rest.wadl.builder.param.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());
    }/*from   w  w w .j ava2 s .  c  o  m*/
    return param;
}

From source file:com.zhucode.web.quick.argresolver.ParaHandlerMethodArgumentResolver.java

@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
    Para p = parameter.getParameterAnnotation(Para.class);
    Object val = webRequest.getParameter(p.name());
    if (!p.required()) {
        if (val == null) {
            val = p.defaultValue();
        }//from w w w.j  a va2  s .  c om
    }
    if (ValueConstants.DEFAULT_NONE.equals(val)) {
        return null;
    }
    try {
        return converter.convertIfNecessary(val, parameter.getParameterType());
    } catch (TypeMismatchException e) {
        throw new ParamErrorexception(p.name(), e.getMessage());
    }
}

From source file:springfox.documentation.spring.web.readers.parameter.ParameterRequiredReader.java

private boolean isRequired(RequestParam annotation) {
    String defaultValue = annotation.defaultValue();
    boolean missingDefaultValue = ValueConstants.DEFAULT_NONE.equals(defaultValue)
            || isNullOrEmpty(defaultValue);
    return annotation.required() && missingDefaultValue;
}

From source file:ch.ralscha.extdirectspring.util.ParameterInfo.java

public ParameterInfo(Class<?> clazz, Method method, int paramIndex) {

    MethodParameter methodParam = new MethodParameter(method, paramIndex);
    methodParam.initParameterNameDiscovery(discoverer);
    GenericTypeResolver.resolveParameterType(methodParam, clazz);

    this.name = methodParam.getParameterName();
    this.typeDescriptor = new TypeDescriptor(methodParam);

    Class<?> paramType = methodParam.getParameterType();
    javaUtilOptional = paramType.getName().equals("java.util.Optional");

    this.supportedParameter = SupportedParameters.isSupported(typeDescriptor.getObjectType());

    Annotation[] paramAnnotations = methodParam.getParameterAnnotations();

    for (Annotation paramAnn : paramAnnotations) {

        this.hasRequestParamAnnotation = false;
        this.hasMetadataParamAnnotation = false;
        this.hasRequestHeaderAnnotation = false;
        this.hasCookieValueAnnotation = false;
        this.hasAuthenticationPrincipalAnnotation = null;

        if (RequestParam.class.isInstance(paramAnn)) {
            RequestParam requestParam = (RequestParam) paramAnn;
            if (StringUtils.hasText(requestParam.value())) {
                this.name = requestParam.value();
            }/*w w  w .j av  a 2  s .co m*/
            this.required = requestParam.required();
            this.defaultValue = ValueConstants.DEFAULT_NONE.equals(requestParam.defaultValue()) ? null
                    : requestParam.defaultValue();
            this.hasRequestParamAnnotation = true;
            break;
        } else if (MetadataParam.class.isInstance(paramAnn)) {
            MetadataParam metadataParam = (MetadataParam) paramAnn;
            if (StringUtils.hasText(metadataParam.value())) {
                this.name = metadataParam.value();
            }
            this.required = metadataParam.required();
            this.defaultValue = ValueConstants.DEFAULT_NONE.equals(metadataParam.defaultValue()) ? null
                    : metadataParam.defaultValue();
            this.hasMetadataParamAnnotation = true;
            break;
        } else if (RequestHeader.class.isInstance(paramAnn)) {
            RequestHeader requestHeader = (RequestHeader) paramAnn;
            if (StringUtils.hasText(requestHeader.value())) {
                this.name = requestHeader.value();
            }
            this.required = requestHeader.required();
            this.defaultValue = ValueConstants.DEFAULT_NONE.equals(requestHeader.defaultValue()) ? null
                    : requestHeader.defaultValue();
            this.hasRequestHeaderAnnotation = true;
            break;
        } else if (CookieValue.class.isInstance(paramAnn)) {
            CookieValue cookieValue = (CookieValue) paramAnn;
            if (StringUtils.hasText(cookieValue.value())) {
                this.name = cookieValue.value();
            }
            this.required = cookieValue.required();
            this.defaultValue = ValueConstants.DEFAULT_NONE.equals(cookieValue.defaultValue()) ? null
                    : cookieValue.defaultValue();
            this.hasCookieValueAnnotation = true;
            break;
        } else if (paramAnn.annotationType().getName()
                .equals("org.springframework.security.web.bind.annotation.AuthenticationPrincipal")
                || paramAnn.annotationType().getName()
                        .equals("org.springframework.security.core.annotation.AuthenticationPrincipal")) {
            hasAuthenticationPrincipalAnnotation = (Boolean) AnnotationUtils.getValue(paramAnn,
                    "errorOnInvalidType");
        }
    }
}

From source file:at.fwd.swagger.spring.demo.plugins.MyParameterRequiredReader.java

private boolean isRequired(RequestParam annotation) {
    System.out.println("required: " + annotation.value());
    String defaultValue = annotation.defaultValue();
    boolean missingDefaultValue = ValueConstants.DEFAULT_NONE.equals(defaultValue)
            || isNullOrEmpty(defaultValue);
    return annotation.required() && missingDefaultValue;
}

From source file:com.wavemaker.tools.apidocs.tools.spring.parser.SpringParameterParser.java

/**
 * It will check for the spring default value, if it matches returns null, else given value.
 *
 * @param defaultValue value to be check.
 * @return null if it matches spring default value, else given value.
 *//*  www.j a  v a2s .  com*/
private String getDefaultValue(String defaultValue) {
    return defaultValue.equals(ValueConstants.DEFAULT_NONE) ? null : defaultValue;
}