1 19 20 package org.netbeans.modules.masterfs.filebasedfs.utils; 21 22 import java.util.MissingResourceException ; 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 ; 29 30 37 public final class FSException extends IOException { 38 39 43 private final Object [] args; 44 45 48 private FSException(final String resource, final Object [] args) { 49 super(resource); 50 this.args = args; 51 } 52 53 56 public String getMessage() { 57 return " " + getLocalizedMessage(); } 59 60 63 public String getLocalizedMessage() { 64 final String res = super.getMessage(); 65 68 String format = null; 69 try{ 70 format = NbBundle.getBundle("org.netbeans.modules.masterfs.filebasedfs.Bundle", java.util.Locale.getDefault(), FileBasedFileSystem.class.getClassLoader()).getString(res); } catch (MissingResourceException mex) { 72 if (format == null) { 73 NbBundle.getBundle("org.openide.filesystems.Bundle", java.util.Locale.getDefault(), FileSystem.class.getClassLoader()).getString(res); } 75 } 76 77 if (args != null) { 78 return java.text.MessageFormat.format(format, args); 79 } else { 80 return format; 81 } 82 } 83 84 90 public static void io(final String resource) throws IOException { 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 resource, final Object [] args) throws IOException { 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 resource, final Object arg1) throws IOException { 103 final FSException fsExc = new FSException(resource, new Object []{arg1}); 104 Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage()); 105 throw fsExc; 106 } 107 108 public static void io(final String resource, final Object arg1, final Object arg2) throws IOException { 109 final FSException fsExc = new FSException(resource, new Object []{arg1, arg2}); 110 Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage()); 111 throw fsExc; 112 } 113 114 public static void io(final String resource, final Object arg1, final Object arg2, final Object arg3) throws IOException { 115 final FSException fsExc = new FSException(resource, new Object []{arg1, arg2, arg3}); 116 Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage()); 117 throw fsExc; 118 } 119 120 public static void io(final String resource, final Object arg1, final Object arg2, final Object arg3, final Object arg4) throws IOException { 121 final FSException fsExc = new FSException(resource, new Object []{arg1, arg2, arg3, arg4}); 122 Exceptions.attachLocalizedMessage(fsExc, fsExc.getLocalizedMessage()); 123 throw fsExc; 124 } 125 126 public static void annotateException(final Throwable t) { 127 Exceptions.attachLocalizedMessage(t, t.getLocalizedMessage()); 128 } 129 } 130 | Popular Tags |