/*----------------------------------------------------------------------------- * Implementation Notes * * Resource bundles are read in once, and thereafter cached. * ResourceBundle statically keeps track of which files have been * read, so we are guaranteed that each file is read at most once. * Resource bundles can be loaded from different data directories and * will be treated as distinct, even if they are for the same locale. * * Resource bundles are lightweight objects, which have pointers to * one or more shared Hashtable objects containing all the data. * Copying would be cheap, but there is no copy constructor, since * there wasn't one in the original API. * * The ResourceBundle parsing mechanism is implemented as a transition * network, for easy maintenance and modification. The network is * implemented as a matrix (instead of in code) to make this even * easier. The matrix contains Transition objects. Each Transition * object describes a destination node and an action to take before * moving to the destination node. The source node is encoded by the * index of the object in the array that contains it. The pieces * needed to understand the transition network are the enums for node * IDs and actions, the parse() method, which walks through the * network and implements the actions, and the network itself. The * network guarantees certain conditions, for example, that a new * resource will not be closed until one has been opened first; or * that data will not be stored into a TaggedList until a TaggedList * has been created. Nonetheless, the code in parse() does some * consistency checks as it runs the network, and fails with an * U_INTERNAL_PROGRAM_ERROR if one of these checks fails. If the input * data has a bad format, an U_INVALID_FORMAT_ERROR is returned. If you * see an U_INTERNAL_PROGRAM_ERROR the transition matrix has a bug in * it. * * Old functionality of multiple locales in a single file is still * supported. For this reason, LOCALE names override FILE names. If * data for en_US is located in the en.txt file, once it is loaded, * the code will not care where it came from (other than remembering * which directory it came from). However, if there is an en_US * resource in en_US.txt, that will take precedence. There is no * limit to the number or type of resources that can be stored in a * file, however, files are only searched in a specific way. If * en_US_CA is requested, then first en_US_CA.txt is searched, then * en_US.txt, then en.txt, then default.txt. So it only makes sense * to put certain locales in certain files. In this example, it would * be logical to put en_US_CA, en_US, and en into the en.txt file, * since they would be found there if asked for. The extreme example * is to place all locale resources into default.txt, which should * also work. * * Inheritance is implemented. For example, xx_YY_zz inherits as * follows: xx_YY_zz, xx_YY, xx, default. Inheritance is implemented * as an array of hashtables. There will be from 1 to 4 hashtables in * the array. * * Fallback files are implemented. The fallback pattern is Language * Country Variant (LCV) -> LC -> L. Fallback is first done for the * requested locale. Then it is done for the default locale, as * returned by Locale::getDefault(). Then the special file * default.txt is searched for the default locale. The overall FILE * fallback path is LCV -> LC -> L -> dLCV -> dLC -> dL -> default. * * Note that although file name searching includes the default locale, * once a ResourceBundle object is constructed, the inheritance path * no longer includes the default locale. The path is LCV -> LC -> L * -> default. * * File parsing is lazy. Nothing is parsed unless it is called for by * someone. So when a ResourceBundle for xx_YY_zz is constructed, * only that locale is parsed (along with anything else in the same * file). Later, if the FooBar tag is asked for, and if it isn't * found in xx_YY_zz, then xx_YY.txt will be parsed and checked, and * so forth, until the chain is exhausted or the tag is found. * * Thread-safety is implemented around caches, both the cache that * stores all the resource data, and the cache that stores flags * indicating whether or not a file has been visited. These caches * delete their storage at static cleanup time, when the process * quits. * * ResourceBundle supports TableCollation as a special case. This * involves having special ResourceBundle objects which DO own their * data, since we don't want large collation rule strings in the * ResourceBundle cache (these are already cached in the * TableCollation cache). TableCollation files (.ctx files) have the * same format as normal resource data files, with a different * interpretation, from the standpoint of ResourceBundle. .ctx files * are loaded into otherwise ordinary ResourceBundle objects. They * don't inherit (that's implemented by TableCollation) and they own * their data (as mentioned above). However, they still support * possible multiple locales in a single .ctx file. (This is in * practice a bad idea, since you only want the one locale you're * looking for, and only one tag will be present * ("CollationElements"), so you don't need an inheritance chain of * multiple locales.) Up to 4 locale resources will be loaded from a * .ctx file; everything after the first 4 is ignored (parsed and * deleted). (Normal .txt files have no limit.) Instead of being * loaded into the cache, and then looked up as needed, the locale * resources are read straight into the ResourceBundle object. * * The Index, which used to reside in default.txt, has been moved to a * new file, index.txt. This file contains a slightly modified format * with the addition of the "InstalledLocales" tag; it looks like: * * Index { * InstalledLocales { * ar * .. * zh_TW * } * }
*/ //-----------------------------------------------------------------------------
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.