private String getPatternString ( String key ) throws MissingResourceException { ResourceBundle bundle = getBundle ( ) ; Object object = bundle . getObject ( key ) ; // is the resource a single string if ( object instanceof String ) { return ( String ) object ; } else if ( object instanceof String [ ] ) { //if string array then randomly pick one String [ ] strings = ( String [ ] ) object ; return strings [ RANDOM . nextInt ( strings . length ) ] ; } else { throw new MissingResourceException ( "Unable to find resource of appropriate type." , "java.lang.String" , key ) ; } }
Utility method to retrieve a string from ResourceBundle . If the key is a single string then that will be returned . If key refers to string array then a random string will be chosen . Other types cause an exception .