001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2001,2002 Marcus Stursberg
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.compiler;
023:
024: /**
025: * Indicates a Failure to compile.
026: *
027: * @author Marcus Stursberg
028: */
029: public class CompilerException extends java.io.IOException {
030:
031: static final long serialVersionUID = 6247426753392546734L;
032:
033: /**
034: * The throwable that caused this throwable to get thrown, or null if this throwable was not
035: * caused by another throwable, or if the causative throwable is unknown. If this field is equal
036: * to this throwable itself, it indicates that the cause of this throwable has not yet been
037: * initialized.
038: */
039: private Throwable _cause = this ;
040:
041: /**
042: * Construct a new exception with the specified message.
043: *
044: * @param message Description of the error
045: */
046: public CompilerException(String message) {
047: super (message);
048: }
049:
050: /**
051: * Construct a new exception with the specified message and wraps another cause.
052: *
053: * @param message Description of the error
054: * @param cause Throwable
055: */
056: public CompilerException(String message, Throwable cause) {
057: super (message);
058: this ._cause = cause;
059: }
060:
061: /**
062: * Initializes the <i>cause</i> of this throwable to the specified value. (The cause is the
063: * throwable that caused this throwable to get thrown.)
064: *
065: * <p>
066: * This method can be called at most once. It is generally called from within the constructor,
067: * or immediately after creating the throwable. If this throwable was created with {@link
068: * #CompilerException(String,Throwable)}, this method cannot be called even once.
069: *
070: * @param cause the cause (which is saved for later retrieval by the {@link #getCause()}
071: * method). (A <code>null</code> value is permitted, and indicates that the cause is
072: * nonexistent or unknown.)
073: * @return a reference to this <code>Throwable</code> instance.
074: * @throws IllegalArgumentException if <code>cause</code> is this throwable. (A throwable
075: * cannot be its own cause.)
076: * @throws IllegalStateException if this throwable was created with {@link
077: * #CompilerException(String,Throwable)}, or this method has already been called on this
078: * throwable.
079: */
080: public synchronized Throwable initCause(Throwable cause) {
081: if (this ._cause != this )
082: throw new IllegalStateException("Can't overwrite cause");
083: if (cause == this )
084: throw new IllegalArgumentException(
085: "Self-causation not permitted");
086: this ._cause = cause;
087: return this ;
088: }
089:
090: /**
091: * Returns the cause of this throwable or <code>null</code> if the cause is nonexistent or
092: * unknown. (The cause is the throwable that caused this throwable to get thrown.)
093: *
094: * <p>
095: * This implementation returns the cause that was supplied via one of the constructors requiring
096: * a <code>Throwable</code>, or that was set after creation with the
097: * {@link #initCause(Throwable)} method. While it is typically unnecessary to override this
098: * method, a subclass can override it to return a cause set by some other means. This is
099: * appropriate for a "legacy chained throwable" that predates the addition of chained exceptions
100: * to <code>Throwable</code>. Note that it is <i>not</i> necessary to override any of the
101: * <code>PrintStackTrace</code> methods, all of which invoke the <code>getCause</code>
102: * method to determine the cause of a throwable.
103: *
104: * @return the cause of this throwable or <code>null</code> if the cause is nonexistent or
105: * unknown.
106: */
107: public Throwable getCause() {
108: return (_cause == this ? null : _cause);
109: }
110: }
|