KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openide > filesystems > FSException


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.openide.filesystems;
20
21 import java.io.IOException JavaDoc;
22 import org.openide.util.Exceptions;
23
24
25 /** Localized IOException for filesystems.
26 *
27 * @author Jaroslav Tulach
28 */

29 final class FSException extends IOException JavaDoc {
30     /** name of resource to use for localized message */
31
32     // private String resource;
33

34     /** arguments to pass to the resource */
35     private Object JavaDoc[] args;
36
37     /** Creates new FSException. */
38     private FSException(String JavaDoc resource, Object JavaDoc[] args) {
39         super(resource);
40         this.args = args;
41     }
42
43     /** Message should be meaning full, but different from localized one.
44     */

45     public String JavaDoc getMessage() {
46         return " " + getLocalizedMessage(); // NOI18N
47
}
48
49     /** Localized message.
50     */

51     public String JavaDoc getLocalizedMessage() {
52         String JavaDoc res = super.getMessage();
53         String JavaDoc format = FileSystem.getString(res);
54
55         if (args != null) {
56             return java.text.MessageFormat.format(format, args);
57         } else {
58             return format;
59         }
60     }
61
62     /** Creates the localized exception.
63     * @param resource to take localization string from
64     * @exception the exception
65     */

66     public static void io(String JavaDoc resource) throws IOException JavaDoc {
67         FSException fsExc = new FSException(resource, null);
68         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
69         throw fsExc;
70     }
71
72     public static void io(String JavaDoc resource, Object JavaDoc[] args)
73     throws IOException JavaDoc {
74         FSException fsExc = new FSException(resource, args);
75         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
76         throw fsExc;
77     }
78
79     public static void io(String JavaDoc resource, Object JavaDoc arg1)
80     throws IOException JavaDoc {
81         FSException fsExc = new FSException(resource, new Object JavaDoc[] { arg1 });
82         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
83         throw fsExc;
84     }
85
86     public static void io(String JavaDoc resource, Object JavaDoc arg1, Object JavaDoc arg2)
87     throws IOException JavaDoc {
88         FSException fsExc = new FSException(resource, new Object JavaDoc[] { arg1, arg2 });
89         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
90         throw fsExc;
91     }
92
93     public static void io(String JavaDoc resource, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3)
94     throws IOException JavaDoc {
95         FSException fsExc = new FSException(resource, new Object JavaDoc[] { arg1, arg2, arg3 });
96         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
97         throw fsExc;
98     }
99
100     public static void io(String JavaDoc resource, Object JavaDoc arg1, Object JavaDoc arg2, Object JavaDoc arg3, Object JavaDoc arg4)
101     throws IOException JavaDoc {
102         FSException fsExc = new FSException(resource, new Object JavaDoc[] { arg1, arg2, arg3, arg4 });
103         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
104         throw fsExc;
105     }
106 }
107
Popular Tags