001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.persistence;
020:
021: import java.io.IOException;
022: import java.io.ObjectInputStream;
023: import java.io.ObjectOutputStream;
024: import java.io.PrintStream;
025: import java.io.PrintWriter;
026: import java.io.Serializable;
027:
028: import org.apache.openjpa.util.ExceptionInfo;
029: import org.apache.openjpa.util.Exceptions;
030:
031: import org.apache.openjpa.lib.util.Localizer.Message;
032:
033: /**
034: * Extended {@link IllegalArgumentException}.
035: *
036: * @author Abe White
037: * @since 0.4.0
038: * @nojavadoc
039: */
040: public class ArgumentException extends IllegalArgumentException
041: implements Serializable, ExceptionInfo {
042:
043: private transient boolean _fatal = false;
044: private transient Object _failed = null;
045: private transient Throwable[] _nested = null;
046:
047: public ArgumentException(String msg, Throwable[] nested,
048: Object failed, boolean fatal) {
049: super (msg);
050: _nested = nested;
051: _failed = failed;
052: _fatal = fatal;
053: }
054:
055: public ArgumentException(Message msg, Throwable[] nested,
056: Object failed, boolean fatal) {
057: this (msg.getMessage(), nested, failed, fatal);
058: }
059:
060: public int getType() {
061: return USER;
062: }
063:
064: public int getSubtype() {
065: return 0;
066: }
067:
068: public boolean isFatal() {
069: return _fatal;
070: }
071:
072: public Throwable getCause() {
073: return PersistenceExceptions.getCause(_nested);
074: }
075:
076: public Throwable[] getNestedThrowables() {
077: return (_nested == null) ? Exceptions.EMPTY_THROWABLES
078: : _nested;
079: }
080:
081: public Object getFailedObject() {
082: return _failed;
083: }
084:
085: public String toString() {
086: return Exceptions.toString(this );
087: }
088:
089: public void printStackTrace() {
090: printStackTrace(System.err);
091: }
092:
093: public void printStackTrace(PrintStream out) {
094: super .printStackTrace(out);
095: Exceptions.printNestedThrowables(this , out);
096: }
097:
098: public void printStackTrace(PrintWriter out) {
099: super .printStackTrace(out);
100: Exceptions.printNestedThrowables(this , out);
101: }
102:
103: private void writeObject(ObjectOutputStream out) throws IOException {
104: out.writeBoolean(_fatal);
105: out.writeObject(Exceptions.replaceFailedObject(_failed));
106: out.writeObject(Exceptions.replaceNestedThrowables(_nested));
107: }
108:
109: private void readObject(ObjectInputStream in) throws IOException,
110: ClassNotFoundException {
111: _fatal = in.readBoolean();
112: _failed = in.readObject();
113: _nested = (Throwable[]) in.readObject();
114: }
115: }
|