Home » apache-openjpa-1.1.0-source » org.apache.openjpa » persistence » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    * http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.    
   18    */
   19   package org.apache.openjpa.persistence;
   20   
   21   import java.io.IOException;
   22   import java.io.ObjectInputStream;
   23   import java.io.ObjectOutputStream;
   24   import java.io.PrintStream;
   25   import java.io.PrintWriter;
   26   import java.io.Serializable;
   27   
   28   import org.apache.openjpa.util.ExceptionInfo;
   29   import org.apache.openjpa.util.Exceptions;
   30   
   31   import org.apache.openjpa.lib.util.Localizer.Message;
   32   
   33   /**
   34    * Extended {@link IllegalArgumentException}.
   35    *
   36    * @author Abe White
   37    * @since 0.4.0
   38    * @nojavadoc
   39    */
   40   public class ArgumentException
   41       extends IllegalArgumentException
   42       implements Serializable, ExceptionInfo {
   43   
   44       private transient boolean _fatal = false;
   45       private transient Object _failed = null;
   46       private transient Throwable[] _nested = null;
   47   
   48       public ArgumentException(String msg, Throwable[] nested, Object failed,
   49           boolean fatal) {
   50           super(msg);
   51           _nested = nested;
   52           _failed = failed;
   53           _fatal = fatal;
   54       }
   55   
   56       public ArgumentException(Message msg, Throwable[] nested, Object failed,
   57           boolean fatal) {
   58           this(msg.getMessage(), nested, failed, fatal);
   59       }
   60   
   61       public int getType() {
   62           return USER;
   63       }
   64   
   65       public int getSubtype() {
   66           return 0;
   67       }
   68   
   69       public boolean isFatal() {
   70           return _fatal;
   71       }
   72   
   73       public Throwable getCause() {
   74           return PersistenceExceptions.getCause(_nested);
   75       }
   76   
   77       public Throwable[] getNestedThrowables() {
   78           return (_nested == null) ? Exceptions.EMPTY_THROWABLES : _nested;
   79       }
   80   
   81       public Object getFailedObject() {
   82           return _failed;
   83       }
   84   
   85       public String toString() {
   86           return Exceptions.toString(this);
   87       }
   88   
   89       public void printStackTrace() {
   90           printStackTrace(System.err);
   91       }
   92   
   93       public void printStackTrace(PrintStream out) {
   94           super.printStackTrace(out);
   95           Exceptions.printNestedThrowables(this, out);
   96       }
   97   
   98       public void printStackTrace(PrintWriter out) {
   99           super.printStackTrace(out);
  100           Exceptions.printNestedThrowables(this, out);
  101       }
  102   
  103       private void writeObject(ObjectOutputStream out)
  104           throws IOException {
  105           out.writeBoolean(_fatal);
  106           out.writeObject(Exceptions.replaceFailedObject(_failed));
  107           out.writeObject(Exceptions.replaceNestedThrowables(_nested));
  108       }
  109   
  110       private void readObject(ObjectInputStream in)
  111           throws IOException, ClassNotFoundException {
  112           _fatal = in.readBoolean();
  113           _failed = in.readObject();
  114           _nested = (Throwable[]) in.readObject();
  115       }
  116   }
  117   

Save This Page
Home » apache-openjpa-1.1.0-source » org.apache.openjpa » persistence » [javadoc | source]