Package org.hibernate.validator

Examples of org.hibernate.validator.ClassValidator


  @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


  @SuppressWarnings("unchecked")
  protected ClassValidator<? extends Object> getValidator(
      Class<? extends Object> beanClass, Locale locale) {
    // TODO - localization support.
    ValidatorKey key = new ValidatorKey(beanClass, locale);
    ClassValidator result = classValidators.get(key);
    if (null == result) {
      result = createValidator(beanClass, locale);
      classValidators.put(key, result);
    }
    return result;
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  protected ClassValidator<? extends Object> createValidator(
      Class<? extends Object> beanClass, Locale locale) {
    ResourceBundle bundle = getCurrentResourceBundle(locale);
    return bundle == null ? new ClassValidator(beanClass)
        : new ClassValidator(beanClass, bundle);
  }
View Full Code Here

    User username = new User();
    username.setFirstname( "Emmanuel" );
    username.setMiddlename( "P" );
    username.setLastname( "Bernard" );
    cc.setUsername( username );
    ClassValidator ccValid = new ClassValidator( CreditCard.class );
    assertEquals( 0, ccValid.getInvalidValues( cc ).length );
    username.setMiddlename( null );
    assertEquals( 0, ccValid.getInvalidValues( cc ).length );
    Session s = openSession();
    Transaction tx = s.beginTransaction();
    s.persist( cc );
    s.flush();
    tx.rollback();
View Full Code Here

    presNok.name = null;
    Presenter presOk = new Presenter();
    presOk.name = "Thierry Ardisson";
    tv.presenters.add( presOk );
    tv.presenters.add( presNok );
    ClassValidator validator = new ClassValidator( Tv.class );
    InvalidValue[] values = validator.getInvalidValues( tv );
    assertEquals( 1, values.length );
    assertEquals( "presenters[1].name", values[0].getPropertyPath() );
  }
View Full Code Here

    showOk.name = "Tout le monde en parle";
    Show showNok = new Show();
    showNok.name = null;
    tv.shows.put( "Midnight", showOk );
    tv.shows.put( "Primetime", showNok );
    ClassValidator validator = new ClassValidator( Tv.class );
    InvalidValue[] values = validator.getInvalidValues( tv );
    assertEquals( 1, values.length );
    assertEquals( "shows['Primetime'].name", values[0].getPropertyPath() );
  }
View Full Code Here

    tv.movies = new Movie[]{
        movieOk,
        null,
        movieNok
    };
    ClassValidator validator = new ClassValidator( Tv.class );
    InvalidValue[] values = validator.getInvalidValues( tv );
    assertEquals( 1, values.length );
    assertEquals( "movies[2].name", values[0].getPropertyPath() );
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  protected ClassValidator<? extends Object> getValidator(
      FacesContext facesContext, Class<? extends Object> beanClass) {
    // TODO - localization support.
    ValidatorKey key = new ValidatorKey(beanClass, calculateLocale(facesContext));
    ClassValidator result = classValidators.get(key);
    if (null == result) {
      result = createValidator(facesContext, beanClass);
      classValidators.put(key, result);
    }
    return result;
View Full Code Here

   */
  @SuppressWarnings("unchecked")
  protected ClassValidator<? extends Object> createValidator(
      FacesContext facesContext, Class<? extends Object> beanClass) {
    ResourceBundle bundle = createHibernateMessages(facesContext);
    return bundle == null ? new ClassValidator(beanClass)
        : new ClassValidator(beanClass, bundle);
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  protected ClassValidator<? extends Object> getValidator(
      Class<? extends Object> beanClass, Locale locale) {
    // TODO - localization support.
    ValidatorKey key = new ValidatorKey(beanClass, locale);
    ClassValidator result = classValidators.get(key);
    if (null == result) {
      result = createValidator(beanClass, locale);
      classValidators.put(key, result);
    }
    return result;
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.