Package javax.validation.constraints

Examples of javax.validation.constraints.Digits


        }
        final Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(method)[paramNum];

        for (final Annotation parameterAnnotation : parameterAnnotations) {
            if (parameterAnnotation instanceof Digits) {
                Digits digitsAnnotation = (Digits) parameterAnnotation;
                FacetUtil.addFacet(create(digitsAnnotation, processParameterContext.getFacetHolder()));
                return;
            }
        }
    }
View Full Code Here


        if (BigDecimal.class != processMethodContext.getMethod().getReturnType()) {
            return;
        }

        final Digits annotation = Annotations.getAnnotation(processMethodContext.getMethod(), Digits.class);
        if (annotation == null) {
            return;
        }
        FacetUtil.addFacet(create(processMethodContext, annotation));
    }
View Full Code Here

        }
        final Annotation[] parameterAnnotations = Annotations.getParameterAnnotations(method)[paramNum];

        for (final Annotation parameterAnnotation : parameterAnnotations) {
            if (parameterAnnotation instanceof Digits) {
                Digits digitsAnnotation = (Digits) parameterAnnotation;
                FacetUtil.addFacet(create(digitsAnnotation, processParameterContext.getFacetHolder()));
                return;
            }
        }
    }
View Full Code Here

            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof Digits) {
            // The annotated element must be a number within accepted range Supported types are: BigDecimal BigInteger
            // String byte, short, int, long, and their respective wrapper types
            // null elements are considered valid
            Digits digits = (Digits) annotation;
            if (digits.fraction() == 0) {
                sb.append("digits: true, \n");
                sb.append("maxlength: ").append(digits.integer());
            } else {
                // Something like /^\d{1,5}(\.\d{1,2})?$/
                sb.append("pattern: /^\\d{1,").append(digits.integer()).append("}(\\.\\d{1,").append(digits.fraction()).append("})?$/ ");
            }
        } else if (annotation instanceof Digits.List) {
            // Defines several @Digits annotations on the same element
            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof Future) {
View Full Code Here

            DecimalMax a = (DecimalMax) helper.getAnnotation(element, DecimalMax.class);
            DecimalMaxFacet facet = new DecimalMaxFacet(a.value(), a.inclusive());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Digits.class)) {
            Digits a = (Digits) helper.getAnnotation(element, Digits.class);
            DigitsFacet facet = new DigitsFacet(a.integer(), a.fraction());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Max.class)) {
            Max a = (Max) helper.getAnnotation(element, Max.class);
            MaxFacet facet = new MaxFacet(a.value());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Min.class)) {
            Min a = (Min) helper.getAnnotation(element, Min.class);
            MinFacet facet = new MinFacet(a.value());
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, NotNull.class)) {
            property.setNotNullAnnotated(true);
        }
        if (helper.isAnnotationPresent(element, Pattern.class)) {
            Pattern a = (Pattern) helper.getAnnotation(element, Pattern.class);
            PatternFacet facet = new PatternFacet(a.regexp(), a.flags());
            property.addFacet(facet);
        }
        /* Example:
            @Pattern.List({
                @Pattern(regexp = "first_expression", message = "first.Pattern.message"),
                @Pattern(regexp = "second_expression", message = "second.Pattern.message"),
                @Pattern(regexp = "third_expression", message = "third.Pattern.message")
        }) */
        if (helper.isAnnotationPresent(element, Pattern.List.class)) {
            Pattern.List a = (Pattern.List) helper.getAnnotation(element, Pattern.List.class);
            PatternListFacet facet = new PatternListFacet(new ArrayList<PatternFacet>());
            for (Pattern pat : a.value()) {
                PatternFacet pf = new PatternFacet(pat.regexp(), pat.flags());
                facet.addPattern(pf);
            }
            property.addFacet(facet);
        }
        if (helper.isAnnotationPresent(element, Size.class)) {
            Size a = (Size) helper.getAnnotation(element, Size.class);
            final int min = a.min();
            final int max = a.max();
            if (min != 0 || max != Integer.MAX_VALUE) { // Fixes generation of an empty facet.
                if ("java.lang.String".equals(property.getType().getName())) { // @Size serves for both length facet and occurs restriction.
                    SizeFacet facet = new SizeFacet(min, max); // For minLength, maxLength.
                    property.addFacet(facet);
                } else { // For minOccurs, maxOccurs.
View Full Code Here

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", 5 );
    descriptor.setValue( "fraction", 2 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    constraint = new DigitsValidatorForCharSequence();
    constraint.initialize( p );
  }
View Full Code Here

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", -1 );
    descriptor.setValue( "fraction", 1 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    DigitsValidatorForCharSequence constraint = new DigitsValidatorForCharSequence();
    constraint.initialize( p );
  }
View Full Code Here

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", 1 );
    descriptor.setValue( "fraction", -1 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    DigitsValidatorForCharSequence constraint = new DigitsValidatorForCharSequence();
    constraint.initialize( p );
  }
View Full Code Here

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", 5 );
    descriptor.setValue( "fraction", 2 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
    constraint.initialize( p );

View Full Code Here

    AnnotationDescriptor<Digits> descriptor = new AnnotationDescriptor<Digits>( Digits.class );
    descriptor.setValue( "integer", 0 );
    descriptor.setValue( "fraction", 0 );
    descriptor.setValue( "message", "{validator.digits}" );
    Digits p = AnnotationFactory.create( descriptor );

    DigitsValidatorForNumber constraint = new DigitsValidatorForNumber();
    constraint.initialize( p );

View Full Code Here

TOP

Related Classes of javax.validation.constraints.Digits

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.