View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.commons.vfs;
    18
    19  import org.apache.commons.vfs.util.Messages;
    20
    21  import java.io.IOException;
    22
    23  /***
    24   * Thrown for file system errors.
    25   *
    26   * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
    27   * @version $Revision: 480428 $ $Date: 2006-11-29 07:15:24 +0100 (Mi, 29 Nov 2006) $
    28   */
    29  public class FileSystemException
    30      extends IOException
    31  {
    32      /***
    33       * The Throwable that caused this exception to be thrown.
    34       */
    35      private final Throwable throwable;
    36
    37      /***
    38       * The message code.
    39       */
    40      private final String code;
    41
    42      /***
    43       * array of complementary info (context).
    44       */
    45      private final String[] info;
    46
    47      /***
    48       * Constructs exception with the specified detail message.
    49       *
    50       * @param code the error code of the message.
    51       */
    52      public FileSystemException(final String code)
    53      {
    54          this(code, null, null);
    55      }
    56
    57      /***
    58       * Constructs exception with the specified detail message.
    59       *
    60       * @param code  the error code of the message.
    61       * @param info0 one context information.
    62       */
    63      public FileSystemException(final String code, final Object info0)
    64      {
    65          this(code, new Object[]{info0}, null);
    66      }
    67
    68      /***
    69       * Constructs exception with the specified detail message.
    70       *
    71       * @param code      the error code of the message.
    72       * @param info0     one context information.
    73       * @param throwable the cause.
    74       */
    75      public FileSystemException(final String code,
    76                                 final Object info0,
    77                                 final Throwable throwable)
    78      {
    79          this(code, new Object[]{info0}, throwable);
    80      }
    81
    82      /***
    83       * Constructs exception with the specified detail message.
    84       *
    85       * @param code the error code of the message.
    86       * @param info array of complementary info (context).
    87       */
    88      public FileSystemException(final String code, final Object[] info)
    89      {
    90          this(code, info, null);
    91      }
    92
    93      /***
    94       * Constructs exception with the specified detail message.
    95       *
    96       * @param code the error code of the message.
    97       * @param info array of complementary info (context).
    98       */
    99      public FileSystemException(final String code, final Throwable throwable)
    100     {
    101         this(code, null, throwable);
    102     }
    103
    104     /***
    105      * Constructs exception with the specified detail message.
    106      *
    107      * @param code      the error code of the message.
    108      * @param info      array of complementary info (context).
    109      * @param throwable the cause.
    110      */
    111     public FileSystemException(final String code,
    112                                final Object[] info,
    113                                final Throwable throwable)
    114     {
    115         super(code);
    116
    117         if (info == null)
    118         {
    119             this.info = new String[0];
    120         }
    121         else
    122         {
    123             this.info = new String[info.length];
    124             for (int i = 0; i < info.length; i++)
    125             {
    126                 this.info[i] = String.valueOf(info[i]);
    127             }
    128         }
    129         this.code = code;
    130         this.throwable = throwable;
    131     }
    132
    133     /***
    134      * retrieve message from bundle
    135      */
    136     public String getMessage()
    137 	{
    138     	return Messages.getString(super.getMessage(), getInfo());
    139 	}
    140
    141 	/***
    142      * Constructs wrapper exception.
    143      *
    144      * @param throwable the root cause to wrap.
    145      */
    146     public FileSystemException(final Throwable throwable)
    147     {
    148         this(throwable.getMessage(), null, throwable);
    149     }
    150
    151     /***
    152      * Retrieve root cause of the exception.
    153      *
    154      * @return the root cause
    155      */
    156     public final Throwable getCause()
    157     {
    158         return throwable;
    159     }
    160
    161     /***
    162      * Retrieve error code of the exception.
    163      * Could be used as key for internationalization.
    164      *
    165      * @return the code.
    166      */
    167     public String getCode()
    168     {
    169         return code;
    170     }
    171
    172     /***
    173      * Retrieve array of complementary info (context).
    174      * Could be used as parameter for internationalization.
    175      *
    176      * @return the context info.
    177      */
    178     public String[] getInfo()
    179     {
    180         return info;
    181     }
    182 }