author | xdono |
Mon, 15 Dec 2008 16:55:25 -0800 | |
changeset 1639 | a97859015238 |
parent 1570 | 4165709c91e3 |
child 4156 | acaa49a2768a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
1639 | 2 |
* Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package javax.management; |
|
27 |
||
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
28 |
import com.sun.jmx.mbeanserver.Util; |
2 | 29 |
import java.io.IOException; |
30 |
import java.io.StreamCorruptedException; |
|
31 |
import java.io.Serializable; |
|
32 |
import java.io.ObjectOutputStream; |
|
33 |
import java.io.ObjectInputStream; |
|
34 |
import java.lang.reflect.Method; |
|
35 |
import java.util.Arrays; |
|
36 |
import java.util.Map; |
|
37 |
import java.util.WeakHashMap; |
|
38 |
import java.security.AccessController; |
|
39 |
import java.security.PrivilegedAction; |
|
40 |
||
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
41 |
import java.util.HashMap; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
42 |
import java.util.Locale; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
43 |
import java.util.MissingResourceException; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
44 |
import java.util.ResourceBundle; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
45 |
import java.util.logging.Level; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
46 |
import java.util.logging.Logger; |
2 | 47 |
import static javax.management.ImmutableDescriptor.nonNullDescriptor; |
48 |
||
49 |
/** |
|
50 |
* <p>Describes the management interface exposed by an MBean; that is, |
|
51 |
* the set of attributes and operations which are available for |
|
52 |
* management operations. Instances of this class are immutable. |
|
53 |
* Subclasses may be mutable but this is not recommended.</p> |
|
54 |
* |
|
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
55 |
* <p id="info-changed">Usually the {@code MBeanInfo} for any given MBean does |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
56 |
* not change over the lifetime of that MBean. Dynamic MBeans can change their |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
57 |
* {@code MBeanInfo} and in that case it is recommended that they emit a {@link |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
58 |
* Notification} with a {@linkplain Notification#getType() type} of {@code |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
59 |
* "jmx.mbean.info.changed"} and a {@linkplain Notification#getUserData() |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
60 |
* userData} that is the new {@code MBeanInfo}. This is not required, but |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
61 |
* provides a conventional way for clients of the MBean to discover the change. |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
62 |
* See also the <a href="Descriptor.html#immutableInfo">immutableInfo</a> and |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
63 |
* <a href="Descriptor.html#infoTimeout">infoTimeout</a> fields in the {@code |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
64 |
* MBeanInfo} {@link Descriptor}.</p> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
65 |
* |
2 | 66 |
* <p>The contents of the <code>MBeanInfo</code> for a Dynamic MBean |
67 |
* are determined by its {@link DynamicMBean#getMBeanInfo |
|
68 |
* getMBeanInfo()} method. This includes Open MBeans and Model |
|
69 |
* MBeans, which are kinds of Dynamic MBeans.</p> |
|
70 |
* |
|
71 |
* <p>The contents of the <code>MBeanInfo</code> for a Standard MBean |
|
72 |
* are determined by the MBean server as follows:</p> |
|
73 |
* |
|
74 |
* <ul> |
|
75 |
* |
|
76 |
* <li>{@link #getClassName()} returns the Java class name of the MBean |
|
77 |
* object; |
|
78 |
* |
|
79 |
* <li>{@link #getConstructors()} returns the list of all public |
|
80 |
* constructors in that object; |
|
81 |
* |
|
82 |
* <li>{@link #getAttributes()} returns the list of all attributes |
|
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
83 |
* whose existence is deduced as follows: |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
84 |
* <ul> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
85 |
* <li>if the Standard MBean is defined with an MBean interface, |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
86 |
* from <code>get<i>Name</i></code>, <code>is<i>Name</i></code>, or |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
87 |
* <code>set<i>Name</i></code> methods that conform to the conventions |
2 | 88 |
* for Standard MBeans; |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
89 |
* <li>if the Standard MBean is defined with the {@link MBean @MBean} or |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
90 |
* {@link MXBean @MXBean} annotation on a class, from methods with the |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
91 |
* {@link ManagedAttribute @ManagedAttribute} annotation; |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
92 |
* </ul> |
2 | 93 |
* |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
94 |
* <li>{@link #getOperations()} returns the list of all operations whose |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
95 |
* existence is deduced as follows: |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
96 |
* <ul> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
97 |
* <li>if the Standard MBean is defined with an MBean interface, from methods in |
2 | 98 |
* the MBean interface that do not represent attributes; |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
99 |
* <li>if the Standard MBean is defined with the {@link MBean @MBean} or |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
100 |
* {@link MXBean @MXBean} annotation on a class, from methods with the |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
101 |
* {@link ManagedOperation @ManagedOperation} annotation; |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
102 |
* </ul> |
2 | 103 |
* |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
104 |
* <li>{@link #getNotifications()} returns: |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
105 |
* <ul> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
106 |
* <li>if the MBean implements the {@link NotificationBroadcaster} interface, |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
107 |
* the result of calling {@link |
2 | 108 |
* NotificationBroadcaster#getNotificationInfo()} on it; |
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
109 |
* <li>otherwise, if there is a {@link NotificationInfo @NotificationInfo} |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
110 |
* or {@link NotificationInfos @NotificationInfos} annotation on the |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
111 |
* MBean interface or <code>@MBean</code> or <code>@MXBean</code> |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
112 |
* class, the array implied by those annotations; |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
113 |
* <li>otherwise an empty array; |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
114 |
* </ul> |
2 | 115 |
* |
116 |
* <li>{@link #getDescriptor()} returns a descriptor containing the contents |
|
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
117 |
* of any descriptor annotations in the MBean interface (see |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
118 |
* {@link DescriptorFields @DescriptorFields} and |
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
119 |
* {@link DescriptorKey @DescriptorKey}). |
2 | 120 |
* |
121 |
* </ul> |
|
122 |
* |
|
123 |
* <p>The description returned by {@link #getDescription()} and the |
|
124 |
* descriptions of the contained attributes and operations are determined |
|
1513
d09513aaa9da
6252609: Two different default descriptor forms defined for ModelMBeanInfoSupport
emcmanus
parents:
1510
diff
changeset
|
125 |
* by the corresponding {@link Description} annotations if any; |
2 | 126 |
* otherwise their contents are not specified.</p> |
127 |
* |
|
128 |
* <p>The remaining details of the <code>MBeanInfo</code> for a |
|
129 |
* Standard MBean are not specified. This includes the description of |
|
130 |
* any contained constructors, and notifications; the names |
|
131 |
* of parameters to constructors and operations; and the descriptions of |
|
132 |
* constructor parameters.</p> |
|
133 |
* |
|
134 |
* @since 1.5 |
|
135 |
*/ |
|
136 |
public class MBeanInfo implements Cloneable, Serializable, DescriptorRead { |
|
137 |
||
138 |
/* Serial version */ |
|
139 |
static final long serialVersionUID = -6451021435135161911L; |
|
140 |
||
141 |
/** |
|
142 |
* @serial The Descriptor for the MBean. This field |
|
143 |
* can be null, which is equivalent to an empty Descriptor. |
|
144 |
*/ |
|
145 |
private transient Descriptor descriptor; |
|
146 |
||
147 |
/** |
|
148 |
* @serial The human readable description of the class. |
|
149 |
*/ |
|
150 |
private final String description; |
|
151 |
||
152 |
/** |
|
153 |
* @serial The MBean qualified name. |
|
154 |
*/ |
|
155 |
private final String className; |
|
156 |
||
157 |
/** |
|
158 |
* @serial The MBean attribute descriptors. |
|
159 |
*/ |
|
160 |
private final MBeanAttributeInfo[] attributes; |
|
161 |
||
162 |
/** |
|
163 |
* @serial The MBean operation descriptors. |
|
164 |
*/ |
|
165 |
private final MBeanOperationInfo[] operations; |
|
166 |
||
167 |
/** |
|
168 |
* @serial The MBean constructor descriptors. |
|
169 |
*/ |
|
170 |
private final MBeanConstructorInfo[] constructors; |
|
171 |
||
172 |
/** |
|
173 |
* @serial The MBean notification descriptors. |
|
174 |
*/ |
|
175 |
private final MBeanNotificationInfo[] notifications; |
|
176 |
||
177 |
private transient int hashCode; |
|
178 |
||
179 |
/** |
|
180 |
* <p>True if this class is known not to override the array-valued |
|
181 |
* getters of MBeanInfo. Obviously true for MBeanInfo itself, and true |
|
182 |
* for a subclass where we succeed in reflecting on the methods |
|
183 |
* and discover they are not overridden.</p> |
|
184 |
* |
|
185 |
* <p>The purpose of this variable is to avoid cloning the arrays |
|
186 |
* when doing operations like {@link #equals} where we know they |
|
187 |
* will not be changed. If a subclass overrides a getter, we |
|
188 |
* cannot access the corresponding array directly.</p> |
|
189 |
*/ |
|
190 |
private final transient boolean arrayGettersSafe; |
|
191 |
||
192 |
/** |
|
193 |
* Constructs an <CODE>MBeanInfo</CODE>. |
|
194 |
* |
|
195 |
* @param className The name of the Java class of the MBean described |
|
196 |
* by this <CODE>MBeanInfo</CODE>. This value may be any |
|
197 |
* syntactically legal Java class name. It does not have to be a |
|
198 |
* Java class known to the MBean server or to the MBean's |
|
199 |
* ClassLoader. If it is a Java class known to the MBean's |
|
200 |
* ClassLoader, it is recommended but not required that the |
|
201 |
* class's public methods include those that would appear in a |
|
202 |
* Standard MBean implementing the attributes and operations in |
|
203 |
* this MBeanInfo. |
|
204 |
* @param description A human readable description of the MBean (optional). |
|
205 |
* @param attributes The list of exposed attributes of the MBean. |
|
206 |
* This may be null with the same effect as a zero-length array. |
|
207 |
* @param constructors The list of public constructors of the |
|
208 |
* MBean. This may be null with the same effect as a zero-length |
|
209 |
* array. |
|
210 |
* @param operations The list of operations of the MBean. This |
|
211 |
* may be null with the same effect as a zero-length array. |
|
212 |
* @param notifications The list of notifications emitted. This |
|
213 |
* may be null with the same effect as a zero-length array. |
|
214 |
*/ |
|
215 |
public MBeanInfo(String className, |
|
216 |
String description, |
|
217 |
MBeanAttributeInfo[] attributes, |
|
218 |
MBeanConstructorInfo[] constructors, |
|
219 |
MBeanOperationInfo[] operations, |
|
220 |
MBeanNotificationInfo[] notifications) |
|
221 |
throws IllegalArgumentException { |
|
222 |
this(className, description, attributes, constructors, operations, |
|
223 |
notifications, null); |
|
224 |
} |
|
225 |
||
226 |
/** |
|
227 |
* Constructs an <CODE>MBeanInfo</CODE>. |
|
228 |
* |
|
229 |
* @param className The name of the Java class of the MBean described |
|
230 |
* by this <CODE>MBeanInfo</CODE>. This value may be any |
|
231 |
* syntactically legal Java class name. It does not have to be a |
|
232 |
* Java class known to the MBean server or to the MBean's |
|
233 |
* ClassLoader. If it is a Java class known to the MBean's |
|
234 |
* ClassLoader, it is recommended but not required that the |
|
235 |
* class's public methods include those that would appear in a |
|
236 |
* Standard MBean implementing the attributes and operations in |
|
237 |
* this MBeanInfo. |
|
238 |
* @param description A human readable description of the MBean (optional). |
|
239 |
* @param attributes The list of exposed attributes of the MBean. |
|
240 |
* This may be null with the same effect as a zero-length array. |
|
241 |
* @param constructors The list of public constructors of the |
|
242 |
* MBean. This may be null with the same effect as a zero-length |
|
243 |
* array. |
|
244 |
* @param operations The list of operations of the MBean. This |
|
245 |
* may be null with the same effect as a zero-length array. |
|
246 |
* @param notifications The list of notifications emitted. This |
|
247 |
* may be null with the same effect as a zero-length array. |
|
248 |
* @param descriptor The descriptor for the MBean. This may be null |
|
249 |
* which is equivalent to an empty descriptor. |
|
250 |
* |
|
251 |
* @since 1.6 |
|
252 |
*/ |
|
253 |
public MBeanInfo(String className, |
|
254 |
String description, |
|
255 |
MBeanAttributeInfo[] attributes, |
|
256 |
MBeanConstructorInfo[] constructors, |
|
257 |
MBeanOperationInfo[] operations, |
|
258 |
MBeanNotificationInfo[] notifications, |
|
259 |
Descriptor descriptor) |
|
260 |
throws IllegalArgumentException { |
|
261 |
||
262 |
this.className = className; |
|
263 |
||
264 |
this.description = description; |
|
265 |
||
266 |
if (attributes == null) |
|
267 |
attributes = MBeanAttributeInfo.NO_ATTRIBUTES; |
|
268 |
this.attributes = attributes; |
|
269 |
||
270 |
if (operations == null) |
|
271 |
operations = MBeanOperationInfo.NO_OPERATIONS; |
|
272 |
this.operations = operations; |
|
273 |
||
274 |
if (constructors == null) |
|
275 |
constructors = MBeanConstructorInfo.NO_CONSTRUCTORS; |
|
276 |
this.constructors = constructors; |
|
277 |
||
278 |
if (notifications == null) |
|
279 |
notifications = MBeanNotificationInfo.NO_NOTIFICATIONS; |
|
280 |
this.notifications = notifications; |
|
281 |
||
282 |
if (descriptor == null) |
|
283 |
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR; |
|
284 |
this.descriptor = descriptor; |
|
285 |
||
286 |
this.arrayGettersSafe = |
|
287 |
arrayGettersSafe(this.getClass(), MBeanInfo.class); |
|
288 |
} |
|
289 |
||
290 |
/** |
|
291 |
* <p>Returns a shallow clone of this instance. |
|
292 |
* The clone is obtained by simply calling <tt>super.clone()</tt>, |
|
293 |
* thus calling the default native shallow cloning mechanism |
|
294 |
* implemented by <tt>Object.clone()</tt>. |
|
295 |
* No deeper cloning of any internal field is made.</p> |
|
296 |
* |
|
297 |
* <p>Since this class is immutable, the clone method is chiefly of |
|
298 |
* interest to subclasses.</p> |
|
299 |
*/ |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
300 |
@Override |
2 | 301 |
public Object clone () { |
302 |
try { |
|
303 |
return super.clone() ; |
|
304 |
} catch (CloneNotSupportedException e) { |
|
305 |
// should not happen as this class is cloneable |
|
306 |
return null; |
|
307 |
} |
|
308 |
} |
|
309 |
||
310 |
||
311 |
/** |
|
312 |
* Returns the name of the Java class of the MBean described by |
|
313 |
* this <CODE>MBeanInfo</CODE>. |
|
314 |
* |
|
315 |
* @return the class name. |
|
316 |
*/ |
|
317 |
public String getClassName() { |
|
318 |
return className; |
|
319 |
} |
|
320 |
||
321 |
/** |
|
322 |
* Returns a human readable description of the MBean. |
|
323 |
* |
|
324 |
* @return the description. |
|
325 |
*/ |
|
326 |
public String getDescription() { |
|
327 |
return description; |
|
328 |
} |
|
329 |
||
330 |
/** |
|
331 |
* Returns the list of attributes exposed for management. |
|
332 |
* Each attribute is described by an <CODE>MBeanAttributeInfo</CODE> object. |
|
333 |
* |
|
334 |
* The returned array is a shallow copy of the internal array, |
|
335 |
* which means that it is a copy of the internal array of |
|
336 |
* references to the <CODE>MBeanAttributeInfo</CODE> objects |
|
337 |
* but that each referenced <CODE>MBeanAttributeInfo</CODE> object is not copied. |
|
338 |
* |
|
339 |
* @return An array of <CODE>MBeanAttributeInfo</CODE> objects. |
|
340 |
*/ |
|
341 |
public MBeanAttributeInfo[] getAttributes() { |
|
342 |
MBeanAttributeInfo[] as = nonNullAttributes(); |
|
343 |
if (as.length == 0) |
|
344 |
return as; |
|
345 |
else |
|
346 |
return as.clone(); |
|
347 |
} |
|
348 |
||
349 |
private MBeanAttributeInfo[] fastGetAttributes() { |
|
350 |
if (arrayGettersSafe) |
|
351 |
return nonNullAttributes(); |
|
352 |
else |
|
353 |
return getAttributes(); |
|
354 |
} |
|
355 |
||
356 |
/** |
|
357 |
* Return the value of the attributes field, or an empty array if |
|
358 |
* the field is null. This can't happen with a |
|
359 |
* normally-constructed instance of this class, but can if the |
|
360 |
* instance was deserialized from another implementation that |
|
361 |
* allows the field to be null. It would be simpler if we enforced |
|
362 |
* the class invariant that these fields cannot be null by writing |
|
363 |
* a readObject() method, but that would require us to define the |
|
364 |
* various array fields as non-final, which is annoying because |
|
365 |
* conceptually they are indeed final. |
|
366 |
*/ |
|
367 |
private MBeanAttributeInfo[] nonNullAttributes() { |
|
368 |
return (attributes == null) ? |
|
369 |
MBeanAttributeInfo.NO_ATTRIBUTES : attributes; |
|
370 |
} |
|
371 |
||
372 |
/** |
|
373 |
* Returns the list of operations of the MBean. |
|
374 |
* Each operation is described by an <CODE>MBeanOperationInfo</CODE> object. |
|
375 |
* |
|
376 |
* The returned array is a shallow copy of the internal array, |
|
377 |
* which means that it is a copy of the internal array of |
|
378 |
* references to the <CODE>MBeanOperationInfo</CODE> objects |
|
379 |
* but that each referenced <CODE>MBeanOperationInfo</CODE> object is not copied. |
|
380 |
* |
|
381 |
* @return An array of <CODE>MBeanOperationInfo</CODE> objects. |
|
382 |
*/ |
|
383 |
public MBeanOperationInfo[] getOperations() { |
|
384 |
MBeanOperationInfo[] os = nonNullOperations(); |
|
385 |
if (os.length == 0) |
|
386 |
return os; |
|
387 |
else |
|
388 |
return os.clone(); |
|
389 |
} |
|
390 |
||
391 |
private MBeanOperationInfo[] fastGetOperations() { |
|
392 |
if (arrayGettersSafe) |
|
393 |
return nonNullOperations(); |
|
394 |
else |
|
395 |
return getOperations(); |
|
396 |
} |
|
397 |
||
398 |
private MBeanOperationInfo[] nonNullOperations() { |
|
399 |
return (operations == null) ? |
|
400 |
MBeanOperationInfo.NO_OPERATIONS : operations; |
|
401 |
} |
|
402 |
||
403 |
/** |
|
404 |
* <p>Returns the list of the public constructors of the MBean. |
|
405 |
* Each constructor is described by an |
|
406 |
* <CODE>MBeanConstructorInfo</CODE> object.</p> |
|
407 |
* |
|
408 |
* <p>The returned array is a shallow copy of the internal array, |
|
409 |
* which means that it is a copy of the internal array of |
|
410 |
* references to the <CODE>MBeanConstructorInfo</CODE> objects but |
|
411 |
* that each referenced <CODE>MBeanConstructorInfo</CODE> object |
|
412 |
* is not copied.</p> |
|
413 |
* |
|
414 |
* <p>The returned list is not necessarily exhaustive. That is, |
|
415 |
* the MBean may have a public constructor that is not in the |
|
416 |
* list. In this case, the MBean server can construct another |
|
417 |
* instance of this MBean's class using that constructor, even |
|
418 |
* though it is not listed here.</p> |
|
419 |
* |
|
420 |
* @return An array of <CODE>MBeanConstructorInfo</CODE> objects. |
|
421 |
*/ |
|
422 |
public MBeanConstructorInfo[] getConstructors() { |
|
423 |
MBeanConstructorInfo[] cs = nonNullConstructors(); |
|
424 |
if (cs.length == 0) |
|
425 |
return cs; |
|
426 |
else |
|
427 |
return cs.clone(); |
|
428 |
} |
|
429 |
||
430 |
private MBeanConstructorInfo[] fastGetConstructors() { |
|
431 |
if (arrayGettersSafe) |
|
432 |
return nonNullConstructors(); |
|
433 |
else |
|
434 |
return getConstructors(); |
|
435 |
} |
|
436 |
||
437 |
private MBeanConstructorInfo[] nonNullConstructors() { |
|
438 |
return (constructors == null) ? |
|
439 |
MBeanConstructorInfo.NO_CONSTRUCTORS : constructors; |
|
440 |
} |
|
441 |
||
442 |
/** |
|
443 |
* Returns the list of the notifications emitted by the MBean. |
|
444 |
* Each notification is described by an <CODE>MBeanNotificationInfo</CODE> object. |
|
445 |
* |
|
446 |
* The returned array is a shallow copy of the internal array, |
|
447 |
* which means that it is a copy of the internal array of |
|
448 |
* references to the <CODE>MBeanNotificationInfo</CODE> objects |
|
449 |
* but that each referenced <CODE>MBeanNotificationInfo</CODE> object is not copied. |
|
450 |
* |
|
451 |
* @return An array of <CODE>MBeanNotificationInfo</CODE> objects. |
|
452 |
*/ |
|
453 |
public MBeanNotificationInfo[] getNotifications() { |
|
454 |
MBeanNotificationInfo[] ns = nonNullNotifications(); |
|
455 |
if (ns.length == 0) |
|
456 |
return ns; |
|
457 |
else |
|
458 |
return ns.clone(); |
|
459 |
} |
|
460 |
||
461 |
private MBeanNotificationInfo[] fastGetNotifications() { |
|
462 |
if (arrayGettersSafe) |
|
463 |
return nonNullNotifications(); |
|
464 |
else |
|
465 |
return getNotifications(); |
|
466 |
} |
|
467 |
||
468 |
private MBeanNotificationInfo[] nonNullNotifications() { |
|
469 |
return (notifications == null) ? |
|
470 |
MBeanNotificationInfo.NO_NOTIFICATIONS : notifications; |
|
471 |
} |
|
472 |
||
473 |
/** |
|
474 |
* Get the descriptor of this MBeanInfo. Changing the returned value |
|
475 |
* will have no affect on the original descriptor. |
|
476 |
* |
|
477 |
* @return a descriptor that is either immutable or a copy of the original. |
|
478 |
* |
|
479 |
* @since 1.6 |
|
480 |
*/ |
|
481 |
public Descriptor getDescriptor() { |
|
482 |
return (Descriptor) nonNullDescriptor(descriptor).clone(); |
|
483 |
} |
|
484 |
||
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
485 |
@Override |
2 | 486 |
public String toString() { |
487 |
return |
|
488 |
getClass().getName() + "[" + |
|
489 |
"description=" + getDescription() + ", " + |
|
490 |
"attributes=" + Arrays.asList(fastGetAttributes()) + ", " + |
|
491 |
"constructors=" + Arrays.asList(fastGetConstructors()) + ", " + |
|
492 |
"operations=" + Arrays.asList(fastGetOperations()) + ", " + |
|
493 |
"notifications=" + Arrays.asList(fastGetNotifications()) + ", " + |
|
494 |
"descriptor=" + getDescriptor() + |
|
495 |
"]"; |
|
496 |
} |
|
497 |
||
498 |
/** |
|
499 |
* <p>Compare this MBeanInfo to another. Two MBeanInfo objects |
|
500 |
* are equal if and only if they return equal values for {@link |
|
501 |
* #getClassName()}, for {@link #getDescription()}, and for |
|
502 |
* {@link #getDescriptor()}, and the |
|
503 |
* arrays returned by the two objects for {@link |
|
504 |
* #getAttributes()}, {@link #getOperations()}, {@link |
|
505 |
* #getConstructors()}, and {@link #getNotifications()} are |
|
506 |
* pairwise equal. Here "equal" means {@link |
|
507 |
* Object#equals(Object)}, not identity.</p> |
|
508 |
* |
|
509 |
* <p>If two MBeanInfo objects return the same values in one of |
|
510 |
* their arrays but in a different order then they are not equal.</p> |
|
511 |
* |
|
512 |
* @param o the object to compare to. |
|
513 |
* |
|
514 |
* @return true if and only if <code>o</code> is an MBeanInfo that is equal |
|
515 |
* to this one according to the rules above. |
|
516 |
*/ |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
517 |
@Override |
2 | 518 |
public boolean equals(Object o) { |
519 |
if (o == this) |
|
520 |
return true; |
|
521 |
if (!(o instanceof MBeanInfo)) |
|
522 |
return false; |
|
523 |
MBeanInfo p = (MBeanInfo) o; |
|
524 |
if (!isEqual(getClassName(), p.getClassName()) || |
|
525 |
!isEqual(getDescription(), p.getDescription()) || |
|
526 |
!getDescriptor().equals(p.getDescriptor())) { |
|
527 |
return false; |
|
528 |
} |
|
529 |
||
530 |
return |
|
531 |
(Arrays.equals(p.fastGetAttributes(), fastGetAttributes()) && |
|
532 |
Arrays.equals(p.fastGetOperations(), fastGetOperations()) && |
|
533 |
Arrays.equals(p.fastGetConstructors(), fastGetConstructors()) && |
|
534 |
Arrays.equals(p.fastGetNotifications(), fastGetNotifications())); |
|
535 |
} |
|
536 |
||
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
537 |
@Override |
2 | 538 |
public int hashCode() { |
539 |
/* Since computing the hashCode is quite expensive, we cache it. |
|
540 |
If by some terrible misfortune the computed value is 0, the |
|
541 |
caching won't work and we will recompute it every time. |
|
542 |
||
543 |
We don't bother synchronizing, because, at worst, n different |
|
544 |
threads will compute the same hashCode at the same time. */ |
|
545 |
if (hashCode != 0) |
|
546 |
return hashCode; |
|
547 |
||
548 |
hashCode = |
|
549 |
getClassName().hashCode() ^ |
|
550 |
getDescriptor().hashCode() ^ |
|
551 |
arrayHashCode(fastGetAttributes()) ^ |
|
552 |
arrayHashCode(fastGetOperations()) ^ |
|
553 |
arrayHashCode(fastGetConstructors()) ^ |
|
554 |
arrayHashCode(fastGetNotifications()); |
|
555 |
||
556 |
return hashCode; |
|
557 |
} |
|
558 |
||
559 |
private static int arrayHashCode(Object[] array) { |
|
560 |
int hash = 0; |
|
561 |
for (int i = 0; i < array.length; i++) |
|
562 |
hash ^= array[i].hashCode(); |
|
563 |
return hash; |
|
564 |
} |
|
565 |
||
566 |
/** |
|
567 |
* Cached results of previous calls to arrayGettersSafe. This is |
|
568 |
* a WeakHashMap so that we don't prevent a class from being |
|
569 |
* garbage collected just because we know whether it's immutable. |
|
570 |
*/ |
|
1510 | 571 |
private static final Map<Class<?>, Boolean> arrayGettersSafeMap = |
572 |
new WeakHashMap<Class<?>, Boolean>(); |
|
2 | 573 |
|
574 |
/** |
|
575 |
* Return true if <code>subclass</code> is known to preserve the |
|
576 |
* immutability of <code>immutableClass</code>. The class |
|
577 |
* <code>immutableClass</code> is a reference class that is known |
|
578 |
* to be immutable. The subclass <code>subclass</code> is |
|
579 |
* considered immutable if it does not override any public method |
|
580 |
* of <code>immutableClass</code> whose name begins with "get". |
|
581 |
* This is obviously not an infallible test for immutability, |
|
582 |
* but it works for the public interfaces of the MBean*Info classes. |
|
583 |
*/ |
|
1510 | 584 |
static boolean arrayGettersSafe(Class<?> subclass, Class<?> immutableClass) { |
2 | 585 |
if (subclass == immutableClass) |
586 |
return true; |
|
587 |
synchronized (arrayGettersSafeMap) { |
|
588 |
Boolean safe = arrayGettersSafeMap.get(subclass); |
|
589 |
if (safe == null) { |
|
590 |
try { |
|
591 |
ArrayGettersSafeAction action = |
|
592 |
new ArrayGettersSafeAction(subclass, immutableClass); |
|
593 |
safe = AccessController.doPrivileged(action); |
|
594 |
} catch (Exception e) { // e.g. SecurityException |
|
595 |
/* We don't know, so we assume it isn't. */ |
|
596 |
safe = false; |
|
597 |
} |
|
598 |
arrayGettersSafeMap.put(subclass, safe); |
|
599 |
} |
|
600 |
return safe; |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
/* |
|
605 |
* The PrivilegedAction stuff is probably overkill. We can be |
|
606 |
* pretty sure the caller does have the required privileges -- a |
|
607 |
* JMX user that can't do reflection can't even use Standard |
|
608 |
* MBeans! But there's probably a performance gain by not having |
|
609 |
* to check the whole call stack. |
|
610 |
*/ |
|
611 |
private static class ArrayGettersSafeAction |
|
612 |
implements PrivilegedAction<Boolean> { |
|
613 |
||
614 |
private final Class<?> subclass; |
|
615 |
private final Class<?> immutableClass; |
|
616 |
||
617 |
ArrayGettersSafeAction(Class<?> subclass, Class<?> immutableClass) { |
|
618 |
this.subclass = subclass; |
|
619 |
this.immutableClass = immutableClass; |
|
620 |
} |
|
621 |
||
622 |
public Boolean run() { |
|
623 |
Method[] methods = immutableClass.getMethods(); |
|
624 |
for (int i = 0; i < methods.length; i++) { |
|
625 |
Method method = methods[i]; |
|
626 |
String methodName = method.getName(); |
|
627 |
if (methodName.startsWith("get") && |
|
628 |
method.getParameterTypes().length == 0 && |
|
629 |
method.getReturnType().isArray()) { |
|
630 |
try { |
|
631 |
Method submethod = |
|
632 |
subclass.getMethod(methodName); |
|
633 |
if (!submethod.equals(method)) |
|
634 |
return false; |
|
635 |
} catch (NoSuchMethodException e) { |
|
636 |
return false; |
|
637 |
} |
|
638 |
} |
|
639 |
} |
|
640 |
return true; |
|
641 |
} |
|
642 |
} |
|
643 |
||
644 |
private static boolean isEqual(String s1, String s2) { |
|
645 |
boolean ret; |
|
646 |
||
647 |
if (s1 == null) { |
|
648 |
ret = (s2 == null); |
|
649 |
} else { |
|
650 |
ret = s1.equals(s2); |
|
651 |
} |
|
652 |
||
653 |
return ret; |
|
654 |
} |
|
655 |
||
656 |
/** |
|
657 |
* Serializes an {@link MBeanInfo} to an {@link ObjectOutputStream}. |
|
658 |
* @serialData |
|
659 |
* For compatibility reasons, an object of this class is serialized as follows. |
|
660 |
* <ul> |
|
661 |
* The method {@link ObjectOutputStream#defaultWriteObject defaultWriteObject()} |
|
662 |
* is called first to serialize the object except the field {@code descriptor} |
|
663 |
* which is declared as transient. The field {@code descriptor} is serialized |
|
664 |
* as follows: |
|
665 |
* <ul> |
|
666 |
* <li> If {@code descriptor} is an instance of the class |
|
667 |
* {@link ImmutableDescriptor}, the method {@link ObjectOutputStream#write |
|
668 |
* write(int val)} is called to write a byte with the value {@code 1}, |
|
669 |
* then the method {@link ObjectOutputStream#writeObject writeObject(Object obj)} |
|
670 |
* is called twice to serialize the field names and the field values of the |
|
671 |
* {@code descriptor}, respectively as a {@code String[]} and an |
|
672 |
* {@code Object[]};</li> |
|
673 |
* <li> Otherwise, the method {@link ObjectOutputStream#write write(int val)} |
|
674 |
* is called to write a byte with the value {@code 0}, then the method |
|
675 |
* {@link ObjectOutputStream#writeObject writeObject(Object obj)} is called |
|
676 |
* to serialize the field {@code descriptor} directly. |
|
677 |
* </ul> |
|
678 |
* </ul> |
|
679 |
* @since 1.6 |
|
680 |
*/ |
|
681 |
private void writeObject(ObjectOutputStream out) throws IOException { |
|
682 |
out.defaultWriteObject(); |
|
683 |
||
684 |
if (descriptor.getClass() == ImmutableDescriptor.class) { |
|
685 |
out.write(1); |
|
686 |
||
687 |
final String[] names = descriptor.getFieldNames(); |
|
688 |
||
689 |
out.writeObject(names); |
|
690 |
out.writeObject(descriptor.getFieldValues(names)); |
|
691 |
} else { |
|
692 |
out.write(0); |
|
693 |
||
694 |
out.writeObject(descriptor); |
|
695 |
} |
|
696 |
} |
|
697 |
||
698 |
/** |
|
699 |
* Deserializes an {@link MBeanInfo} from an {@link ObjectInputStream}. |
|
700 |
* @serialData |
|
701 |
* For compatibility reasons, an object of this class is deserialized as follows. |
|
702 |
* <ul> |
|
703 |
* The method {@link ObjectInputStream#defaultReadObject defaultReadObject()} |
|
704 |
* is called first to deserialize the object except the field |
|
705 |
* {@code descriptor}, which is not serialized in the default way. Then the method |
|
706 |
* {@link ObjectInputStream#read read()} is called to read a byte, the field |
|
707 |
* {@code descriptor} is deserialized according to the value of the byte value: |
|
708 |
* <ul> |
|
709 |
* <li>1. The method {@link ObjectInputStream#readObject readObject()} |
|
710 |
* is called twice to obtain the field names (a {@code String[]}) and |
|
711 |
* the field values (a {@code Object[]}) of the {@code descriptor}. |
|
712 |
* The two obtained values then are used to construct |
|
713 |
* an {@link ImmutableDescriptor} instance for the field |
|
714 |
* {@code descriptor};</li> |
|
715 |
* <li>0. The value for the field {@code descriptor} is obtained directly |
|
716 |
* by calling the method {@link ObjectInputStream#readObject readObject()}. |
|
717 |
* If the obtained value is null, the field {@code descriptor} is set to |
|
718 |
* {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR};</li> |
|
719 |
* <li>-1. This means that there is no byte to read and that the object is from |
|
720 |
* an earlier version of the JMX API. The field {@code descriptor} is set to |
|
721 |
* {@link ImmutableDescriptor#EMPTY_DESCRIPTOR EMPTY_DESCRIPTOR}.</li> |
|
722 |
* <li>Any other value. A {@link StreamCorruptedException} is thrown.</li> |
|
723 |
* </ul> |
|
724 |
* </ul> |
|
725 |
* @since 1.6 |
|
726 |
*/ |
|
727 |
||
728 |
private void readObject(ObjectInputStream in) |
|
729 |
throws IOException, ClassNotFoundException { |
|
730 |
||
731 |
in.defaultReadObject(); |
|
732 |
||
733 |
switch (in.read()) { |
|
734 |
case 1: |
|
735 |
final String[] names = (String[])in.readObject(); |
|
736 |
||
737 |
if (names.length == 0) { |
|
738 |
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR; |
|
739 |
} else { |
|
740 |
final Object[] values = (Object[])in.readObject(); |
|
741 |
descriptor = new ImmutableDescriptor(names, values); |
|
742 |
} |
|
743 |
||
744 |
break; |
|
745 |
case 0: |
|
746 |
descriptor = (Descriptor)in.readObject(); |
|
747 |
||
748 |
if (descriptor == null) { |
|
749 |
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR; |
|
750 |
} |
|
751 |
||
752 |
break; |
|
753 |
case -1: // from an earlier version of the JMX API |
|
754 |
descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR; |
|
755 |
||
756 |
break; |
|
757 |
default: |
|
758 |
throw new StreamCorruptedException("Got unexpected byte."); |
|
759 |
} |
|
760 |
} |
|
1570
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
761 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
762 |
/** |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
763 |
* <p>Return an {@code MBeanInfo} object that is the same as this one |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
764 |
* except that its descriptions are localized in the given locale. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
765 |
* This means the text returned by {@link MBeanInfo#getDescription} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
766 |
* (the description of the MBean itself), and the text returned by the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
767 |
* {@link MBeanFeatureInfo#getDescription getDescription()} method |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
768 |
* for every {@linkplain MBeanAttributeInfo attribute}, {@linkplain |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
769 |
* MBeanOperationInfo operation}, {@linkplain MBeanConstructorInfo |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
770 |
* constructor}, and {@linkplain MBeanNotificationInfo notification} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
771 |
* contained in the {@code MBeanInfo}.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
772 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
773 |
* <p>Here is how the description {@code this.getDescription()} is |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
774 |
* localized.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
775 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
776 |
* <p>First, if the {@linkplain #getDescriptor() descriptor} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
777 |
* of this {@code MBeanInfo} contains a field <code><a |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
778 |
* href="Descriptor.html#locale">"locale"</a></code>, and the value of |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
779 |
* the field is the same as {@code locale.toString()}, then this {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
780 |
* MBeanInfo} is returned. Otherwise, localization proceeds as follows, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
781 |
* and the {@code "locale"} field in the returned {@code MBeanInfo} will |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
782 |
* be {@code locale.toString()}. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
783 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
784 |
* <p>A <em>{@code className}</em> is determined. If this |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
785 |
* {@code MBeanInfo} contains a descriptor with the field |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
786 |
* <a href="Descriptor.html#interfaceClassName">{@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
787 |
* "interfaceClassName"}</a>, then the value of that field is the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
788 |
* {@code className}. Otherwise, it is {@link #getClassName()}. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
789 |
* Everything before the last period (.) in the {@code className} is |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
790 |
* the <em>{@code package}</em>, and everything after is the <em>{@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
791 |
* simpleClassName}</em>. (If there is no period, then the {@code package} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
792 |
* is empty and the {@code simpleClassName} is the same as the {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
793 |
* className}.)</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
794 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
795 |
* <p>A <em>{@code resourceKey}</em> is determined. If this {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
796 |
* MBeanInfo} contains a {@linkplain MBeanInfo#getDescriptor() descriptor} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
797 |
* with a field {@link JMX#DESCRIPTION_RESOURCE_KEY_FIELD |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
798 |
* "descriptionResourceKey"}, the value of the field is |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
799 |
* the {@code resourceKey}. Otherwise, the {@code resourceKey} is {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
800 |
* simpleClassName + ".mbean"}.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
801 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
802 |
* <p>A <em>{@code resourceBundleBaseName}</em> is determined. If |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
803 |
* this {@code MBeanInfo} contains a descriptor with a field {@link |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
804 |
* JMX#DESCRIPTION_RESOURCE_BUNDLE_BASE_NAME_FIELD |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
805 |
* "descriptionResourceBundleBaseName"}, the value of the field |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
806 |
* is the {@code resourceBundleBaseName}. Otherwise, the {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
807 |
* resourceBundleBaseName} is {@code package + ".MBeanDescriptions"}. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
808 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
809 |
* <p>Then, a {@link java.util.ResourceBundle ResourceBundle} is |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
810 |
* determined, using<br> {@link java.util.ResourceBundle#getBundle(String, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
811 |
* Locale, ClassLoader) ResourceBundle.getBundle(resourceBundleBaseName, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
812 |
* locale, loader)}. If this succeeds, and if {@link |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
813 |
* java.util.ResourceBundle#getString(String) getString(resourceKey)} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
814 |
* returns a string, then that string is the localized description. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
815 |
* Otherwise, the original description is unchanged.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
816 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
817 |
* <p>A localized description for an {@code MBeanAttributeInfo} is |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
818 |
* obtained similarly. The default {@code resourceBundleBaseName} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
819 |
* is the same as above. The default description and the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
820 |
* descriptor fields {@code "descriptionResourceKey"} and {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
821 |
* "descriptionResourceBundleBaseName"} come from the {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
822 |
* MBeanAttributeInfo} rather than the {@code MBeanInfo}. If the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
823 |
* attribute's {@linkplain MBeanFeatureInfo#getName() name} is {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
824 |
* Foo} then its default {@code resourceKey} is {@code simpleClassName + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
825 |
* ".attribute.Foo"}.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
826 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
827 |
* <p>Similar rules apply for operations, constructors, and notifications. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
828 |
* If the name of the operation, constructor, or notification is {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
829 |
* Foo} then the default {@code resourceKey} is respectively {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
830 |
* simpleClassName + ".operation.Foo"}, {@code simpleClassName + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
831 |
* ".constructor.Foo"}, or {@code simpleClassName + ".notification.Foo"}. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
832 |
* If two operations or constructors have the same name (overloading) then |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
833 |
* they have the same default {@code resourceKey}; if different localized |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
834 |
* descriptions are needed then a non-default key must be supplied using |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
835 |
* {@code "descriptionResourceKey"}.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
836 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
837 |
* <p>Similar rules also apply for descriptions of parameters ({@link |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
838 |
* MBeanParameterInfo}). The default {@code resourceKey} for a parameter |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
839 |
* whose {@linkplain MBeanFeatureInfo#getName() name} is {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
840 |
* Bar} in an operation or constructor called {@code Foo} is {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
841 |
* simpleClassName + ".operation.Foo.Bar"} or {@code simpleClassName + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
842 |
* ".constructor.Foo.Bar"} respectively.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
843 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
844 |
* <h4>Example</h4> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
845 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
846 |
* <p>Suppose you have an MBean defined by these two Java source files:</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
847 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
848 |
* <pre> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
849 |
* // ConfigurationMBean.java |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
850 |
* package com.example; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
851 |
* public interface ConfigurationMBean { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
852 |
* public String getName(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
853 |
* public void save(String fileName); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
854 |
* } |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
855 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
856 |
* // Configuration.java |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
857 |
* package com.example; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
858 |
* public class Configuration implements ConfigurationMBean { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
859 |
* public Configuration(String defaultName) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
860 |
* ... |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
861 |
* } |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
862 |
* ... |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
863 |
* } |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
864 |
* </pre> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
865 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
866 |
* <p>Then you could define the default descriptions for the MBean, by |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
867 |
* including a resource bundle called {@code com/example/MBeanDescriptions} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
868 |
* with the compiled classes. Most often this is done by creating a file |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
869 |
* {@code MBeanDescriptions.properties} in the same directory as {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
870 |
* ConfigurationMBean.java}. Make sure that this file is copied into the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
871 |
* same place as the compiled classes; in typical build environments that |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
872 |
* will be true by default.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
873 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
874 |
* <p>The file {@code com/example/MBeanDescriptions.properties} might |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
875 |
* look like this:</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
876 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
877 |
* <pre> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
878 |
* # Description of the MBean |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
879 |
* ConfigurationMBean.mbean = Configuration manager |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
880 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
881 |
* # Description of the Name attribute |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
882 |
* ConfigurationMBean.attribute.Name = The name of the configuration |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
883 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
884 |
* # Description of the save operation |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
885 |
* ConfigurationMBean.operation.save = Save the configuration to a file |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
886 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
887 |
* # Description of the parameter to the save operation. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
888 |
* # Parameter names from the original Java source are not available, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
889 |
* # so the default names are p1, p2, etc. If the names were available, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
890 |
* # this would be ConfigurationMBean.operation.save.fileName |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
891 |
* ConfigurationMBean.operation.save.p1 = The name of the file |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
892 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
893 |
* # Description of the constructor. The default name of a constructor is |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
894 |
* # its fully-qualified class name. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
895 |
* ConfigurationMBean.constructor.com.example.Configuration = <!-- |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
896 |
* -->Constructor with name of default file |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
897 |
* # Description of the constructor parameter. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
898 |
* ConfigurationMBean.constructor.com.example.Configuration.p1 = <!-- |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
899 |
* -->Name of the default file |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
900 |
* </pre> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
901 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
902 |
* <p>Starting with this file, you could create descriptions for the French |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
903 |
* locale by creating {@code com/example/MBeanDescriptions_fr.properties}. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
904 |
* The keys in this file are the same as before but the text has been |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
905 |
* translated: |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
906 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
907 |
* <pre> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
908 |
* ConfigurationMBean.mbean = Gestionnaire de configuration |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
909 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
910 |
* ConfigurationMBean.attribute.Name = Le nom de la configuration |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
911 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
912 |
* ConfigurationMBean.operation.save = Sauvegarder la configuration <!-- |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
913 |
* -->dans un fichier |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
914 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
915 |
* ConfigurationMBean.operation.save.p1 = Le nom du fichier |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
916 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
917 |
* ConfigurationMBean.constructor.com.example.Configuration = <!-- |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
918 |
* -->Constructeur avec nom du fichier par défaut |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
919 |
* ConfigurationMBean.constructor.com.example.Configuration.p1 = <!-- |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
920 |
* -->Nom du fichier par défaut |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
921 |
* </pre> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
922 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
923 |
* <p>The descriptions in {@code MBeanDescriptions.properties} and |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
924 |
* {@code MBeanDescriptions_fr.properties} will only be consulted if |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
925 |
* {@code localizeDescriptions} is called, perhaps because the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
926 |
* MBean Server has been wrapped by {@link |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
927 |
* ClientContext#newLocalizeMBeanInfoForwarder} or because the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
928 |
* connector server has been created with the {@link |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
929 |
* javax.management.remote.JMXConnectorServer#LOCALIZE_MBEAN_INFO_FORWARDER |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
930 |
* LOCALIZE_MBEAN_INFO_FORWARDER} option. If you want descriptions |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
931 |
* even when there is no localization step, then you should consider |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
932 |
* using {@link Description @Description} annotations. Annotations |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
933 |
* provide descriptions by default but are overridden if {@code |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
934 |
* localizeDescriptions} is called.</p> |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
935 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
936 |
* @param locale the target locale for descriptions. Cannot be null. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
937 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
938 |
* @param loader the {@code ClassLoader} to use for looking up resource |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
939 |
* bundles. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
940 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
941 |
* @return an {@code MBeanInfo} with descriptions appropriately localized. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
942 |
* |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
943 |
* @throws NullPointerException if {@code locale} is null. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
944 |
*/ |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
945 |
public MBeanInfo localizeDescriptions(Locale locale, ClassLoader loader) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
946 |
if (locale == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
947 |
throw new NullPointerException("locale"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
948 |
Descriptor d = getDescriptor(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
949 |
String mbiLocaleString = (String) d.getFieldValue(JMX.LOCALE_FIELD); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
950 |
if (locale.toString().equals(mbiLocaleString)) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
951 |
return this; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
952 |
return new Rewriter(this, locale, loader).getMBeanInfo(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
953 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
954 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
955 |
private static class Rewriter { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
956 |
private final MBeanInfo mbi; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
957 |
private final ClassLoader loader; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
958 |
private final Locale locale; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
959 |
private final String packageName; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
960 |
private final String simpleClassNamePlusDot; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
961 |
private ResourceBundle defaultBundle; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
962 |
private boolean defaultBundleLoaded; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
963 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
964 |
// ResourceBundle.getBundle throws NullPointerException |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
965 |
// if the loader is null, even though that is perfectly |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
966 |
// valid and means the bootstrap loader. So we work |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
967 |
// around with a ClassLoader that is equivalent to the |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
968 |
// bootstrap loader but is not null. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
969 |
private static final ClassLoader bootstrapLoader = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
970 |
new ClassLoader(null) {}; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
971 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
972 |
Rewriter(MBeanInfo mbi, Locale locale, ClassLoader loader) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
973 |
this.mbi = mbi; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
974 |
this.locale = locale; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
975 |
if (loader == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
976 |
loader = bootstrapLoader; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
977 |
this.loader = loader; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
978 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
979 |
String intfName = (String) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
980 |
mbi.getDescriptor().getFieldValue("interfaceClassName"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
981 |
if (intfName == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
982 |
intfName = mbi.getClassName(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
983 |
int lastDot = intfName.lastIndexOf('.'); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
984 |
this.packageName = intfName.substring(0, lastDot + 1); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
985 |
this.simpleClassNamePlusDot = intfName.substring(lastDot + 1) + "."; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
986 |
// Inner classes show up as Outer$Inner so won't match the dot. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
987 |
// When there is no dot, lastDot is -1, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
988 |
// packageName is empty, and simpleClassNamePlusDot is intfName. |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
989 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
990 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
991 |
MBeanInfo getMBeanInfo() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
992 |
MBeanAttributeInfo[] mbais = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
993 |
rewrite(mbi.getAttributes(), "attribute."); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
994 |
MBeanOperationInfo[] mbois = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
995 |
rewrite(mbi.getOperations(), "operation."); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
996 |
MBeanConstructorInfo[] mbcis = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
997 |
rewrite(mbi.getConstructors(), "constructor."); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
998 |
MBeanNotificationInfo[] mbnis = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
999 |
rewrite(mbi.getNotifications(), "notification."); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1000 |
Descriptor d = mbi.getDescriptor(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1001 |
d = changeLocale(d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1002 |
String description = getDescription(d, "mbean", ""); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1003 |
if (description == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1004 |
description = mbi.getDescription(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1005 |
return new MBeanInfo( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1006 |
mbi.getClassName(), description, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1007 |
mbais, mbcis, mbois, mbnis, d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1008 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1009 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1010 |
private Descriptor changeLocale(Descriptor d) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1011 |
if (d.getFieldValue(JMX.LOCALE_FIELD) != null) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1012 |
Map<String, Object> map = new HashMap<String, Object>(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1013 |
for (String field : d.getFieldNames()) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1014 |
map.put(field, d.getFieldValue(field)); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1015 |
map.remove(JMX.LOCALE_FIELD); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1016 |
d = new ImmutableDescriptor(map); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1017 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1018 |
return ImmutableDescriptor.union( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1019 |
d, new ImmutableDescriptor(JMX.LOCALE_FIELD + "=" + locale)); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1020 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1021 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1022 |
private String getDescription( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1023 |
Descriptor d, String defaultPrefix, String defaultSuffix) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1024 |
ResourceBundle bundle = bundleFromDescriptor(d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1025 |
if (bundle == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1026 |
return null; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1027 |
String key = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1028 |
(String) d.getFieldValue(JMX.DESCRIPTION_RESOURCE_KEY_FIELD); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1029 |
if (key == null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1030 |
key = simpleClassNamePlusDot + defaultPrefix + defaultSuffix; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1031 |
return descriptionFromResource(bundle, key); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1032 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1033 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1034 |
private <T extends MBeanFeatureInfo> T[] rewrite( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1035 |
T[] features, String resourcePrefix) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1036 |
for (int i = 0; i < features.length; i++) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1037 |
T feature = features[i]; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1038 |
Descriptor d = feature.getDescriptor(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1039 |
String description = |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1040 |
getDescription(d, resourcePrefix, feature.getName()); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1041 |
if (description != null && |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1042 |
!description.equals(feature.getDescription())) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1043 |
features[i] = setDescription(feature, description); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1044 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1045 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1046 |
return features; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1047 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1048 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1049 |
private <T extends MBeanFeatureInfo> T setDescription( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1050 |
T feature, String description) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1051 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1052 |
Object newf; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1053 |
String name = feature.getName(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1054 |
Descriptor d = feature.getDescriptor(); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1055 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1056 |
if (feature instanceof MBeanAttributeInfo) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1057 |
MBeanAttributeInfo mbai = (MBeanAttributeInfo) feature; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1058 |
newf = new MBeanAttributeInfo( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1059 |
name, mbai.getType(), description, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1060 |
mbai.isReadable(), mbai.isWritable(), mbai.isIs(), |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1061 |
d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1062 |
} else if (feature instanceof MBeanOperationInfo) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1063 |
MBeanOperationInfo mboi = (MBeanOperationInfo) feature; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1064 |
MBeanParameterInfo[] sig = rewrite( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1065 |
mboi.getSignature(), "operation." + name + "."); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1066 |
newf = new MBeanOperationInfo( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1067 |
name, description, sig, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1068 |
mboi.getReturnType(), mboi.getImpact(), d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1069 |
} else if (feature instanceof MBeanConstructorInfo) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1070 |
MBeanConstructorInfo mbci = (MBeanConstructorInfo) feature; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1071 |
MBeanParameterInfo[] sig = rewrite( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1072 |
mbci.getSignature(), "constructor." + name + "."); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1073 |
newf = new MBeanConstructorInfo( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1074 |
name, description, sig, d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1075 |
} else if (feature instanceof MBeanNotificationInfo) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1076 |
MBeanNotificationInfo mbni = (MBeanNotificationInfo) feature; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1077 |
newf = new MBeanNotificationInfo( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1078 |
mbni.getNotifTypes(), name, description, d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1079 |
} else if (feature instanceof MBeanParameterInfo) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1080 |
MBeanParameterInfo mbpi = (MBeanParameterInfo) feature; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1081 |
newf = new MBeanParameterInfo( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1082 |
name, mbpi.getType(), description, d); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1083 |
} else { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1084 |
logger().log(Level.FINE, "Unknown feature type: " + |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1085 |
feature.getClass()); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1086 |
newf = feature; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1087 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1088 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1089 |
return Util.<T>cast(newf); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1090 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1091 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1092 |
private ResourceBundle bundleFromDescriptor(Descriptor d) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1093 |
String bundleName = (String) d.getFieldValue( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1094 |
JMX.DESCRIPTION_RESOURCE_BUNDLE_BASE_NAME_FIELD); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1095 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1096 |
if (bundleName != null) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1097 |
return getBundle(bundleName); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1098 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1099 |
if (defaultBundleLoaded) |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1100 |
return defaultBundle; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1101 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1102 |
bundleName = packageName + "MBeanDescriptions"; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1103 |
defaultBundle = getBundle(bundleName); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1104 |
defaultBundleLoaded = true; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1105 |
return defaultBundle; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1106 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1107 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1108 |
private String descriptionFromResource( |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1109 |
ResourceBundle bundle, String key) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1110 |
try { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1111 |
return bundle.getString(key); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1112 |
} catch (MissingResourceException e) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1113 |
logger().log(Level.FINEST, "No resource for " + key, e); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1114 |
} catch (Exception e) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1115 |
logger().log(Level.FINE, "Bad resource for " + key, e); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1116 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1117 |
return null; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1118 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1119 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1120 |
private ResourceBundle getBundle(String name) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1121 |
try { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1122 |
return ResourceBundle.getBundle(name, locale, loader); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1123 |
} catch (Exception e) { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1124 |
logger().log(Level.FINE, |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1125 |
"Could not load ResourceBundle " + name, e); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1126 |
return null; |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1127 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1128 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1129 |
|
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1130 |
private Logger logger() { |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1131 |
return Logger.getLogger("javax.management.locale"); |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1132 |
} |
4165709c91e3
5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents:
1513
diff
changeset
|
1133 |
} |
2 | 1134 |
} |