Author: epbernard
Date: 2007-01-26 16:21:03 -0500 (Fri, 26 Jan 2007)
New Revision: 11108
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
Log:
ANN-545 eliminate dep between HAN and Validator
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-26
21:17:27 UTC (rev 11107)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/validator/event/ValidateEventListener.java 2007-01-26
21:21:03 UTC (rev 11108)
@@ -12,7 +12,6 @@
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
-import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.event.Initializable;
import org.hibernate.event.PreInsertEvent;
@@ -47,7 +46,7 @@
/**
* initialize the validators, any non significant validators are not kept
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public synchronized void initialize(final Configuration cfg) {
if ( !isInitialized ) {
String interpolatorString = cfg.getProperty( Environment.MESSAGE_INTERPOLATOR_CLASS
);
@@ -61,31 +60,36 @@
throw new HibernateException( "Unable to find message interpolator: " +
interpolatorString, e );
}
catch (IllegalAccessException e) {
- throw new HibernateException( "Unable to instanciate message interpolator:
" + interpolatorString, e );
+ throw new HibernateException( "Unable to instanciate message interpolator:
" + interpolatorString,
+ e );
}
catch (InstantiationException e) {
- throw new HibernateException( "Unable to instanciate message interpolator:
" + interpolatorString, e );
+ throw new HibernateException( "Unable to instanciate message interpolator:
" + interpolatorString,
+ e );
}
catch (ClassCastException e) {
throw new HibernateException( "Class does not implement "
- + MessageInterpolator.class.getName() + ": " + interpolatorString, e );
+ + MessageInterpolator.class.getName() + ": " + interpolatorString, e );
}
}
Iterator<PersistentClass> classes = (Iterator<PersistentClass>)
cfg.getClassMappings();
- ReflectionManager reflectionManager;
- try {
- //TODO introduce q ReflectionManagerHolder interface to avoid reflection
- //I want to avoid hard link between HAN and Validator for usch a simple
need
- //reuse the existing reflectionManager one when possible
- reflectionManager = (ReflectionManager) cfg.getClass().getMethod(
"getReflectionManager" ).invoke(cfg);
+ ReflectionManager reflectionManager;
+ try {
+ //TODO introduce q ReflectionManagerHolder interface to avoid reflection
+ //I want to avoid hard link between HAN and Validator for usch a simple need
+ //reuse the existing reflectionManager one when possible
+ reflectionManager =
+ (ReflectionManager) cfg.getClass().getMethod( "getReflectionManager"
).invoke( cfg );
- } catch (Exception e) {
- reflectionManager = new JavaReflectionManager();
- }
- while ( classes.hasNext() ) {
+ }
+ catch (Exception e) {
+ reflectionManager = new JavaReflectionManager();
+ }
+ while ( classes.hasNext() ) {
PersistentClass clazz = classes.next();
final Class mappedClass = clazz.getMappedClass();
- ClassValidator validator = new ClassValidator( mappedClass, null, interpolator, null,
reflectionManager );
+ ClassValidator validator =
+ new ClassValidator( mappedClass, null, interpolator, null, reflectionManager );
ValidatableElement element = new ValidatableElement( mappedClass, validator );
addSubElement( clazz.getIdentifierProperty(), element );
Iterator properties = clazz.getPropertyIterator();
@@ -100,9 +104,9 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private void addSubElement(Property property, ValidatableElement element) {
- if ( property != null && property.isComposite() && !
property.isBackRef() ) {
+ if ( property != null && property.isComposite() &&
!property.isBackRef() ) {
Component component = (Component) property.getValue();
if ( component.isEmbedded() ) return;
PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor( property,
EntityMode.POJO );
@@ -119,9 +123,9 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
protected void validate(Object entity, EntityMode mode) {
- if ( entity == null || ! EntityMode.POJO.equals( mode ) ) return;
+ if ( entity == null || !EntityMode.POJO.equals( mode ) ) return;
ValidatableElement element;
if ( isInitialized ) {
element = validators.get( entity.getClass() );
@@ -136,7 +140,7 @@
InvalidValue[] invalidValues = element.validator == null ?
null :
element.validator.getInvalidValues( entity );
- if (invalidValues != null) {
+ if ( invalidValues != null ) {
for ( InvalidValue invalidValue : invalidValues ) {
consolidatedInvalidValues.add( invalidValue );
}
@@ -149,7 +153,7 @@
}
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private void validateSubElements(
ValidatableElement element, Object entity, List<InvalidValue>
consolidatedInvalidValues
) {
Show replies by date