FileDocCategorySizeDatePackage
TopLinkException.javaAPI DocGlassfish v2 API10034Tue May 22 16:54:18 BST 2007oracle.toplink.essentials.exceptions

TopLinkException

public abstract class TopLinkException extends RuntimeException

Purpose: Any exception raised by TopLink should be a subclass of this exception class.

Fields Summary
protected transient AbstractSession
session
protected Throwable
internalException
protected static Boolean
shouldPrintInternalException
protected String
indentationString
protected int
errorCode
protected static final String
CR
protected boolean
hasBeenLogged
Constructors Summary
public TopLinkException()
INTERNAL: Return a new exception.


              
      
        this("");
    
public TopLinkException(String theMessage)
INTERNAL: TopLink exception should only be thrown by TopLink.

        super(theMessage);
        this.indentationString = "";
        hasBeenLogged = false;
    
public TopLinkException(String message, Throwable internalException)
INTERNAL: TopLink exception should only be thrown by TopLink.

        this(message);
        setInternalException(internalException);
    
Methods Summary
protected static java.lang.Stringcr()
INTERNAL: Convenience method - return a platform-specific line-feed.

        return oracle.toplink.essentials.internal.helper.Helper.cr();
    
public intgetErrorCode()
PUBLIC: Return the exception error code.

        return errorCode;
    
public java.lang.StringgetIndentationString()
INTERNAL: Used to print things nicely in the testing tool.

        return indentationString;
    
public java.lang.ThrowablegetInternalException()
PUBLIC: Return the internal native exception. TopLink frequently catches Java exceptions and wraps them in its own exception classes to provide more information. The internal exception can still be accessed if required.

        return internalException;
    
public java.lang.StringgetMessage()
PUBLIC: Return the exception error message. TopLink error messages are multi-line so that detail descriptions of the exception are given.

        StringWriter writer = new StringWriter(100);

        // Avoid printing internal exception error message twice.
        if ((getInternalException() == null) || (!super.getMessage().equals(getInternalException().toString()))) {
            writer.write(cr());
            writer.write(getIndentationString());
            writer.write(ExceptionMessageGenerator.getHeader("DescriptionHeader"));
            writer.write(super.getMessage());
        }

        if (getInternalException() != null) {
            writer.write(cr());
            writer.write(getIndentationString());
            writer.write(ExceptionMessageGenerator.getHeader("InternalExceptionHeader"));
            writer.write(getInternalException().toString());

            if ((getInternalException() instanceof java.lang.reflect.InvocationTargetException) && ((((java.lang.reflect.InvocationTargetException)getInternalException()).getTargetException()) != null)) {
                writer.write(cr());
                writer.write(getIndentationString());
                writer.write(ExceptionMessageGenerator.getHeader("TargetInvocationExceptionHeader"));
                writer.write(((java.lang.reflect.InvocationTargetException)getInternalException()).getTargetException().toString());
            }
        }

        return writer.toString();
    
public oracle.toplink.essentials.internal.sessions.AbstractSessiongetSession()
PUBLIC: Return the session.

        return session;
    
public booleanhasBeenLogged()
INTERNAL: Return if this exception has been logged to avoid being logged more than once.

        return hasBeenLogged;
    
public voidprintStackTrace()
PUBLIC: Print both the normal and internal stack traces.

        printStackTrace(System.err);
    
public voidprintStackTrace(java.io.PrintStream outStream)
PUBLIC: Print both the normal and internal stack traces.

        printStackTrace(new PrintWriter(outStream));
    
public voidprintStackTrace(java.io.PrintWriter writer)
PUBLIC: Print both the normal and internal stack traces.

        writer.write(ExceptionMessageGenerator.getHeader("LocalExceptionStackHeader"));
        writer.write(cr());
        super.printStackTrace(writer);

        if ((getInternalException() != null) && shouldPrintInternalException()) {
            writer.write(ExceptionMessageGenerator.getHeader("InternalExceptionStackHeader"));
            writer.write(cr());
            getInternalException().printStackTrace(writer);

            if ((getInternalException() instanceof java.lang.reflect.InvocationTargetException) && ((((java.lang.reflect.InvocationTargetException)getInternalException()).getTargetException()) != null)) {
                writer.write(ExceptionMessageGenerator.getHeader("TargetInvocationExceptionStackHeader"));
                writer.write(cr());
                ((java.lang.reflect.InvocationTargetException)getInternalException()).getTargetException().printStackTrace(writer);
            }
        }
        writer.flush();
    
public voidsetErrorCode(int errorCode)
INTERNAL:

        this.errorCode = errorCode;
    
public voidsetHasBeenLogged(boolean logged)
INTERNAL: Set this flag to avoid logging an exception more than once.

        this.hasBeenLogged = logged;
    
public voidsetIndentationString(java.lang.String indentationString)
INTERNAL: Used to print things nicely in the testing tool.

        this.indentationString = indentationString;
    
public voidsetInternalException(java.lang.Throwable anException)
INTERNAL: Used to specify the internal exception.

        internalException = anException;
        JavaPlatform.setExceptionCause(this, anException);
    
public voidsetSession(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL:

        this.session = session;
    
public static voidsetShouldPrintInternalException(boolean printException)
PUBLIC: Allows overiding of TopLink's exception chaining detection.

param
booleam printException - If printException is true, the TopLink-stored Internal exception will be included in a stack traceor in the exception message of a TopLinkException. If printException is false, the TopLink-stored Internal Exception will not be included in the stack trace or the exception message of TopLinkExceptions

        shouldPrintInternalException = new Boolean(printException);
    
public static booleanshouldPrintInternalException()
INTERNAL Check to see if the TopLink-stored internal exception should be printed in this a TopLinkException's stack trace. This method will check the static ShouldPrintInternalException variable and if it is not set, estimate based on the JDK version used.

        if (shouldPrintInternalException == null) {
            shouldPrintInternalException = new Boolean(JavaPlatform.shouldPrintInternalException());
        }
        return shouldPrintInternalException.booleanValue();
    
public java.lang.StringtoString()
INTERNAL:

        return getIndentationString() + ExceptionMessageGenerator.getHeader("ExceptionHeader") + getErrorCode() + "] (" + oracle.toplink.essentials.sessions.DatabaseLogin.getVersion() + "): " + getClass().getName() + getMessage();