KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > masterfs > filebasedfs > utils > 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
20 package org.netbeans.modules.masterfs.filebasedfs.utils;
21
22 import java.util.MissingResourceException JavaDoc;
23 import org.openide.filesystems.FileSystem;
24 import org.openide.util.Exceptions;
25 import org.openide.util.NbBundle;
26 import org.netbeans.modules.masterfs.filebasedfs.FileBasedFileSystem;
27
28 import java.io.IOException JavaDoc;
29
30 /**
31  * Copy/pasted from org.openide.filesystems
32  * <p/>
33  * Localized IOException for filesystems.
34  *
35  * @author Jaroslav Tulach
36  */

37 public final class FSException extends IOException JavaDoc {
38     /** name of resource to use for localized message */
39     // private String resource;
40
/**
41      * arguments to pass to the resource
42      */

43     private final Object JavaDoc[] args;
44
45     /**
46      * Creates new FSException.
47      */

48     private FSException(final String JavaDoc resource, final Object JavaDoc[] args) {
49         super(resource);
50         this.args = args;
51     }
52
53     /**
54      * Message should be meaning full, but different from localized one.
55      */

56     public String JavaDoc getMessage() {
57         return " " + getLocalizedMessage(); // NOI18N
58
}
59
60     /**
61      * Localized message.
62      */

63     public String JavaDoc getLocalizedMessage() {
64         final String JavaDoc res = super.getMessage();
65         /*This call to getBundle should ensure that currentClassLoader is not used to load resources from.
66          This should prevent from deadlock, that occured: one waits for FileObject and has resource,
67          second one waits for resource and has FileObject*/

68         String JavaDoc format = null;
69         try{
70             format = NbBundle.getBundle("org.netbeans.modules.masterfs.filebasedfs.Bundle", java.util.Locale.getDefault(), FileBasedFileSystem.class.getClassLoader()).getString(res);//NOI18N
71
} catch (MissingResourceException JavaDoc mex) {
72             if (format == null) {
73                 NbBundle.getBundle("org.openide.filesystems.Bundle", java.util.Locale.getDefault(), FileSystem.class.getClassLoader()).getString(res);//NOI18N
74
}
75         }
76                 
77         if (args != null) {
78             return java.text.MessageFormat.format(format, args);
79         } else {
80             return format;
81         }
82     }
83
84     /**
85      * Creates the localized exception.
86      *
87      * @param resource to take localization string from
88      * @throws the exception
89      */

90     public static void io(final String JavaDoc resource) throws IOException JavaDoc {
91         final FSException fsExc = new FSException(resource, null);
92         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
93         throw fsExc;
94     }
95
96     public static void io(final String JavaDoc resource, final Object JavaDoc[] args) throws IOException JavaDoc {
97         final FSException fsExc = new FSException(resource, args);
98         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
99         throw fsExc;
100     }
101
102     public static void io(final String JavaDoc resource, final Object JavaDoc arg1) throws IOException JavaDoc {
103         final FSException fsExc = new FSException(resource, new Object JavaDoc[]{arg1});
104         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
105         throw fsExc;
106     }
107
108     public static void io(final String JavaDoc resource, final Object JavaDoc arg1, final Object JavaDoc arg2) throws IOException JavaDoc {
109         final FSException fsExc = new FSException(resource, new Object JavaDoc[]{arg1, arg2});
110         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
111         throw fsExc;
112     }
113
114     public static void io(final String JavaDoc resource, final Object JavaDoc arg1, final Object JavaDoc arg2, final Object JavaDoc arg3) throws IOException JavaDoc {
115         final FSException fsExc = new FSException(resource, new Object JavaDoc[]{arg1, arg2, arg3});
116         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
117         throw fsExc;
118     }
119
120     public static void io(final String JavaDoc resource, final Object JavaDoc arg1, final Object JavaDoc arg2, final Object JavaDoc arg3, final Object JavaDoc arg4) throws IOException JavaDoc {
121         final FSException fsExc = new FSException(resource, new Object JavaDoc[]{arg1, arg2, arg3, arg4});
122         Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage());
123         throw fsExc;
124     }
125
126     public static void annotateException(final Throwable JavaDoc t) {
127         Exceptions.attachLocalizedMessage(t, t.getLocalizedMessage());
128     }
129 }
130
Popular Tags