Package org.hibernate.validator

Examples of org.hibernate.validator.ClassValidator


        Class<?> modelClass = value.getClass();
        java.util.ResourceBundle rb = null;
        if (modelClass.isAnnotationPresent(ResourceBundle.class))
          rb = java.util.ResourceBundle.getBundle(modelClass
              .getAnnotation(ResourceBundle.class).value());
        ClassValidator validator = new ClassValidator(modelClass, rb);
        InvalidValue[] invalidValues = validator
            .getInvalidValues(value);
        if (invalidValues != null && invalidValues.length > 0) {
          throw new ValidatorException(invalidValues);
        }
      }
View Full Code Here


    }

    @SuppressWarnings("unchecked")
    protected Map<String, InvalidValue> validate(DomainEntity entity) {
      Map<String, InvalidValue> fieldErrors = null;
      ClassValidator<DomainEntity> validator = new ClassValidator(ClassUtils.getActualClass(entity), ResourceBundle.getBundle("org.hibernate.validator.resources.DefaultValidatorMessages", WebContextLocale.getActiveLocale()));
      InvalidValue[] errors = filterErrors(validator.getInvalidValues(entity));
      if ((errors != null) && (errors.length > 0)) {
            fieldErrors = new HashMap<String, InvalidValue>(errors.length);
            for (InvalidValue error : errors)
                fieldErrors.put(messageResolver.getMessage(ClassUtils.getActualClass(entity).getName() + "." + error.getPropertyPath(), null, WebContextLocale.getActiveLocale()), error);
      }
View Full Code Here

  public List<InvalidValue> validate(ActionSupport actionAs, Locale clientLocale,
      ClassLoader classLoader) throws IOException {
    List<InvalidValue> invalidValuesFromRequest = new ArrayList<InvalidValue>();
   
    ClassValidator actionValidator = null;
    if (localesMap.containsKey(clientLocale.toString())) {
      actionValidator = new ClassValidator(actionAs.getClass(),localesMap.get(clientLocale.toString()));
    } else {
      ResourceBundle clientDefaultMessages = ResourceBundle.getBundle("org.hibernate.validator.resources.DefaultValidatorMessages", clientLocale, this.getClass().getClassLoader());
     
      try {
        ResourceBundle clientCustomMessages = ResourceBundle.getBundle("ValidatorMessages", clientLocale);
        actionValidator = new ClassValidator(actionAs.getClass(),clientCustomMessages);
        localesMap.put(clientLocale.toString(), clientCustomMessages);
      } catch (MissingResourceException e) {
        actionValidator = new ClassValidator(actionAs.getClass(),clientDefaultMessages);
        localesMap.put(clientLocale.toString(), clientDefaultMessages);
      }
    }
   
    // take all errors but discard when the field do not came from the request
    // Only the first validation error by field is used.
    InvalidValue[] invalidValues = actionValidator.getInvalidValues(actionAs);
    List<String> invalidFieldNames = new ArrayList<String>();
    Map parameters = ActionContext.getContext().getParameters();
    for (InvalidValue invalidValue : invalidValues) {
      String fieldFullName = invalidValue.getPropertyPath();
      if (invalidFieldNames.contains(fieldFullName))
View Full Code Here

        public boolean isNullable() {
            return !getField().isAnnotationPresent(NotNull.class);
        }

        public InvalidValue[] validate(Object value) {
            ClassValidator validator = Validators.instance().getValidator(getClazz());
            return validator.getPotentialInvalidValues(getFieldName(), value);
        }
View Full Code Here

        Collections.sort(newNodes, comparator);

        for (WikiNode newNode : newNodes) {
            log.debug("validating new node");

            ClassValidator validator = Validators.instance().getValidator(newNode.getClass());
            InvalidValue[] invalidValues = validator.getInvalidValues(newNode);
            if (invalidValues != null && invalidValues.length > 0) {
                log.debug("new node is invalid: " + newNode);
                for (InvalidValue invalidValue : invalidValues) {
                    statusMessages.addFromResourceBundleOrDefault(
                        ERROR,
View Full Code Here

        reflectionManager = new JavaReflectionManager();
      }
      while ( classes.hasNext() ) {
        PersistentClass clazz = classes.next();
        final Class mappedClass = clazz.getMappedClass();
        ClassValidator validator =
            new ClassValidator( mappedClass, null, interpolator, null, reflectionManager );
        ValidatableElement element = new ValidatableElement( mappedClass, validator );
        addSubElement( clazz.getIdentifierProperty(), element );
        Iterator properties = clazz.getPropertyIterator();
        while ( properties.hasNext() ) {
          addSubElement( (Property) properties.next(), element );
View Full Code Here

    if ( property != null && property.isComposite() && !property.isBackRef() ) {
      Component component = (Component) property.getValue();
      if ( component.isEmbedded() ) return;
      PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.POJO );
      Getter getter = accessor.getGetter( element.clazz, property.getName() );
      ClassValidator validator = new ClassValidator( getter.getReturnType() );
      ValidatableElement subElement = new ValidatableElement( getter.getReturnType(), validator, getter );
      Iterator properties = component.getPropertyIterator();
      while ( properties.hasNext() ) {
        addSubElement( (Property) properties.next(), subElement );
      }
View Full Code Here

  @SuppressWarnings( "unchecked" )
  public void onChange(Object object) {
    if (object == null) return;
    Class entity = object.getClass();
    WeakReference<ClassValidator> weakValidator = validators.get(entity);
    ClassValidator validator = weakValidator != null ? weakValidator.get() : null;
    if ( validator == null ) {
      //initialize
      //TODO reuse the same reflection manager?
      validator = new ClassValidator(entity);
      if ( ! validator.hasValidationRules() ) {
        validator = NO_VALIDATOR;
      }
      validators.put( entity, new WeakReference<ClassValidator>(validator) );
      currentValidators.add( validator );
    }
    if ( validator != NO_VALIDATOR ) {
      validator.assertValid( object );
    }
  }
View Full Code Here

        reflectionManager = new JavaReflectionManager();
      }
      while ( classes.hasNext() ) {
        PersistentClass clazz = classes.next();
        final Class mappedClass = clazz.getMappedClass();
        ClassValidator validator =
            new ClassValidator( mappedClass, null, interpolator, null, reflectionManager );
        ValidatableElement element = new ValidatableElement( mappedClass, validator );
        addSubElement( clazz.getIdentifierProperty(), element );
        Iterator properties = clazz.getPropertyIterator();
        while ( properties.hasNext() ) {
          addSubElement( (Property) properties.next(), element );
View Full Code Here

    if ( property != null && property.isComposite() && !property.isBackRef() ) {
      Component component = (Component) property.getValue();
      if ( component.isEmbedded() ) return;
      PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor( property, EntityMode.POJO );
      Getter getter = accessor.getGetter( element.clazz, property.getName() );
      ClassValidator validator = new ClassValidator( getter.getReturnType() );
      ValidatableElement subElement = new ValidatableElement( getter.getReturnType(), validator, getter );
      Iterator properties = component.getPropertyIterator();
      while ( properties.hasNext() ) {
        addSubElement( (Property) properties.next(), subElement );
      }
View Full Code Here

TOP

Related Classes of org.hibernate.validator.ClassValidator

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.