/*
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package javax.xml.transform;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.CodeSigner;
import java.security.CodeSource;
import java.security.PermissionCollection;
import java.security.Permissions;
import java.security.PrivilegedAction;
import java.security.ProtectionDomain;
import java.util.Objects;
/**
* This class specifies an exceptional condition that occurred
* during the transformation process.
*/
public class TransformerException extends Exception {
private static final long serialVersionUID = 975798773772956428L;
/** Field locator specifies where the error occurred */
SourceLocator locator;
/**
* Method getLocator retrieves an instance of a SourceLocator
* object that specifies where an error occurred.
*
* @return A SourceLocator object, or null if none was specified.
*/
public SourceLocator getLocator() {
return this.locator;
}
/**
* Method setLocator sets an instance of a SourceLocator
* object that specifies where an error occurred.
*
* @param location A SourceLocator object, or null to clear the location.
*/
public void setLocator(SourceLocator location) {
this.locator = location;
}
/** Field containedException specifies a wrapped exception. May be null. */
Throwable containedException;
/**
* This method retrieves an exception that this exception wraps.
*
* @return An Throwable object, or null.
* @see #getCause
*/
public Throwable getException() {
return containedException;
}
/**
* 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 the cause, or null if unknown
*/
@Override
public Throwable getCause() {
return ((containedException == this)
? null
: containedException);
}
/**
* 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 #TransformerException(Throwable)} or
* {@link #TransformerException(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 #TransformerException(Throwable)} or
* {@link #TransformerException(String,Throwable)}, or this method has already
* been called on this throwable.
*/
@Override
public synchronized Throwable initCause(Throwable cause) {
if (this.containedException != null) {
throw new IllegalStateException("Can't overwrite cause");
}
if (cause == this) {
throw new IllegalArgumentException(
"Self-causation not permitted");
}
this.containedException = cause;
return this;
}
/**
* Create a new TransformerException.
*
* @param message The error or warning message.
*/
public TransformerException(String message) {
this(message, null, null);
}
/**
* Create a new TransformerException wrapping an existing exception.
*
* @param e The exception to be wrapped.
*/
public TransformerException(Throwable e) {
this(null, null, e);
}
/**
* Wrap an existing exception in a TransformerException.
*
*
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 */ public TransformerException(String message, Throwable e) { this(message, null, e); } /** * Create a new TransformerException 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. */ public TransformerException(String message, SourceLocator locator) { this(message, locator, null); } /** * Wrap an existing exception in a TransformerException. * * @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 */ public TransformerException(String message, SourceLocator locator, Throwable e) { super(((message == null) || (message.length() == 0)) ? ((e == null) ? "" : e.toString()) : message); this.containedException = e; this.locator = locator; } /** * Get the error message with location information * appended. * * @return AString
representing the error message with
* location information appended.
*/
public String getMessageAndLocation() {
StringBuilder sbuffer = new StringBuilder();
sbuffer.append(Objects.toString(super.getMessage(), ""));
sbuffer.append(Objects.toString(getLocationAsString(), ""));
return sbuffer.toString();
}
/**
* Get the location information as a string.
*
* @return A string with location info, or null
* if there is no location information.
*/
public String getLocationAsString() {
if (locator == null) {
return null;
}
if (System.getSecurityManager() == null) {
return getLocationString();
} else {
return (String) AccessController.doPrivileged(
new PrivilegedAction