jaxp/src/share/classes/javax/xml/transform/TransformerException.java
author ohair
Mon, 14 Apr 2008 14:52:27 -0700
changeset 311 3c14f21bf3f7
parent 6 7f561c08de6b
permissions -rw-r--r--
6484686: The next directory looks like it is no longer part of the build (deploy makefiles) Summary: Getting rid of the _OUTPUTDIR settings. Using BUILD_PARENT_DIRECTORY instead. This solves problems with the "/build/windows-i586*" paths getting mangled on Windows builds (fastdebug builds in particular). Reviewed-by: tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 * have any questions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
package javax.xml.transform;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import java.lang.reflect.Method;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import java.lang.reflect.InvocationTargetException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * This class specifies an exceptional condition that occured
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * during the transformation process.
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
public class TransformerException extends Exception {
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
    /** Field locator specifies where the error occured */
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
    SourceLocator locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
     * Method getLocator retrieves an instance of a SourceLocator
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
     * object that specifies where an error occured.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
     * @return A SourceLocator object, or null if none was specified.
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    public SourceLocator getLocator() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
        return locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
     * Method setLocator sets an instance of a SourceLocator
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
     * object that specifies where an error occured.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
     * @param location A SourceLocator object, or null to clear the location.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    public void setLocator(SourceLocator location) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
        locator = location;
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
    /** Field containedException specifies a wrapped exception.  May be null. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    Throwable containedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
     * This method retrieves an exception that this exception wraps.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
     * @return An Throwable object, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
     * @see #getCause
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    public Throwable getException() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
        return containedException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     * Returns the cause of this throwable or <code>null</code> if the
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     * cause is nonexistent or unknown.  (The cause is the throwable that
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
     * caused this throwable to get thrown.)
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    public Throwable getCause() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
        return ((containedException == this)
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
                ? null
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
                : containedException);
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
     * Initializes the <i>cause</i> of this throwable to the specified value.
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
     * (The cause is the throwable that caused this throwable to get thrown.)
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     * <p>This method can be called at most once.  It is generally called from
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     * within the constructor, or immediately after creating the
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
     * throwable.  If this throwable was created
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     * with {@link #TransformerException(Throwable)} or
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     * {@link #TransformerException(String,Throwable)}, this method cannot be called
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     * even once.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
     * @param  cause the cause (which is saved for later retrieval by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
     *         {@link #getCause()} method).  (A <code>null</code> value is
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     *         permitted, and indicates that the cause is nonexistent or
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
     *         unknown.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     * @return  a reference to this <code>Throwable</code> instance.
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
     * @throws IllegalArgumentException if <code>cause</code> is this
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
     *         throwable.  (A throwable cannot
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     *         be its own cause.)
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
     * @throws IllegalStateException if this throwable was
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
     *         created with {@link #TransformerException(Throwable)} or
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
     *         {@link #TransformerException(String,Throwable)}, or this method has already
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
     *         been called on this throwable.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    public synchronized Throwable initCause(Throwable cause) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        if (this.containedException != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
            throw new IllegalStateException("Can't overwrite cause");
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
        if (cause == this) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
            throw new IllegalArgumentException(
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
                "Self-causation not permitted");
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        this.containedException = cause;
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        return this;
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
     * Create a new TransformerException.
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * @param message The error or warning message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
    public TransformerException(String message) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
        super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
        this.containedException = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        this.locator            = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * Create a new TransformerException wrapping an existing exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     * @param e The exception to be wrapped.
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    public TransformerException(Throwable e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
        super(e.toString());
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
        this.containedException = e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
        this.locator            = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     * Wrap an existing exception in a TransformerException.
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
     * <p>This is used for throwing processor exceptions before
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
     * the processing has started.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     * @param message The error or warning message, or null to
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     *                use the message from the embedded exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     * @param e Any exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
    public TransformerException(String message, Throwable e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
        super(((message == null) || (message.length() == 0))
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
              ? e.toString()
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
              : message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
        this.containedException = e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
        this.locator            = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     * Create a new TransformerException from a message and a Locator.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
     * <p>This constructor is especially useful when an application is
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
     * creating its own exception from within a DocumentHandler
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
     * callback.</p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     * @param message The error or warning message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
     * @param locator The locator object for the error or warning.
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    public TransformerException(String message, SourceLocator locator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
        super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        this.containedException = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        this.locator            = locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     * Wrap an existing exception in a TransformerException.
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     * @param message The error or warning message, or null to
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
     *                use the message from the embedded exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     * @param locator The locator object for the error or warning.
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
     * @param e Any exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    public TransformerException(String message, SourceLocator locator,
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
                                Throwable e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        this.containedException = e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
        this.locator            = locator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
     * Get the error message with location information
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
     * appended.
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
     * @return A <code>String</code> representing the error message with
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
     *         location information appended.
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    public String getMessageAndLocation() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        StringBuffer sbuffer = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        String       message = super.getMessage();
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        if (null != message) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
            sbuffer.append(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
        if (null != locator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
            String systemID = locator.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
            int    line     = locator.getLineNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            int    column   = locator.getColumnNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
            if (null != systemID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
                sbuffer.append("; SystemID: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
                sbuffer.append(systemID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
            if (0 != line) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
                sbuffer.append("; Line#: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
                sbuffer.append(line);
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
            if (0 != column) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
                sbuffer.append("; Column#: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
                sbuffer.append(column);
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
        return sbuffer.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
     * Get the location information as a string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
     * @return A string with location info, or null
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
     * if there is no location information.
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
    public String getLocationAsString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
        if (null != locator) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            StringBuffer sbuffer  = new StringBuffer();
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
            String       systemID = locator.getSystemId();
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
            int          line     = locator.getLineNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
            int          column   = locator.getColumnNumber();
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
            if (null != systemID) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
                sbuffer.append("; SystemID: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
                sbuffer.append(systemID);
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
            if (0 != line) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
                sbuffer.append("; Line#: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
                sbuffer.append(line);
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
            if (0 != column) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                sbuffer.append("; Column#: ");
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                sbuffer.append(column);
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
            return sbuffer.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
        } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
            return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
     * Print the the trace of methods from where the error
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
     * originated.  This will trace all nested exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
     * objects, as well as this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
    public void printStackTrace() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        printStackTrace(new java.io.PrintWriter(System.err, true));
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
     * Print the the trace of methods from where the error
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
     * originated.  This will trace all nested exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
     * objects, as well as this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
     * @param s The stream where the dump will be sent to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    public void printStackTrace(java.io.PrintStream s) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
        printStackTrace(new java.io.PrintWriter(s));
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
     * Print the the trace of methods from where the error
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
     * originated.  This will trace all nested exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
     * objects, as well as this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
     * @param s The writer where the dump will be sent to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    public void printStackTrace(java.io.PrintWriter s) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
        if (s == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
            s = new java.io.PrintWriter(System.err, true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
            String locInfo = getLocationAsString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
            if (null != locInfo) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
                s.println(locInfo);
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
            super.printStackTrace(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
        } catch (Throwable e) {}
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
        Throwable exception = getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
        for (int i = 0; (i < 10) && (null != exception); i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
            s.println("---------");
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
                if (exception instanceof TransformerException) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
                    String locInfo =
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
                        ((TransformerException) exception)
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
                            .getLocationAsString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
                    if (null != locInfo) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
                        s.println(locInfo);
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
                exception.printStackTrace(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
            } catch (Throwable e) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
                s.println("Could not print stack trace...");
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
            try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
                Method meth =
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
                    ((Object) exception).getClass().getMethod("getException",
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
                        (Class[]) null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
                if (null != meth) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
                    Throwable prev = exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
                    exception = (Throwable) meth.invoke(exception, (Object[]) null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
                    if (prev == exception) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
                } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
                    exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
            } catch (InvocationTargetException ite) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
                exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
            } catch (IllegalAccessException iae) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
                exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
            } catch (NoSuchMethodException nsme) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
                exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
        // insure output is written
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
        s.flush();
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
}