package diskfiles; import com.raghuraman.rbcore.keycontrol.msg.ints.fluid.MsgWithReloadableCacheAndOneLocale; import com.raghuraman.rbcore.keycontrol.msg.BundleLocator; import com.raghuraman.rbcore.keycontrol.msgobject.dl.Message; public class DiskFileException extends Exception implements Message { /** * name of the resource bundle */ private static final String resouceBundleName = "diskfiles.DiskFile"; /** * The keys field is used when the general settings specifies a fluid-int type for the fields. A String * array of the actual key names is built and set in this field. Since each key is an index the key name * can be quickly obtained from this index. */ private static final String[] keys = BundleLocator.getFieldNames(Nested.class); /** * The messenger field is a convenience field used by this class */ private static final MsgWithReloadableCacheAndOneLocale dlMessenger = new MsgWithReloadableCacheAndOneLocale(resouceBundleName, keys); public static final DiskFileException getEmptyDiskNameException() { return new DiskFileException(Nested.EMPTY_DISK_NAME.ordinal()); } public static final DiskFileException getEmptyDiskNameException(Throwable cause) { return new DiskFileException(Nested.EMPTY_DISK_NAME.ordinal(), cause); } public static final DiskFileException getLargeDiskException(int maxDiskNameLength, String diskName, int diskNameLength) { Object[] arr = { maxDiskNameLength, diskName, diskNameLength }; return new DiskFileException(Nested.LARGE_DISK.ordinal(), arr); } public static final DiskFileException getLargeDiskException(int maxDiskNameLength, String diskName, int diskNameLength, Throwable cause) { Object[] arr = { maxDiskNameLength, diskName, diskNameLength }; return new DiskFileException(Nested.LARGE_DISK.ordinal(), cause, arr); } public static final DiskFileException getNoOfFilesOutOfRangeException(int minInclusive, int max, int value) { Object[] arr = { minInclusive, max, value }; return new DiskFileException(Nested.NO_OF_FILES_OUT_OF_RANGE.ordinal(), arr); } public static final DiskFileException getNoOfFilesOutOfRangeException(int minInclusive, int max, int value, Throwable cause) { Object[] arr = { minInclusive, max, value }; return new DiskFileException(Nested.NO_OF_FILES_OUT_OF_RANGE.ordinal(), cause, arr); } public static final DiskFileException getInvalidNumberOfFileException(String input) { Object[] arr = { input }; return new DiskFileException(Nested.INVALID_NUMBER_OF_FILE.ordinal(), arr); } public static final DiskFileException getInvalidNumberOfFileException(String input, Throwable cause) { Object[] arr = { input }; return new DiskFileException(Nested.INVALID_NUMBER_OF_FILE.ordinal(), cause, arr); } /** * gets the internationalized message * @return message */ public final String getMessage() { return dlMessenger.getMessage(Integer.parseInt(super.getMessage()), arr); } /** * The arr field is a instance final field and is used to hold the parameters of the message. */ private final Object[] arr; /** * All constructors are private to prevent unnecessary instantiation of this class * @param key * @param cause * @param arr */ private DiskFileException(int key, Throwable cause, Object[] arr) { super (String.valueOf(key), cause); this.arr=arr; } /** * All constructors are private to prevent unnecessary instantiation of this class * @param key * @param cause */ private DiskFileException(int key, Throwable cause) { this (key, cause, null); } /** * All constructors are private to prevent unnecessary instantiation of this class * @param key * @param arr */ private DiskFileException(int key, Object[] arr) { this (key, null, arr); } /** * All constructors are private to prevent unnecessary instantiation of this class * @param key */ private DiskFileException(int key) { this (key, null, null); } /** * Currently this method simply reloads the cache and returns true. In case reloading is not needed it * may be turned off from the general settings page of the rb editor. * @return A boolean flag to indicate whether reloading of the cache was attempted */ public static final boolean reloadDlMessengerCache() { dlMessenger.updateCache(resouceBundleName); return true; } protected static enum Nested { EMPTY_DISK_NAME, LARGE_DISK, NO_OF_FILES_OUT_OF_RANGE, INVALID_NUMBER_OF_FILE } }