SponsorDaoException.java

  1. // license-header java merge-point
  2. //
  3. // Attention: Generated code! Do not modify by hand!!
  4. // Generated by DaoDefaultException.vsl in andromda-ejb3-cartridge on 08/08/2014 12:21:07.
  5. //
  6. package org.andromda.demo.ejb3.athlete;

  7. import org.apache.commons.beanutils.PropertyUtils;

  8. /**
  9.  * <p>
  10.  * TODO: Model Documentation for org.andromda.demo.ejb3.athlete.Sponsor
  11.  * </p>
  12.  */
  13. public class SponsorDaoException
  14.     extends Exception
  15. {
  16.     /**
  17.      * The serial version UID of this class. Needed for serialization.
  18.      */
  19.     private static final long serialVersionUID = -5150522456724891050L;

  20.     /**
  21.      * The default constructor.
  22.      */
  23.     public SponsorDaoException()
  24.     {}

  25.     /**
  26.      * Constructs a new instance of SponsorDaoException
  27.      *
  28.      * @param throwable the parent Throwable
  29.      */
  30.     public SponsorDaoException(Throwable throwable)
  31.     {
  32.         super(findRootCause(throwable));
  33.     }

  34.     /**
  35.      * Constructs a new instance of SponsorDaoException
  36.      *
  37.      * @param message the throwable message.
  38.      */
  39.     public SponsorDaoException(String message)
  40.     {
  41.         super(message);
  42.     }

  43.     /**
  44.      * Constructs a new instance of SponsorDaoException
  45.      *
  46.      * @param message the throwable message.
  47.      * @param throwable the parent of this Throwable.
  48.      */
  49.     public SponsorDaoException(String message, Throwable throwable)
  50.     {
  51.         super(message, findRootCause(throwable));
  52.     }

  53.     /**
  54.      * Finds the root cause of the parent exception
  55.      * by traveling up the exception tree
  56.      */
  57.     private static Throwable findRootCause(Throwable th)
  58.     {
  59.         if (th != null)
  60.         {
  61.             // Lets reflectively get any JMX or EJB exception causes.
  62.             try
  63.             {
  64.                 Throwable targetException = null;
  65.                 // java.lang.reflect.InvocationTargetException
  66.                 // or javax.management.ReflectionException
  67.                 String exceptionProperty = "targetException";
  68.                 if (PropertyUtils.isReadable(th, exceptionProperty))
  69.                 {
  70.                     targetException = (Throwable)PropertyUtils.getProperty(th, exceptionProperty);
  71.                 }
  72.                 else
  73.                 {
  74.                     exceptionProperty = "causedByException";
  75.                     //javax.ejb.EJBException
  76.                     if (PropertyUtils.isReadable(th, exceptionProperty))
  77.                     {
  78.                         targetException = (Throwable)PropertyUtils.getProperty(th, exceptionProperty);
  79.                     }
  80.                 }
  81.                 if (targetException != null)
  82.                 {
  83.                     th = targetException;
  84.                 }
  85.             }
  86.             catch (Exception ex)
  87.             {
  88.                 // just print the exception and continue
  89.                 ex.printStackTrace();
  90.             }

  91.             if (th.getCause() != null)
  92.             {
  93.                 th = th.getCause();
  94.                 th = findRootCause(th);
  95.             }
  96.         }
  97.         return th;
  98.     }
  99. }