001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.uml.common;
043:
044: import java.io.*;
045:
046: /**
047: * General Exception class for errors thrown in the application.
048: */
049: public class ETException extends Exception {
050:
051: /** Constructor. Wraps a regular exception. */
052: public ETException(Throwable exc) {
053: this (ETStrings.E_CMN_UNEXPECTED_EXC, exc.getMessage());
054: iException = exc;
055: }
056:
057: /** Constructor. Wraps a ETException. */
058: public ETException(ETException exc) {
059: setMessage(exc.getMessage());
060: iErrorID = ((ETException) exc).iErrorID;
061: iException = exc;
062: }
063:
064: /** Constructor. Creates an exception with the specified message ID. */
065: public ETException(MsgID ID) {
066: setMessage(ID.get());
067: iErrorID = ID.getID();
068: }
069:
070: /** Constructor. Creates an exception with the specified message ID.
071: The occurences of %x are replaced by the given parameters.*/
072: public ETException(MsgID ID, Object p1) {
073: setMessage(ID.get(p1));
074: iErrorID = ID.getID();
075: }
076:
077: /** Constructor. Creates an exception with the specified message ID.
078: The occurences of %x are replaced by the given parameters.*/
079: public ETException(MsgID ID, Object p1, Object p2) {
080: setMessage(ID.get(p1, p2));
081: iErrorID = ID.getID();
082: }
083:
084: /** Constructor. Creates an exception with the specified message ID.
085: The occurences of %x are replaced by the given parameters.*/
086: public ETException(MsgID ID, Object p1, Object p2, Object p3) {
087: setMessage(ID.get(p1, p2, p3));
088: iErrorID = ID.getID();
089: }
090:
091: /** Constructor. Creates an exception with the specified message ID.
092: The occurences of %x are replaced by the given parameters.*/
093: public ETException(MsgID ID, Object p1, Object p2, Object p3,
094: Object p4) {
095: setMessage(ID.get(p1, p2, p3, p4));
096: iErrorID = ID.getID();
097: }
098:
099: /** Constructor. Creates an exception with the specified message ID.
100: The occurences of %x are replaced by the given parameters.*/
101: public ETException(MsgID ID, Object[] params) {
102: setMessage(ID.get(params));
103: iErrorID = ID.getID();
104: }
105:
106: /** This method gets the message ID for the current ETException object.
107: @return the ID representing the message that corresponds to the ETException object. */
108: public String getErrorID() {
109: return iErrorID;
110: }
111:
112: /** Overrides the error ID for this exception. */
113: protected void setErrorID(String ID) {
114: iErrorID = ID;
115: }
116:
117: /** Local independent error ID.
118: @serial */
119: private String iErrorID;
120:
121: /** Overrides getMessage to return the locale dependant message. */
122: public String getMessage() {
123: return iMessage;
124: }
125:
126: /** Sets the message to be displayed to the user. */
127: protected void setMessage(String msg) {
128: iMessage = msg;
129: }
130:
131: public void printStackTrace() {
132:
133: if (iException != null) {
134: iException.printStackTrace();
135: ETSystem.out.println("\nException wrapped in\n\n");
136: }
137: }
138:
139: public void printStackTrace(PrintStream s) {
140:
141: if (iException != null) {
142: iException.printStackTrace(s);
143: s.println("\nException wrapped in\n\n");
144: }
145: }
146:
147: public void printStackTrace(PrintWriter s) {
148:
149: if (iException != null) {
150: iException.printStackTrace(s);
151: s.println("\nException wrapped in\n\n");
152: }
153: }
154:
155: /** Local dependent message.
156: @serial */
157: private String iMessage = "";
158: private Throwable iException;
159:
160: }
|