ProjectResourceBundlepublic class ProjectResourceBundle extends ResourceBundle Wrapper class for resource bundles. Property files are used to store
resource strings, which are the only types of resources available.
Property files can inherit properties from other files so that
a base property file can be used and a small number of properties
can be over-ridden by another property file. For example you may
create an english version of a resource file named "resource.properties".
You then decide that the British English version of all of the properties
except one are the same, so there is no need to redefine all of the
properties in "resource_en_GB", just the one that is different.
The basename is the name of the property file without the ".properties"
extension.
Properties will be cached for performance.
Property values stored in the property files can also contain dynamic
variables. Any dynamic variable defined in PropertiesUtil.getVariableValue()
can be used (such as {date}), as well as arguments in the form {0}, {1}, etc.
Argument values are specified in the various overloaded getString() methods. |
Fields Summary |
---|
protected static Log | log | private static final Hashtable | bundleCache | private static final Locale | defaultLocale | private final ResourceBundle | resourceBundle | private final String | resourceName |
Constructors Summary |
---|
private ProjectResourceBundle(String name, ResourceBundle bundle)Construct a new ProjectResourceBundle
this.resourceBundle = bundle;
this.resourceName = name;
|
Methods Summary |
---|
public static void | clearCache()Clears the internal cache
bundleCache.clear();
| public static org.apache.axis.i18n.ProjectResourceBundle | getBundle(java.lang.String projectName, java.lang.String packageName, java.lang.String resourceName)Construct a new ProjectResourceBundle
return getBundle(projectName, packageName, resourceName, null, null, null);
| public static org.apache.axis.i18n.ProjectResourceBundle | getBundle(java.lang.String projectName, java.lang.Class caller, java.lang.String resourceName, java.util.Locale locale)Construct a new ProjectResourceBundle
return getBundle(projectName,
caller,
resourceName,
locale,
null);
| public static org.apache.axis.i18n.ProjectResourceBundle | getBundle(java.lang.String projectName, java.lang.String packageName, java.lang.String resourceName, java.util.Locale locale, java.lang.ClassLoader loader)Construct a new ProjectResourceBundle
return getBundle(projectName, packageName, resourceName, locale, loader, null);
| public static org.apache.axis.i18n.ProjectResourceBundle | getBundle(java.lang.String projectName, java.lang.Class caller, java.lang.String resourceName, java.util.Locale locale, java.util.ResourceBundle extendsBundle)Construct a new ProjectResourceBundle
return getBundle(projectName,
getPackage(caller.getClass().getName()),
resourceName,
locale,
caller.getClass().getClassLoader(),
extendsBundle);
| public static org.apache.axis.i18n.ProjectResourceBundle | getBundle(java.lang.String projectName, java.lang.String packageName, java.lang.String resourceName, java.util.Locale locale, java.lang.ClassLoader loader, java.util.ResourceBundle extendsBundle)Construct a new ProjectResourceBundle
if (log.isDebugEnabled()) {
log.debug("getBundle(" + projectName + ","
+ packageName + ","
+ resourceName + ","
+ String.valueOf(locale) + ",...)");
}
Context context = new Context();
context.setLocale(locale);
context.setLoader(loader);
context.setProjectName(projectName);
context.setResourceName(resourceName);
context.setParentBundle(extendsBundle);
packageName = context.validate(packageName);
ProjectResourceBundle bundle = null;
try {
bundle = getBundle(context, packageName);
} catch (RuntimeException e) {
log.debug("Exception: ", e);
throw e;
}
if (bundle == null) {
throw new MissingResourceException("Cannot find resource '" +
packageName + '." + resourceName + "'",
resourceName, "");
}
return bundle;
| private static synchronized org.apache.axis.i18n.ProjectResourceBundle | getBundle(org.apache.axis.i18n.ProjectResourceBundle$Context context, java.lang.String packageName)get bundle...
- check cache
- try up hierarchy
- if at top of hierarchy, use (link to) context.getParentBundle()
String cacheKey = context.getCacheKey(packageName);
ProjectResourceBundle prb = (ProjectResourceBundle)bundleCache.get(cacheKey);
if (prb == null) {
String name = packageName + '." + context.getResourceName();
ResourceBundle rb = context.loadBundle(packageName);
ResourceBundle parent = context.getParentBundle(packageName);
if (rb != null) {
prb = new ProjectResourceBundle(name, rb);
prb.setParent(parent);
if (log.isDebugEnabled()) {
log.debug("Created " + prb + ", linked to parent " + String.valueOf(parent));
}
} else {
if (parent != null) {
if (parent instanceof ProjectResourceBundle) {
prb = (ProjectResourceBundle)parent;
} else {
prb = new ProjectResourceBundle(name, parent);
}
if (log.isDebugEnabled()) {
log.debug("Root package not found, cross link to " + parent);
}
}
}
if (prb != null) {
// Cache the resource
bundleCache.put(cacheKey, prb);
}
}
return prb;
| public java.util.Enumeration | getKeys()
Enumeration myKeys = resourceBundle.getKeys();
if (parent == null) {
return myKeys;
} else {
final HashSet set = new HashSet();
while (myKeys.hasMoreElements()) {
set.add(myKeys.nextElement());
}
Enumeration pKeys = parent.getKeys();
while (pKeys.hasMoreElements()) {
set.add(pKeys.nextElement());
}
return new Enumeration() {
private Iterator it = set.iterator();
public boolean hasMoreElements() { return it.hasNext(); }
public Object nextElement() { return it.next(); }
};
}
| private static final java.lang.String | getPackage(java.lang.String name)
return name.substring(0, name.lastIndexOf('.")).intern();
| public java.lang.String | getResourceName()
return resourceName;
| protected java.lang.Object | handleGetObject(java.lang.String key)
if (log.isDebugEnabled()) {
log.debug(this.toString() + "::handleGetObject(" + key + ")");
}
// return resourceBundle.handleGetObject(key);
Object obj;
try {
obj = resourceBundle.getObject(key);
} catch (MissingResourceException e) {
/* catch missing resource, ignore, & return null
* if this method doesn't return null, then parents
* are not searched
*/
obj = null;
}
return obj;
| public java.lang.String | toString()
return resourceName;
|
|