FileDocCategorySizeDatePackage
DTMException.javaAPI DocJava SE 6 API12032Tue Jun 10 00:22:56 BST 2008com.sun.org.apache.xml.internal.dtm

DTMException

public class DTMException extends RuntimeException
This class specifies an exceptional condition that occured in the DTM module.

Fields Summary
static final long
serialVersionUID
SourceLocator
locator
Field locator specifies where the error occured.
Throwable
containedException
Field containedException specifies a wrapped exception. May be null.
Constructors Summary
public DTMException(String message, SourceLocator locator, Throwable e)
Wrap an existing exception in a DTMException.

param
message The error or warning message, or null to use the message from the embedded exception.
param
locator The locator object for the error or warning.
param
e Any exception


        super(message);

        this.containedException = e;
        this.locator            = locator;
    
public DTMException(String message)
Create a new DTMException.

param
message The error or warning message.


        super(message);

        this.containedException = null;
        this.locator            = null;
    
public DTMException(Throwable e)
Create a new DTMException wrapping an existing exception.

param
e The exception to be wrapped.


        super(e.getMessage());

        this.containedException = e;
        this.locator            = null;
    
public DTMException(String message, Throwable e)
Wrap an existing exception in a DTMException.

This is used for throwing processor exceptions before the processing has started.

param
message The error or warning message, or null to use the message from the embedded exception.
param
e Any exception


        super(((message == null) || (message.length() == 0))
              ? e.getMessage()
              : message);

        this.containedException = e;
        this.locator            = null;
    
public DTMException(String message, SourceLocator locator)
Create a new DTMException from a message and a Locator.

This constructor is especially useful when an application is creating its own exception from within a DocumentHandler callback.

param
message The error or warning message.
param
locator The locator object for the error or warning.


        super(message);

        this.containedException = null;
        this.locator            = locator;
    
Methods Summary
public java.lang.ThrowablegetCause()
Returns the cause of this throwable or null if the cause is nonexistent or unknown. (The cause is the throwable that caused this throwable to get thrown.)


        return ((containedException == this)
                ? null
                : containedException);
    
public java.lang.ThrowablegetException()
This method retrieves an exception that this exception wraps.

return
An Throwable object, or null.
see
#getCause

        return containedException;
    
public java.lang.StringgetLocationAsString()
Get the location information as a string.

return
A string with location info, or null if there is no location information.


        if (null != locator) {
            StringBuffer sbuffer  = new StringBuffer();
            String       systemID = locator.getSystemId();
            int          line     = locator.getLineNumber();
            int          column   = locator.getColumnNumber();

            if (null != systemID) {
                sbuffer.append("; SystemID: ");
                sbuffer.append(systemID);
            }

            if (0 != line) {
                sbuffer.append("; Line#: ");
                sbuffer.append(line);
            }

            if (0 != column) {
                sbuffer.append("; Column#: ");
                sbuffer.append(column);
            }

            return sbuffer.toString();
        } else {
            return null;
        }
    
public javax.xml.transform.SourceLocatorgetLocator()
Method getLocator retrieves an instance of a SourceLocator object that specifies where an error occured.

return
A SourceLocator object, or null if none was specified.


                                  
       
        return locator;
    
public java.lang.StringgetMessageAndLocation()
Get the error message with location information appended.


        StringBuffer sbuffer = new StringBuffer();
        String       message = super.getMessage();

        if (null != message) {
            sbuffer.append(message);
        }

        if (null != locator) {
            String systemID = locator.getSystemId();
            int    line     = locator.getLineNumber();
            int    column   = locator.getColumnNumber();

            if (null != systemID) {
                sbuffer.append("; SystemID: ");
                sbuffer.append(systemID);
            }

            if (0 != line) {
                sbuffer.append("; Line#: ");
                sbuffer.append(line);
            }

            if (0 != column) {
                sbuffer.append("; Column#: ");
                sbuffer.append(column);
            }
        }

        return sbuffer.toString();
    
