001 package com.croftsoft.core.lang;
002
003 /*********************************************************************
004 * Indicates an Exception while accessing an external resource.
005 *
006 * <p>
007 * Useful for propagating an SQLException or RemoteException through
008 * a Data Access Object (DAO) interface. Define the data accessor
009 * interface methods so that they throw ExternalAccessException instead
010 * of SQLException, RemoteException, IOException, or any other
011 * Exception indicating external access failure. Since the calling
012 * application no longer needs to be hard-coded to handle an Exception
013 * subclass specific to the data access mechanism, the mechanism can be
014 * easily replaced, at run-time if desired, simply by instantiating a
015 * different concrete implementation of the data accessor interface.
016 * </p>
017 *
018 * <p>
019 * The original Exception is passed into the ExternalAccessException as
020 * a constructor argument. The Exception stack trace is stored as a
021 * String within the ExternalAccessException in order to facilitate
022 * serialization and persistence without the need to transport class
023 * files.
024 * </p>
025 *
026 * @see
027 * <a href="http://developer.java.sun.com/developer/restricted/patterns/DataAccessObject.html">
028 * Sun Java Center J2EE Patterns: Data Access Object</a>
029 *
030 * @see
031 * <a href="http://www.sun.com/tech/techrep/1994/abstract-29.html">
032 * "A Note on Distributed Computing"</a>
033 *
034 * @version
035 * 2001-06-21
036 * @since
037 * 2001-02-28
038 * @author
039 * <a target="_blank" href="http://croftsoft.com/">David W. Croft</a>
040 *********************************************************************/
041
042 public final class ExternalAccessException
043 extends Exception
044 //////////////////////////////////////////////////////////////////////
045 //////////////////////////////////////////////////////////////////////
046 {
047
048 private static final long serialVersionUID = 1L;
049
050 private String rootExceptionStackTrace;
051
052 //////////////////////////////////////////////////////////////////////
053 // constructor methods
054 //////////////////////////////////////////////////////////////////////
055
056 public ExternalAccessException (
057 String message,
058 Exception rootException )
059 //////////////////////////////////////////////////////////////////////
060 {
061 super ( message );
062
063 if ( rootException != null )
064 {
065 this.rootExceptionStackTrace
066 = ThrowableLib.getStackTrace ( rootException );
067 }
068 else
069 {
070 this.rootExceptionStackTrace = null;
071 }
072 }
073
074 public ExternalAccessException ( Exception rootException )
075 //////////////////////////////////////////////////////////////////////
076 {
077 this (
078 rootException != null ? rootException.getMessage ( ) : null,
079 rootException );
080 }
081
082 public ExternalAccessException ( String message )
083 //////////////////////////////////////////////////////////////////////
084 {
085 this ( message, null );
086 }
087
088 public ExternalAccessException ( )
089 //////////////////////////////////////////////////////////////////////
090 {
091 this ( null, null );
092 }
093
094 //////////////////////////////////////////////////////////////////////
095 //////////////////////////////////////////////////////////////////////
096
097 public String getRootExceptionStackTrace ( )
098 //////////////////////////////////////////////////////////////////////
099 {
100 return rootExceptionStackTrace;
101 }
102
103 //////////////////////////////////////////////////////////////////////
104 //////////////////////////////////////////////////////////////////////
105 }