1 16 17 package org.springframework.dao.support; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.springframework.dao.DataAccessException; 24 import org.springframework.util.Assert; 25 26 35 public class ChainedPersistenceExceptionTranslator implements PersistenceExceptionTranslator { 36 37 38 private final List delegates = new ArrayList (4); 39 40 41 44 public final void addDelegate(PersistenceExceptionTranslator pet) { 45 Assert.notNull(pet, "PersistenceExceptionTranslator must not be null"); 46 this.delegates.add(pet); 47 } 48 49 52 public final PersistenceExceptionTranslator[] getDelegates() { 53 return (PersistenceExceptionTranslator[]) 54 this.delegates.toArray(new PersistenceExceptionTranslator[this.delegates.size()]); 55 } 56 57 58 public DataAccessException translateExceptionIfPossible(RuntimeException ex) { 59 DataAccessException translatedDex = null; 60 for (Iterator it = this.delegates.iterator(); translatedDex == null && it.hasNext(); ) { 61 PersistenceExceptionTranslator pet = (PersistenceExceptionTranslator) it.next(); 62 translatedDex = pet.translateExceptionIfPossible(ex); 63 } 64 return translatedDex; 65 } 66 67 } 68 | Popular Tags |