We have designed our solution of the demo app as:
To associate localizable information to Java packages and classes is by fetching these information as metadata from a MetaBundle associated with the package or class in question.
Now let's see it in practice.
The core code to fetch the internationalized annotations are these methods:
public String getLocalizedClassName(String className) { MetaBundle meta = MetaBundle.get(className); try { return meta.getString("class/@name", locale); } catch (MetaNotFoundException e) { } return "Class Not Localized"; } public String getLocalizedClassDescription(String className) { MetaBundle meta = MetaBundle.get(className); try { return meta.getString("class/description", locale); } catch (MetaNotFoundException e) { } return "Class Not Localized"; } public String getLocalizedPackageName(String packageName) { MetaBundle meta = MetaBundle.get(packageName); try { return meta.getString("package/@name", locale); } catch (MetaNotFoundException e) { } return "Package Not Localized"; } public String getLocalizedPackageDescription(String packageName) { MetaBundle meta = MetaBundle.get(packageName); try { return meta.getString("package/description", locale); } catch (MetaNotFoundException e) { } return "Package Not Localized"; }This snippet is from tutor/meta/Brief.java
How these methods are invoked and how text obtained from them are displayed onto the UI is left for the reader to find out from within tutor/meta/Brief.java.
All MetaBundles annotating Java classes or packages shipped with the demo source are listed below, followed by the XML files authored for them respectively.
MetaBundlejavawith XML files:MetaBundlejava.meta java_zh.metajava.awtwith XML files:MetaBundlejava/awt.meta java/awt_zh.metajava.awt.Framewith XML files:MetaBundlejava/awt/Frame.metajava.langwith XML files:MetaBundlejava/lang.meta java/lang_zh.metajava.lang.Errorwith XML files:MetaBundlejava/lang/Error.metajava.lang.Exceptionwith XML files:MetaBundlejava/lang/Exception.metajava.lang.Objectwith XML files:MetaBundlejava/lang/Object.meta java/lang/Object_zh.metajava.lang.RuntimeExceptionwith XML files:MetaBundlejava/lang/RuntimeException.metajava.net.URIwith XML files:MetaBundlejava/net/URI.metajava.net.URLwith XML files:MetaBundlejava/net/URL.metajava.utilwith XML files:MetaBundlejava/util.meta java/util_zh.metajava.util.HashMapwith XML files:MetaBundlejava/util/HashMap.metajava.util.Hashtablewith XML files:MetaBundlejava/util/Hashtable.metajava.util.WeakHashMapwith XML files:MetaBundlejava/util/WeakHashMap.metajavaxwith XML files:MetaBundlejavax.meta javax_zh.metajavax.swing.JFramewith XML files:MetaBundlejavax/swing/JFrame.metaorg.w3cwith XML files:MetaBundleorg/w3c.metaorg.xmlwith XML files:org/xml.meta
This is all the demo app has for annotations of Java classes and
packages. Far from sufficient? Sure, we all think so. Well, you'd see it's easy
enough to extend this set of MetaBundles, just write more XML files, and you are
able to see your contribution immediately on the Demo App's window by pressing