public synchronized void initialize(Configuration cfg) {
if ( !isInitialized ) {
String interpolatorString = cfg.getProperty( Environment.MESSAGE_INTERPOLATOR_CLASS );
MessageInterpolator interpolator = null;
if ( StringHelper.isNotEmpty( interpolatorString ) ) {
try {
Class interpolatorClass = ReflectHelper.classForName( interpolatorString );
interpolator = (MessageInterpolator) interpolatorClass.newInstance();
}
catch (ClassNotFoundException e) {
throw new HibernateException( "Unable to find message interpolator: " + interpolatorString, e );
}
catch (IllegalAccessException e) {
throw new HibernateException( "Unable to instanciate message interpolator: " + interpolatorString,
e );
}
catch (InstantiationException 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 );
}
}
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 );
}
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 );
ValidatableElement element = new ValidatableElement( mappedClass, validator );
addSubElement( clazz.getIdentifierProperty(), element );
Iterator properties = clazz.getPropertyIterator();
while ( properties.hasNext() ) {
addSubElement( (Property) properties.next(), element );
}
if ( element.subElements.size() != 0 || element.validator.hasValidationRules() ) {
validators.put( mappedClass, element );
}
}
isInitialized = true;
}
}
initialize the validators, any non significant validators are not kept |