jaxp/src/com/sun/org/apache/xpath/internal/XPathException.java
author lana
Tue, 18 Mar 2014 17:49:48 -0700
changeset 23377 2af1ddf102a4
parent 12457 c348e06f0e82
permissions -rw-r--r--
Merge
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
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: XPathException.java,v 1.3 2005/09/28 13:49:30 pvedula Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 * This class implements an exception object that all
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * XPath classes will throw in case of an error.  This class
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * extends TransformerException, and may hold other exceptions. In the
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * case of nested exceptions, printStackTrace will dump
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * all the traces of the nested exceptions, not just the trace
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * of this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * @xsl.usage general
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
public class XPathException extends TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
    static final long serialVersionUID = 4263549717619045963L;
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
  /** The home of the expression that caused the error.
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
   *  @serial  */
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
  Object m_styleNode = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
   * Get the stylesheet node from where this error originated.
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
   * @return The stylesheet node from where this error originated, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
  public Object getStylesheetNode()
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
    return m_styleNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
   * Set the stylesheet node from where this error originated.
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
   * @param styleNode The stylesheet node from where this error originated, or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
  public void setStylesheetNode(Object styleNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
    m_styleNode = styleNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  /** A nested exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   *  @serial   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
  protected Exception m_exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
   * Create an XPathException object that holds
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   * an error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   * @param message The error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  public XPathException(String message, ExpressionNode ex)
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
    super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    this.setLocator(ex);
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
    setStylesheetNode(getStylesheetNode(ex));
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * Create an XPathException object that holds
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   * an error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * @param message The error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  public XPathException(String message)
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   * Get the XSLT ElemVariable that this sub-expression references.  In order for
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * this to work, the SourceLocator must be the owning ElemTemplateElement.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   * @return The dereference to the ElemVariable, or null if not found.
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  public org.w3c.dom.Node getStylesheetNode(ExpressionNode ex)
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    ExpressionNode owner = getExpressionOwner(ex);
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    if (null != owner && owner instanceof org.w3c.dom.Node)
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
                return ((org.w3c.dom.Node)owner);
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    return null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   * Get the first non-Expression parent of this node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
   * @return null or first ancestor that is not an Expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
  protected ExpressionNode getExpressionOwner(ExpressionNode ex)
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
        ExpressionNode parent = ex.exprGetParent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
        while((null != parent) && (parent instanceof Expression))
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
                parent = parent.exprGetParent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
        return parent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
   * Create an XPathException object that holds
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
   * an error message and the stylesheet node that
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * the error originated from.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   * @param message The error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
   * @param styleNode The stylesheet node that the error originated from.
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
  public XPathException(String message, Object styleNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    m_styleNode = styleNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
   * Create an XPathException object that holds
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
   * an error message, the stylesheet node that
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   * the error originated from, and another exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
   * that caused this exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
   * @param message The error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
   * @param styleNode The stylesheet node that the error originated from.
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
   * @param e The exception that caused this exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
  public XPathException(String message, Node styleNode, Exception e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
    m_styleNode = styleNode;
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    this.m_exception = e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
   * Create an XPathException object that holds
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
   * an error message, and another exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
   * that caused this exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
   * @param message The error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
   * @param e The exception that caused this exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
  public XPathException(String message, Exception e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    super(message);
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
    this.m_exception = e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   * Print the the trace of methods from where the error
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   * originated.  This will trace all nested exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   * objects, as well as this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   * @param s The stream where the dump will be sent to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
  public void printStackTrace(java.io.PrintStream s)
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    if (s == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
      s = System.err;
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
      super.printStackTrace(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    catch (Exception e){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    Throwable exception = m_exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    for (int i = 0; (i < 10) && (null != exception); i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
      s.println("---------");
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
      exception.printStackTrace(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
      if (exception instanceof TransformerException)
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
        TransformerException se = (TransformerException) exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
        Throwable prev = exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
        exception = se.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        if (prev == exception)
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
   * Find the most contained message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
   * @return The error message of the originating exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
  public String getMessage()
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
    String lastMessage = super.getMessage();
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    Throwable exception = m_exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
    while (null != exception)
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
      String nextMessage = exception.getMessage();
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
      if (null != nextMessage)
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        lastMessage = nextMessage;
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
      if (exception instanceof TransformerException)
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        TransformerException se = (TransformerException) exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        Throwable prev = exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        exception = se.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
        if (prev == exception)
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
          break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
        exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    return (null != lastMessage) ? lastMessage : "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
   * Print the the trace of methods from where the error
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
   * originated.  This will trace all nested exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
   * objects, as well as this object.
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
   * @param s The writer where the dump will be sent to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
  public void printStackTrace(java.io.PrintWriter s)
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
    if (s == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
      s = new java.io.PrintWriter(System.err);
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
      super.printStackTrace(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    catch (Exception e){}
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
    boolean isJdk14OrHigher = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
    try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
        Throwable.class.getMethod("getCause", (Class[]) null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
        isJdk14OrHigher = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
    } catch (NoSuchMethodException nsme) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
        // do nothing
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
    // The printStackTrace method of the Throwable class in jdk 1.4
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    // and higher will include the cause when printing the backtrace.
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
    // The following code is only required when using jdk 1.3 or lower
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
    if (!isJdk14OrHigher) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
      Throwable exception = m_exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
      for (int i = 0; (i < 10) && (null != exception); i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
        s.println("---------");
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
        try
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
          exception.printStackTrace(s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
        catch (Exception e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
          s.println("Could not print stack trace...");
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
        if (exception instanceof TransformerException)
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
          TransformerException se = (TransformerException) exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
          Throwable prev = exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
          exception = se.getException();
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
          if (prev == exception)
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
            exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
            break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
          exception = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   *  Return the embedded exception, if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   *  Overrides javax.xml.transform.TransformerException.getException().
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
   *  @return The embedded exception, or null if there is none.
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
  public Throwable getException()
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
    return m_exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
}