PackageStringSourcespublic class PackageStringSources extends Object A StringSource for a package which first looks for a class in the the package
named "PackageStringSource", and then, if not found, attempts to locate
a ResourceBundle with the name "Strings".
Also maintains a cache of such sources so that subsequent uses reuse prior ones. |
Fields Summary |
---|
static final Map | mSources |
Constructors Summary |
---|
private PackageStringSources()
|
Methods Summary |
---|
public static StringSource | get(java.lang.Class theClass, StringSource delegate)Get a string source for the specified class, using the specified
StringSource as its delegate.
StringSource source = mSources.get( theClass );
if ( source == null )
{
source = init( theClass, delegate );
mSources.put( theClass, source );
}
return( source );
| private static StringSource | init(java.lang.Class theClass, StringSource delegate)
StringSource source = null;
final String packageName = theClass.getPackage().getName();
try
{
final String classname = packageName + ".PackageStrings";
final Class packageStringSourceClass = ClassUtil.getClassFromName( classname );
final Constructor c = packageStringSourceClass.getConstructor( new Class[] { StringSource.class } );
source = (StringSource)c.newInstance( new Object[] { delegate } );
}
catch( Exception e )
{
// no such class exists
e.printStackTrace();
}
if ( source == null )
{
final ResourceBundle bundle = ResourceBundle.getBundle( packageName + ".Strings",
Locale.getDefault(), theClass.getClassLoader());
source = new ResourceBundleStringSource( bundle, delegate );
}
return( source );
|
|