public synchronized java.lang.ThrowableinitCause(java.lang.Throwable cause)
Initializes the cause of this throwable to the specified value. (The cause is the throwable that caused this throwable to get thrown.)

This method can be called at most once. It is generally called from within the constructor, or immediately after creating the throwable. If this throwable was created with {@link #DTMException(Throwable)} or {@link #DTMException(String,Throwable)}, this method cannot be called even once.

param
cause the cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
return
a reference to this Throwable instance.
throws
IllegalArgumentException if cause is this throwable. (A throwable cannot be its own cause.)
throws
IllegalStateException if this throwable was created with {@link #DTMException(Throwable)} or {@link #DTMException(String,Throwable)}, or this method has already been called on this throwable.


        if ((this.containedException == null) && (cause != null)) {
            throw new IllegalStateException(XMLMessages.createXMLMessage(XMLErrorResources.ER_CANNOT_OVERWRITE_CAUSE, null)); //"Can't overwrite cause");
        }

        if (cause == this) {
            throw new IllegalArgumentException(
                XMLMessages.createXMLMessage(XMLErrorResources.ER_SELF_CAUSATION_NOT_PERMITTED, null)); //"Self-causation not permitted");
        }

        this.containedException = cause;

        return this;
    
public voidprintStackTrace()
Print the the trace of methods from where the error originated. This will trace all nested exception objects, as well as this object.

        printStackTrace(new java.io.PrintWriter(System.err, true));
    
public voidprintStackTrace(java.io.PrintStream s)
Print the the trace of methods from where the error originated. This will trace all nested exception objects, as well as this object.

param
s The stream where the dump will be sent to.

        printStackTrace(new java.io.PrintWriter(s));
    
public voidprintStackTrace(java.io.PrintWriter s)
Print the the trace of methods from where the error originated. This will trace all nested exception objects, as well as this object.

param
s The writer where the dump will be sent to.


        if (s == null) {
            s = new java.io.PrintWriter(System.err, true);
        }

        try {
            String locInfo = getLocationAsString();

            if (null != locInfo) {
                s.println(locInfo);
            }

            super.printStackTrace(s);
        } catch (Throwable e) {}

        boolean isJdk14OrHigher = false;
        try {
            Throwable.class.getMethod("getCause", (Class[]) null);
            isJdk14OrHigher = true;
        } catch (NoSuchMethodException nsme) {
            // do nothing
        }        

        // The printStackTrace method of the Throwable class in jdk 1.4 
        // and higher will include the cause when printing the backtrace.
        // The following code is only required when using jdk 1.3 or lower                
        if (!isJdk14OrHigher) {
            Throwable exception = getException();
    
            for (int i = 0; (i < 10) && (null != exception); i++) {
                s.println("---------");
    
                try {
                    if (exception instanceof DTMException) {
                        String locInfo =
                            ((DTMException) exception)
                                .getLocationAsString();
    
                        if (null != locInfo) {
                            s.println(locInfo);
                        }
                    }
    
                    exception.printStackTrace(s);
                } catch (Throwable e) {
                    s.println("Could not print stack trace...");
                }
    
                try {
                    Method meth =
                        ((Object) exception).getClass().getMethod("getException",
                            (Class[]) null);
    
                    if (null != meth) {
                        Throwable prev = exception;
    
                        exception = (Throwable) meth.invoke(exception, (Object[]) null);
    
                        if (prev == exception) {
                            break;
                        }
                    } else {
                        exception = null;
                    }
                } catch (InvocationTargetException ite) {
                    exception = null;
                } catch (IllegalAccessException iae) {
                    exception = null;
                } catch (NoSuchMethodException nsme) {
                    exception = null;
                }
            }
        }
    
public voidsetLocator(javax.xml.transform.SourceLocator location)
Method setLocator sets an instance of a SourceLocator object that specifies where an error occured.

param
location A SourceLocator object, or null to clear the location.

        locator = location;