From: Vance K. <va...@us...> - 2006-01-28 02:42:32
|
User: vancek Date: 06/01/27 18:42:26 Added: andromda-ejb3/src/main/resources/templates/ejb3 DefaultServiceException.vsl Log: initial revision Revision Changes Path 1.1 cartridges/andromda-ejb3/src/main/resources/templates/ejb3/DefaultServiceException.vsl Index: DefaultServiceException.vsl =================================================================== // license-header java merge-point // // Attention: Generated code! Do not modify by hand! // Generated by: DefaultServiceException.vsl in andromda-ejb3-cartridge. // #set ($generatedFile = "${stringUtils.replace($service.fullyQualifiedDefaultExceptionName,'.','/')}.java") #if ($stringUtils.isNotBlank($service.packageName)) package $service.packageName; #end import org.apache.commons.beanutils.PropertyUtils; /** * The default exception thrown for unexpected errors occurring * within {@link $service.fullyQualifiedName}. */ public class $service.defaultExceptionName extends java.lang.RuntimeException { /** * The serial version UID of this class. Needed for serialization. */ private static final long serialVersionUID = ${service.serialVersionUID}L; /** * The default constructor for <code>$service.defaultExceptionName</code>. */ public ${service.defaultExceptionName}() {} /** * Constructs a new instance of <code>$service.defaultExceptionName</code>. * * @param throwable the parent Throwable */ public ${service.defaultExceptionName}(Throwable throwable) { super(findRootCause(throwable)); } /** * Constructs a new instance of <code>$service.defaultExceptionName</code>. * * @param message the throwable message. */ public ${service.defaultExceptionName}(String message) { super(message); } /** * Constructs a new instance of <code>$service.defaultExceptionName</code>. * * @param message the throwable message. * @param throwable the parent of this Throwable. */ public ${service.defaultExceptionName}(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) { // Reflectively get any exception causes. try { Throwable targetException = null; // java.lang.reflect.InvocationTargetException 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; } } |