HHH-3261 : fixed wrapping of exception from initialize/destory listeners

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@14648 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2008-05-07 18:11:38 +00:00
parent 9ab9158656
commit 46af959c3f
1 changed files with 18 additions and 10 deletions

View File

@ -29,7 +29,6 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.hibernate.AssertionFailure;
import org.hibernate.MappingException; import org.hibernate.MappingException;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Configuration;
@ -162,18 +161,23 @@ public class EventListeners extends Cloneable implements Serializable {
private void processListeners(ListenerProcesser processer) { private void processListeners(ListenerProcesser processer) {
Field[] fields = getClass().getDeclaredFields(); Field[] fields = getClass().getDeclaredFields();
for ( int i = 0; i < fields.length; i++ ) { for ( int i = 0; i < fields.length; i++ ) {
final Object[] listeners;
try { try {
final Object field = fields[i].get( this ); Object fieldValue = fields[i].get(this);
if ( field instanceof Object[] ) { if ( fieldValue instanceof Object[] ) {
final Object[] listeners = ( Object[] ) field; listeners = ( Object[] ) fieldValue;
int length = listeners.length; }
for ( int index = 0 ; index < length ; index++ ) { else {
processer.processListener( listeners[index ] ); continue;
}
} }
} }
catch ( Exception e ) { catch ( Throwable t ) {
throw new HibernateException( "could not process listeners", e ); throw new HibernateException( "could not init listeners", t );
}
int length = listeners.length;
for ( int index = 0 ; index < length ; index++ ) {
processer.processListener( listeners[index ] );
} }
} }
} }
@ -201,6 +205,10 @@ public class EventListeners extends Cloneable implements Serializable {
} }
} }
/**
* Call {@link Destructible#cleanup} on any listeners that implement the
* {@link Destructible} interface.
*/
public void destroyListeners() { public void destroyListeners() {
try { try {
processListeners( processListeners(