An extension of StandardMBean to support internationalization.
The I18N information is taken from a property bundle named MyImplMBeanResources where "MyImpl" is the fully qualified class implementing the MBean.
These bundles are nested following the class hierachy of the implementation class. This means that a superclass of the real implementing class can define the resource bundle for the common attributes and operations.
The resource bundle naming rules defined by {@link java.util.ResourceBundle}are used; in particular :
- If a class called MyPackage.MyImplMBeanResources_localInfo exists it is used (programmatic methd)
- Otherwise the file called MyPackage.MyImplMBeanResources_localInfo.properties is used.
localInfo consists of one or more sections of "language_country_variant" (eg en_GB or fr_FR).
The locale to be used is determined by one of the following mechanisms (in this order)
- The locale object explicitly passed to the constructor (if not null)
- The static method {@link #setDefaultLocale}
- The system property "mx4j.descriptionLocale"
- The current system default locale
The bundle should contain keys as described below :
Global bean description
The global bean description is given by the single key "descr":
descr=The MBean Description
Attributes
Attribute desciptions are given by keys of form "attr.Name" where Name is the attribute name (the method name minus the get/set prefix) :
attr.Counter=The counter
Constructors
Non ambiguous case
All constructors having a different
number of arguments may be described in this way:
cons.N=desciption of constructor N cons.N.param.1=Description of first parameter of constructor N cons.N.paramName.1=paramName1 cons.N.param.2=Description of first parameter of constructor N cons.N.paramName.2=paramName2
Where N is a sequential number starting at one.
Ambiguous case
Where several constructors exist with the same number of arguments an explicit signature must be given. The signature is a comma separated list of class descriptions (as returned by {@link java.lang.Class#getName} and has the key cons.N.sig :
cons.N.sig=int,java.lang.Object cons.N.param.1=The int parameter cons.N.param.2=The Object parameter
Operations
No overloading
When no overloaded versions of an operation exist (same method name but different parameters) the simplest case shown below can be used :
op.operationName=The description op.operationName.param.1=The first parameter op.operationName.paramName.1=param1
Non ambiguous overloading case
When operation overloading is used but the overloaded versions differ in the number of parameters the format below can be used :
op.operationName.1=The first version of operationName op.operationName.1.param.1=parameter for first version op.operationName.1.paramName.1=param1 op.operationName.2=The second version of operationName op.operationName.2.paramName.1=param1 op.operationName.2.param.1=first parameter for second version op.operationName.2.param.2=second parameter for second version op.operationName.2.paramName.2=param2
Ambiguous overloading case
When operations with the same name have the same number of arguments an explicit signature must be used :
op.operationName.1.sig=int op.operationName.1=The first version of operationName (takes int) op.operationName.1.param.1=parameter for first version op.operationName.1.paramName.1=param1 op.operationName.2.sig=java.lang.Object op.operationName.2=The second version of operationName (take Object) op.operationName.2.paramName.1=param1 op.operationName.2.param.1=first parameter for second version
Restrictions
Parameter names must only contain characters allowed in a Java identifier (in particular spaces are
not allowed). This is required by the JMX specifications. No such restrictions exist for the other descriptions.
Behaviour with missing data
If no resource bunde exists for the MBean a java.util.MissingResourceException will be thrown by the constructor.
If the resouce bundle is found but the bean description, constructor description or parameter name is missing the String "??(key)" will be returned instead (eg "??(op.myOperation)".
If a paramName key is missing (for constructor or operation) the version normally given by StandardMBean is used (generally "pN").
If a non ambiguous description cannot be determined the fixed (non translatable) descriptions "ambiguous constructor", "parameter for ambiguous constructor", "ambiguous operation", "parameter for ambiguous operation" are returned.