TicketException.java

// license-header java merge-point
//
/**
 * @author Generated by ApplicationException.vsl in andromda-java-cartridge on 08/08/2014 12:21:08-0400 Do not modify by hand!
 *
 * TEMPLATE:     ApplicationException.vsl in andromda-java-cartridge.
 * MODEL CLASS:  EJB3 Demo::EJB3 Demo::org::andromda::demo::ejb3::ticket::TicketException
 * STEREOTYPE:   Exception
 */
package org.andromda.demo.ejb3.ticket;

import org.apache.commons.beanutils.PropertyUtils;

/**
 * <p>
 * TODO: Model Documentation for org.andromda.demo.ejb3.ticket.TicketException
 * </p>
 */
public class TicketException
    extends Exception
{
    /** The serial version UID of this class. Throwable implements Serializable so declaration not needed. */
    private static final long serialVersionUID = 7507714947068894610L;

    /**
     * The default constructor.
     */
    public TicketException()
    {
        super();
        // Avoid compiler warning from uncommented empty method
    }

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

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

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

    private Object[] messageArguments;

    /**
     * Gets the message arguments that can be used by message resources (in
     * something like the presentation tier)
     *
     * @return messageArguments
     */
    public Object[] getMessageArguments()
    {
        return this.messageArguments;
    }

    /**
     * Sets the message arguments that can be used by message resources (in
     * something like the presentation tier)
     *
     * @param messageArgumentsIn
     */
    public void setMessageArguments(Object[] messageArgumentsIn)
    {
        this.messageArguments = messageArgumentsIn;
    }

    /**
     * Finds the root cause of the parent exception
     * by traveling up the exception tree. Performs printStackTrace if
     * an exception is thrown.
     * @param th Throwable to find the cause from
     * @return targetException Throwable cause
     */
    private static Throwable findRootCause(Throwable th)
    {
        if (th != null)
        {
            // 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;
    }
}