Examples of ClassValidator


Examples of org.hibernate.validator.ClassValidator

    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

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

Examples of org.hibernate.validator.ClassValidator

        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

Examples of org.hibernate.validator.ClassValidator

    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

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

Examples of org.hibernate.validator.ClassValidator

  @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

Examples of org.hibernate.validator.ClassValidator

   */
  @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

Examples of org.hibernate.validator.ClassValidator

    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

Examples of org.hibernate.validator.ClassValidator

    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

Examples of org.hibernate.validator.ClassValidator

    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
TOP
Copyright © 2018 www.massapi.com. 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.