org.andromda.timetracker.domain.TimeAllocationDaoException.java Source code

Java tutorial

Introduction

Here is the source code for org.andromda.timetracker.domain.TimeAllocationDaoException.java

Source

// license-header java merge-point
//
// Attention: Generated code! Do not modify by hand!!
// Generated by DaoDefaultException.vsl in andromda-ejb3-cartridge.
//
package org.andromda.timetracker.domain;

import org.apache.commons.beanutils.PropertyUtils;

/**
 * TimeAllocation represents a time period for which the timecard submitter worked on the associated
 * task.
 */
public class TimeAllocationDaoException extends Exception {
    /**
     * The serial version UID of this class. Needed for serialization.
     */
    private static final long serialVersionUID = 6048749692954952788L;

    /**
     * The default constructor.
     */
    public TimeAllocationDaoException() {
    }

    /**
     * Constructs a new instance of TimeAllocationDaoException
     *
     * @param throwable the parent Throwable
     */
    public TimeAllocationDaoException(Throwable throwable) {
        super(findRootCause(throwable));
    }

    /**
     * Constructs a new instance of TimeAllocationDaoException
     *
     * @param message the throwable message.
     */
    public TimeAllocationDaoException(String message) {
        super(message);
    }

    /**
     * Constructs a new instance of TimeAllocationDaoException
     *
     * @param message the throwable message.
     * @param throwable the parent of this Throwable.
     */
    public TimeAllocationDaoException(String message, Throwable throwable) {
        super(message, findRootCause(throwable));
    }

    /**
     * Finds the root cause of the parent exception
     * by traveling up the exception tree
     */
    private static Throwable findRootCause(Throwable th) {
        if (th != null) {
            // Lets reflectively get any JMX or EJB exception causes.
            try {
                Throwable targetException = null;
                // java.lang.reflect.InvocationTargetException
                // or javax.management.ReflectionException
                String exceptionProperty = "targetException";
                if (PropertyUtils.isReadable(th, exceptionProperty)) {
                    targetException = (Throwable) PropertyUtils.getProperty(th, exceptionProperty);
                } else {
                    exceptionProperty = "causedByException";
                    //javax.ejb.EJBException
                    if (PropertyUtils.isReadable(th, exceptionProperty)) {
                        targetException = (Throwable) PropertyUtils.getProperty(th, exceptionProperty);
                    }
                }
                if (targetException != null) {
                    th = targetException;
                }
            } catch (Exception ex) {
                // just print the exception and continue
                ex.printStackTrace();
            }

            if (th.getCause() != null) {
                th = th.getCause();
                th = findRootCause(th);
            }
        }
        return th;
    }
}