A New Strategy of Language Pack Management for Wireless Apps
By Huang Chang & Tong Chun Jie2005-04-18
LPProxy Bundle
LPProxy provides the following methods:
• void setBaseName(String baseName): Sets the base name of the LP bundle. If a bundle is named as LP_en_US, for example, the base name should be LP.
• String getBaseName(): Gets the base name of the LP bundle.
• void setLocale(Locale locale): Sets the locale of the LP bundle.
• Locale getLocale(): Gets the locale of the LP bundle.
• String getString(String key): Gets a string for the given key from the LP bundle.
The getString(String key) method is the key function, as shown in Listing 2.
Listing 2. The getString(String key) method and its related methods
public String getString(String key) {
init();
return lpSV.getString(key);
}
//initialize and install the required bundle.
private void init()
{
//Reinstall LocaleData bundle if the baseName or the locale changes.
if(reloadBundle)
{
if(this.lpBundle!=null){
//Need to uninstall current Language Pack bundle
ctx.ungetService(lpSR);
try {
lpBundle.uninstall();
} catch (BundleException e) {
e.printStackTrace();
}
}
//Install LocaleData bundle from local runtime or remote SMF Server
if(baseName == null )
{
System.out.println("You must specify the bundle name
and the resource base name");
}else{
try{
//Install LocaleData bundle then start it.
String bName="smfbd:/" + baseName+"_" +
this.locale.getLanguage() + "_"
+this.locale.getCountry();
lpBundle = ctx.installBundle(bName);
lpBundle.start();
//Get the ServiceReference instance
lpSR=locateResourceBundle();
//Get the LPService instance
lpSV = (LPService)ctx.getService(lpSR);
reloadBundle=false;
}catch(BundleException e)
{
e.printStackTrace();
}
}
}else
{
System.out.println("Bundle has already installed");
}
}
//Create ServiceReference instance for LocaleData Bundle.
private ServiceReference locateResourceBundle()
{
try {
//Get all available ServiceReference instances from run time.
ServiceReference sr[]=ctx.getServiceReferences(svName,null);
for(int i=0;i<sr.length;i++){
//Get the target bundle comparing the bundle name.
String key=(String)sr[i].getProperty("Bundle-Name");
if(key.equals(this.baseName+"_"+this.locale.getLanguage()
+"_"+this.locale.getCountry()))
return sr[i];
}
} catch (InvalidSyntaxException e) {
e.printStackTrace();
}
return null;
}
First published by IBM DeveloperWorks
|
|||||||||
You might also want to check these out:
|
Leave a Comment on "A New Strategy of Language Pack Management for Wireless Apps"
You must be logged in to post a comment.
Link to This Tutorial Page!

