Package javax.validation.constraints

Examples of javax.validation.constraints.Size


        } else if (annotation instanceof Pattern.List) {
            // Defines several @Pattern annotations on the same element
            throw new UnsupportedOperationException("Not implemented");
        } else if (annotation instanceof Size) {
            // The annotated element size must be between the specified boundaries (included).
            Size size = (Size) annotation;
            if (size.min() > 0) {
                sb.append("required: true, \n");
            }
            sb.append("minlength: ").append(size.min()).append(",\n");
            sb.append("maxlength: ").append(size.max());
        } else if (annotation instanceof Size.List) {
            // Defines several @Size annotations on the same element
            throw new UnsupportedOperationException("Not implemented");
        }
        return sb.toString();
View Full Code Here


        if (annotation instanceof NotEmpty) {
            return true;
        } else if (annotation instanceof NotNull) {
            return true;
        } else if (annotation instanceof Size) {
            Size sizeAnnotation = (Size) annotation;
            return sizeAnnotation.min() > 0;
        }
        return false;
    }
View Full Code Here

                if (max.value() > 0) {
                    setMaxlength(input, Long.valueOf(max.value()).intValue());
                }
            }
            else if (constraint.annotationType().equals(Size.class)) {
                Size size = (Size) constraint;
                if (size.max() > 0) {
                    setMaxlength(input, size.max());
                }
            }
        }
       
        if (!editableValueHolder.isRequired()) {
            if (constraint.annotationType().equals(Min.class)) {
                Min min = (Min) constraint;
                if (min.value() > 0) {
                    editableValueHolder.setRequired(true);
                }
            }
            else if (constraint.annotationType().equals(Size.class)) {
                Size size = (Size) constraint;
                if (size.min() > 0) {
                    editableValueHolder.setRequired(true);
                }
            }
            else if (constraint.annotationType().equals(NotNull.class)) {
                editableValueHolder.setRequired(true);
View Full Code Here

                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

    assertEquals( composingDescriptors.size(), 2, "Wrong number of composing constraints" );
    boolean hasSize = false;
    for ( ConstraintDescriptor<?> desc : composingDescriptors ) {
      if ( desc.getAnnotation().annotationType().equals( Size.class ) ) {
        hasSize = true;
        Size sizeAnn = ( Size ) desc.getAnnotation();
        assertEquals( sizeAnn.min(), 5, "The min parameter should reflect the overridden parameter" );
        assertEquals(
            desc.getAttributes().get( "min" ),
            5,
            "The min parameter should reflect the overridden parameter"
        );
View Full Code Here

    ConstraintDescriptor<?> descriptor = getConstraintDescriptor( Person.class, "firstName" );
    Set<ConstraintDescriptor<?>> composingDescriptors = descriptor.getComposingConstraints();
    assertEquals( composingDescriptors.size(), 2, "Wrong number of composing constraints" );
    for ( ConstraintDescriptor<?> desc : composingDescriptors ) {
      if ( desc.getAnnotation().annotationType().equals( Size.class ) ) {
        Size sizeAnn = ( Size ) desc.getAnnotation();
        assertEquals( sizeAnn.min(), 5, "The min parameter should reflect the overriden parameter" );
        assertEquals(
            desc.getAttributes().get( "min" ), 5, "The min parameter should reflect the overriden parameter"
        );
      }
      else if ( desc.getAnnotation().annotationType().equals( NotNull.class ) ) {
View Full Code Here

  private <T> ConstraintValidator<Size, T> getValidatorMin1Max2(Class<?> validatorClass) throws Exception {
    AnnotationDescriptor<Size> descriptor = new AnnotationDescriptor<Size>( Size.class );
    descriptor.setValue( "min", 1 );
    descriptor.setValue( "max", 2 );
    descriptor.setValue( "message", "{validator.max}" );
    Size m = AnnotationFactory.create( descriptor );
    @SuppressWarnings("unchecked")
    ConstraintValidator<Size, T> validator = (ConstraintValidator<Size, T>) validatorClass.newInstance();
    validator.initialize( m );
    return validator;
  }
View Full Code Here

        notNull,
        java.lang.annotation.ElementType.FIELD
    );

    AnnotationDescriptor<Size> sizeAnnotationDescriptor = new AnnotationDescriptor<Size>( Size.class );
    Size size = AnnotationFactory.create( sizeAnnotationDescriptor );
    sizeDescriptor = new ConstraintDescriptorImpl<Size>(
        new ConstraintHelper(),
        null,
        size,
        java.lang.annotation.ElementType.FIELD
View Full Code Here

  public void createAnnotationProxy() {
    AnnotationDescriptor<Size> descriptor = new AnnotationDescriptor<Size>( Size.class );
    descriptor.setValue( "min", 5 );
    descriptor.setValue( "max", 10 );

    Size size = AnnotationFactory.create( descriptor );

    assertEquals( size.min(), 5, "Wrong parameter value" );
    assertEquals( size.max(), 10, "Wrong parameter value" );
  }
View Full Code Here

    if (annotation instanceof DecimalMax) {
      params += ((DecimalMax) annotation).value();
    }

    if (annotation instanceof Size) {
      Size size = (Size) annotation;
      params += size.min() + ", " + size.max();
    }

    return params;
  }
View Full Code Here

TOP

Related Classes of javax.validation.constraints.Size

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.