KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > vfs > FileSystemException


1 /*
2  * Copyright 2002-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.vfs;
17
18 import org.apache.commons.vfs.util.Messages;
19
20 import java.io.IOException JavaDoc;
21
22 /**
23  * Thrown for file system errors.
24  *
25  * @author <a HREF="mailto:adammurdoch@apache.org">Adam Murdoch</a>
26  */

27 public final class FileSystemException
28     extends IOException JavaDoc
29 {
30     /**
31      * The Throwable that caused this exception to be thrown.
32      */

33     private final Throwable JavaDoc throwable;
34
35     /**
36      * The message code.
37      */

38     private final String JavaDoc code;
39
40     /**
41      * array of complementary info (context).
42      */

43     private final String JavaDoc[] info;
44
45     /**
46      * Constructs exception with the specified detail message.
47      *
48      * @param code the error code of the message.
49      */

50     public FileSystemException(final String JavaDoc code)
51     {
52         this(code, null, null);
53     }
54
55     /**
56      * Constructs exception with the specified detail message.
57      *
58      * @param code the error code of the message.
59      * @param info0 one context information.
60      */

61     public FileSystemException(final String JavaDoc code, final Object JavaDoc info0)
62     {
63         this(code, new Object JavaDoc[]{info0}, null);
64     }
65
66     /**
67      * Constructs exception with the specified detail message.
68      *
69      * @param code the error code of the message.
70      * @param info0 one context information.
71      * @param throwable the cause.
72      */

73     public FileSystemException(final String JavaDoc code,
74                                final Object JavaDoc info0,
75                                final Throwable JavaDoc throwable)
76     {
77         this(code, new Object JavaDoc[]{info0}, throwable);
78     }
79
80     /**
81      * Constructs exception with the specified detail message.
82      *
83      * @param code the error code of the message.
84      * @param info array of complementary info (context).
85      */

86     public FileSystemException(final String JavaDoc code, final Object JavaDoc[] info)
87     {
88         this(code, info, null);
89     }
90
91     /**
92      * Constructs exception with the specified detail message.
93      *
94      * @param code the error code of the message.
95      * @param info array of complementary info (context).
96      * @param throwable the cause.
97      */

98     public FileSystemException(final String JavaDoc code,
99                                final Object JavaDoc[] info,
100                                final Throwable JavaDoc throwable)
101     {
102         super(Messages.getString(code, info));
103
104         if (info == null)
105         {
106             this.info = new String JavaDoc[0];
107         }
108         else
109         {
110             this.info = new String JavaDoc[info.length];
111             for (int i = 0; i < info.length; i++)
112             {
113                 this.info[i] = String.valueOf(info[i]);
114             }
115         }
116         this.code = code;
117         this.throwable = throwable;
118     }
119
120     /**
121      * Constructs wrapper exception.
122      *
123      * @param throwable the root cause to wrap.
124      */

125     public FileSystemException(final Throwable JavaDoc throwable)
126     {
127         this(throwable.getMessage(), null, throwable);
128     }
129
130     /**
131      * Retrieve root cause of the exception.
132      *
133      * @return the root cause
134      */

135     public final Throwable JavaDoc getCause()
136     {
137         return throwable;
138     }
139
140     /**
141      * Retrieve error code of the exception.
142      * Could be used as key for internationalization.
143      *
144      * @return the code.
145      */

146     public String JavaDoc getCode()
147     {
148         return code;
149     }
150
151     /**
152      * Retrieve array of complementary info (context).
153      * Could be used as parameter for internationalization.
154      *
155      * @return the context info.
156      */

157     public String JavaDoc[] getInfo()
158     {
159         return info;
160     }
161 }
162
Popular Tags