private ResourceBundle getResourceBundle ( ) { ResourceBundle rb = null ; /* * make sure we have a valid bundle name */ if ( null != ivBundleName && ! "" . equals ( ivBundleName . trim ( ) ) ) { ClassLoader classLoader = null ; /* * get the context classloader to lookup bundle */ try { classLoader = AccessController . doPrivileged ( new PrivilegedExceptionAction < ClassLoader > ( ) { public ClassLoader run ( ) throws Exception { return Thread . currentThread ( ) . getContextClassLoader ( ) ; } } ) ; } catch ( PrivilegedActionException e ) { // convert to a runtime exception since callers already have // to deal // with that type throw new java . lang . RuntimeException ( e . getMessage ( ) ) ; } /* * if there is a context classloader * OPTION 1 - look in context classloader */ if ( null != classLoader ) { try { rb = ResourceBundle . getBundle ( ivBundleName , ivLocale , classLoader ) ; } catch ( MissingResourceException e ) { // if (quiet) { // // logger.log(Level.FINEST, // "Cannot find resource bundle {0} for locale {1} in Thread context loader, will try system class loader", // new Object[] { ivBundleName, ivLocale.toString() }); // } } } /* * OPTION 2: Climb up the stack and get class that loaded the class * Use this classloader to get bundle. This helps with OSGI bundle */ if ( null == rb ) { // if (quiet) { // // logger.log(Level.FINEST, // "Cannot find resource bundle {0} for locale {1} in System Class loader, will try callee classloader", // new Object[] { ivBundleName, ivLocale.toString() }); rb = locateBundleFromCallee ( ) ; // } } /* * OPTION 3: Look in system classloader */ if ( null == rb ) { try { rb = ResourceBundle . getBundle ( ivBundleName , ivLocale ) ; } catch ( MissingResourceException e2 ) { /* * left empty on purpose, since we cannot log */ } } } return rb ; }
Private message to locate resource bundle