author | dfuchs |
Tue, 09 Dec 2008 20:20:48 +0100 | |
changeset 1709 | 392dd6db361a |
parent 1225 | 6ef6227d36eb |
child 4156 | acaa49a2768a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 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 |
||
28 |
import com.sun.jmx.mbeanserver.GetPropertyAction; |
|
287 | 29 |
import com.sun.jmx.mbeanserver.Util; |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
30 |
import com.sun.jmx.namespace.serial.JMXNamespaceContext; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
31 |
|
2 | 32 |
import java.io.IOException; |
33 |
import java.io.InvalidObjectException; |
|
34 |
import java.io.ObjectInputStream; |
|
35 |
import java.io.ObjectOutputStream; |
|
36 |
import java.io.ObjectStreamField; |
|
37 |
import java.security.AccessController; |
|
38 |
import java.util.Arrays; |
|
39 |
import java.util.Collections; |
|
40 |
import java.util.HashMap; |
|
41 |
import java.util.Hashtable; |
|
42 |
import java.util.Map; |
|
43 |
||
44 |
/** |
|
45 |
* <p>Represents the object name of an MBean, or a pattern that can |
|
46 |
* match the names of several MBeans. Instances of this class are |
|
47 |
* immutable.</p> |
|
48 |
* |
|
49 |
* <p>An instance of this class can be used to represent:</p> |
|
50 |
* <ul> |
|
51 |
* <li>An object name</li> |
|
52 |
* <li>An object name pattern, within the context of a query</li> |
|
53 |
* </ul> |
|
54 |
* |
|
55 |
* <p>An object name consists of two parts, the domain and the key |
|
56 |
* properties.</p> |
|
57 |
* |
|
58 |
* <p>The <em>domain</em> is a string of characters not including |
|
1709
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
59 |
* the character colon (<code>:</code>).</p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
60 |
* <p>Starting with the version 2.0 of the JMX specification, the |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
61 |
* <em>domain</em> can also start with a {@linkplain |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
62 |
* javax.management.namespace#NamespacePrefix namespace prefix} identifying |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
63 |
* the {@linkplain javax.management.namespace namespace} in which the |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
64 |
* MBean is registered. A namespace prefix is a path string where |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
65 |
* elements are separated by a double slash (<code>//</code>). |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
66 |
* It identifies the {@linkplain javax.management.namespace namespace} in |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
67 |
* which the MBean so named is registered.</p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
68 |
* |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
69 |
* <p>For instance the ObjectName <em>bar//baz:k=v</em> identifiies an MBean |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
70 |
* named <em>baz:k=v</em> in the namespace <em>bar</em>. Similarly the |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
71 |
* ObjectName <em>foo//bar//baz:k=v</em> identifiies an MBean named |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
72 |
* <em>baz:k=v</em> in the namespace <em>foo//bar</em>. See the {@linkplain |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
73 |
* javax.management.namespace namespace} documentation for more details.</p> |
2 | 74 |
* |
75 |
* <p>If the domain includes at least one occurrence of the wildcard |
|
76 |
* characters asterisk (<code>*</code>) or question mark |
|
77 |
* (<code>?</code>), then the object name is a pattern. The asterisk |
|
78 |
* matches any sequence of zero or more characters, while the question |
|
1709
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
79 |
* mark matches any single character. <br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
80 |
* A namespace separator <code>//</code> does not match wildcard |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
81 |
* characters unless it is at the very end of the domain string. |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
82 |
* So <em>foo*bar*:*</em> does not match <em>foo//bar:k=v</em> but it |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
83 |
* does match <em>fooxbar//:k=v</em>. |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
84 |
* </p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
85 |
* |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
86 |
* <p>When included in a namespace path the special path element |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
87 |
* <code>**</code> matches any number of sub namespaces |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
88 |
* recursively, but only if used as a complete namespace path element, |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
89 |
* as in <code>**//b//c//D:k=v</code> or <code>a//**//c//D:k=v</code> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
90 |
* - see <a href="#metawildcard">below</a>. |
2 | 91 |
* |
92 |
* <p>If the domain is empty, it will be replaced in certain contexts |
|
93 |
* by the <em>default domain</em> of the MBean server in which the |
|
94 |
* ObjectName is used.</p> |
|
95 |
* |
|
96 |
* <p>The <em>key properties</em> are an unordered set of keys and |
|
97 |
* associated values.</p> |
|
98 |
* |
|
99 |
* <p>Each <em>key</em> is a nonempty string of characters which may |
|
100 |
* not contain any of the characters comma (<code>,</code>), equals |
|
101 |
* (<code>=</code>), colon, asterisk, or question mark. The same key |
|
102 |
* may not occur twice in a given ObjectName.</p> |
|
103 |
* |
|
104 |
* <p>Each <em>value</em> associated with a key is a string of |
|
105 |
* characters that is either unquoted or quoted.</p> |
|
106 |
* |
|
107 |
* <p>An <em>unquoted value</em> is a possibly empty string of |
|
108 |
* characters which may not contain any of the characters comma, |
|
109 |
* equals, colon, or quote.</p> |
|
110 |
* |
|
111 |
* <p>If the <em>unquoted value</em> contains at least one occurrence |
|
112 |
* of the wildcard characters asterisk or question mark, then the object |
|
113 |
* name is a <em>property value pattern</em>. The asterisk matches any |
|
114 |
* sequence of zero or more characters, while the question mark matches |
|
115 |
* any single character.</p> |
|
116 |
* |
|
117 |
* <p>A <em>quoted value</em> consists of a quote (<code>"</code>), |
|
118 |
* followed by a possibly empty string of characters, followed by |
|
119 |
* another quote. Within the string of characters, the backslash |
|
120 |
* (<code>\</code>) has a special meaning. It must be followed by |
|
121 |
* one of the following characters:</p> |
|
122 |
* |
|
123 |
* <ul> |
|
124 |
* <li>Another backslash. The second backslash has no special |
|
125 |
* meaning and the two characters represent a single backslash.</li> |
|
126 |
* |
|
127 |
* <li>The character 'n'. The two characters represent a newline |
|
128 |
* ('\n' in Java).</li> |
|
129 |
* |
|
130 |
* <li>A quote. The two characters represent a quote, and that quote |
|
131 |
* is not considered to terminate the quoted value. An ending closing |
|
132 |
* quote must be present for the quoted value to be valid.</li> |
|
133 |
* |
|
134 |
* <li>A question mark (?) or asterisk (*). The two characters represent |
|
135 |
* a question mark or asterisk respectively.</li> |
|
136 |
* </ul> |
|
137 |
* |
|
138 |
* <p>A quote may not appear inside a quoted value except immediately |
|
139 |
* after an odd number of consecutive backslashes.</p> |
|
140 |
* |
|
141 |
* <p>The quotes surrounding a quoted value, and any backslashes |
|
142 |
* within that value, are considered to be part of the value.</p> |
|
143 |
* |
|
144 |
* <p>If the <em>quoted value</em> contains at least one occurrence of |
|
145 |
* the characters asterisk or question mark and they are not preceded |
|
146 |
* by a backslash, then they are considered as wildcard characters and |
|
147 |
* the object name is a <em>property value pattern</em>. The asterisk |
|
148 |
* matches any sequence of zero or more characters, while the question |
|
149 |
* mark matches any single character.</p> |
|
150 |
* |
|
151 |
* <p>An ObjectName may be a <em>property list pattern</em>. In this |
|
152 |
* case it may have zero or more keys and associated values. It matches |
|
153 |
* a nonpattern ObjectName whose domain matches and that contains the |
|
154 |
* same keys and associated values, as well as possibly other keys and |
|
155 |
* values.</p> |
|
156 |
* |
|
157 |
* <p>An ObjectName is a <em>property value pattern</em> when at least |
|
158 |
* one of its <em>quoted</em> or <em>unquoted</em> key property values |
|
159 |
* contains the wildcard characters asterisk or question mark as described |
|
160 |
* above. In this case it has one or more keys and associated values, with |
|
161 |
* at least one of the values containing wildcard characters. It matches a |
|
162 |
* nonpattern ObjectName whose domain matches and that contains the same |
|
163 |
* keys whose values match; if the property value pattern is also a |
|
164 |
* property list pattern then the nonpattern ObjectName can contain |
|
165 |
* other keys and values.</p> |
|
166 |
* |
|
167 |
* <p>An ObjectName is a <em>property pattern</em> if it is either a |
|
168 |
* <em>property list pattern</em> or a <em>property value pattern</em> |
|
169 |
* or both.</p> |
|
170 |
* |
|
171 |
* <p>An ObjectName is a pattern if its domain contains a wildcard or |
|
172 |
* if the ObjectName is a property pattern.</p> |
|
173 |
* |
|
174 |
* <p>If an ObjectName is not a pattern, it must contain at least one |
|
175 |
* key with its associated value.</p> |
|
176 |
* |
|
177 |
* <p>Examples of ObjectName patterns are:</p> |
|
178 |
* |
|
179 |
* <ul> |
|
180 |
* <li>{@code *:type=Foo,name=Bar} to match names in any domain whose |
|
181 |
* exact set of keys is {@code type=Foo,name=Bar}.</li> |
|
182 |
* <li>{@code d:type=Foo,name=Bar,*} to match names in the domain |
|
183 |
* {@code d} that have the keys {@code type=Foo,name=Bar} plus |
|
184 |
* zero or more other keys.</li> |
|
185 |
* <li>{@code *:type=Foo,name=Bar,*} to match names in any domain |
|
186 |
* that has the keys {@code type=Foo,name=Bar} plus zero or |
|
187 |
* more other keys.</li> |
|
188 |
* <li>{@code d:type=F?o,name=Bar} will match e.g. |
|
189 |
* {@code d:type=Foo,name=Bar} and {@code d:type=Fro,name=Bar}.</li> |
|
190 |
* <li>{@code d:type=F*o,name=Bar} will match e.g. |
|
191 |
* {@code d:type=Fo,name=Bar} and {@code d:type=Frodo,name=Bar}.</li> |
|
192 |
* <li>{@code d:type=Foo,name="B*"} will match e.g. |
|
193 |
* {@code d:type=Foo,name="Bling"}. Wildcards are recognized even |
|
194 |
* inside quotes, and like other special characters can be escaped |
|
195 |
* with {@code \}.</li> |
|
196 |
* </ul> |
|
197 |
* |
|
1709
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
198 |
* <p id="metawildcard"><b>Pattern and namespaces:</b></p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
199 |
* <p>In an object name pattern, a path element |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
200 |
* of exactly <code>**</code> corresponds to a meta |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
201 |
* wildcard that will match any number of sub namespaces.<br>Hence:</p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
202 |
* <table border="0" cellpadding="5"> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
203 |
* <thead><th>pattern</th><th>matches</th><th>doesn't match</th></thead> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
204 |
* <tbody> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
205 |
* <tr><td><ul><li><code>**//D:k=v</code></li></ul></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
206 |
* <td><code>a//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
207 |
* <code>a//b//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
208 |
* <code>a//b//c//D:k=v</code></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
209 |
* <td><code>D:k=v</code></td></tr> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
210 |
* <tr><td><ul><li><code>a//**//D:k=v</code></li></ul></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
211 |
* <td><code>a//b//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
212 |
* <code>a//b//c//D:k=v</code></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
213 |
* <td><code>b//b//c//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
214 |
* <code>a//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
215 |
* <code>D:k=v</code></td></tr> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
216 |
* <tr><td><ul><li><code>a//**//e//D:k=v</code></li></ul></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
217 |
* <td><code>a//b//e//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
218 |
* <code>a//b//c//e//D:k=v</code></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
219 |
* <td><code>a//b//c//c//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
220 |
* <code>b//b//c//e//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
221 |
* <code>a//e//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
222 |
* <code>e//D:k=v</code></td></tr> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
223 |
* <tr><td><ul><li><code>a//b**//e//D:k=v</code></li></ul></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
224 |
* <td><code>a//b//e//D:k=v</code></td> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
225 |
* <td><code>a//b//c//e//D:k=v</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
226 |
* because in that case <code>b**</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
227 |
* is not a meta-wildcard - and <code>b**</code><br> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
228 |
* is thus equivalent to <code>b*</code>.</td></tr> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
229 |
* </tbody> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
230 |
* </table> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
231 |
*</ul> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
232 |
* </p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
233 |
* <p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
234 |
* <b>Note:</b> Although ObjectName patterns where the characters |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
235 |
* <code>*</code> and <code>?</code> appear in the namespace path are legal, |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
236 |
* they are not valid in the {@code name} parameter of the MBean Server's |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
237 |
* {@link MBeanServer#queryNames queryNames} and {@link MBeanServer#queryMBeans |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
238 |
* queryMBeans} methods. See the |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
239 |
* <a href="namespace/package-summary.html#RejectedNamespacePatterns"><!-- |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
240 |
* -->namespaces documentation</a> for more details. |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
241 |
* </p> |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
242 |
* |
2 | 243 |
* <p>An ObjectName can be written as a String with the following |
244 |
* elements in order:</p> |
|
245 |
* |
|
246 |
* <ul> |
|
247 |
* <li>The domain. |
|
248 |
* <li>A colon (<code>:</code>). |
|
249 |
* <li>A key property list as defined below. |
|
250 |
* </ul> |
|
251 |
* |
|
252 |
* <p>A key property list written as a String is a comma-separated |
|
253 |
* list of elements. Each element is either an asterisk or a key |
|
254 |
* property. A key property consists of a key, an equals |
|
255 |
* (<code>=</code>), and the associated value.</p> |
|
256 |
* |
|
257 |
* <p>At most one element of a key property list may be an asterisk. |
|
258 |
* If the key property list contains an asterisk element, the |
|
259 |
* ObjectName is a property list pattern.</p> |
|
260 |
* |
|
261 |
* <p>Spaces have no special significance in a String representing an |
|
262 |
* ObjectName. For example, the String: |
|
263 |
* <pre> |
|
264 |
* domain: key1 = value1 , key2 = value2 |
|
265 |
* </pre> |
|
266 |
* represents an ObjectName with two keys. The name of each key |
|
267 |
* contains six characters, of which the first and last are spaces. |
|
268 |
* The value associated with the key <code>" key1 "</code> |
|
269 |
* also begins and ends with a space.</p> |
|
270 |
* |
|
271 |
* <p>In addition to the restrictions on characters spelt out above, |
|
272 |
* no part of an ObjectName may contain a newline character |
|
273 |
* (<code>'\n'</code>), whether the domain, a key, or a value, whether |
|
274 |
* quoted or unquoted. The newline character can be represented in a |
|
275 |
* quoted value with the sequence <code>\n</code>. |
|
276 |
* |
|
277 |
* <p>The rules on special characters and quoting apply regardless of |
|
278 |
* which constructor is used to make an ObjectName.</p> |
|
279 |
* |
|
280 |
* <p>To avoid collisions between MBeans supplied by different |
|
281 |
* vendors, a useful convention is to begin the domain name with the |
|
282 |
* reverse DNS name of the organization that specifies the MBeans, |
|
283 |
* followed by a period and a string whose interpretation is |
|
284 |
* determined by that organization. For example, MBeans specified by |
|
285 |
* Sun Microsystems Inc., DNS name <code>sun.com</code>, would have |
|
286 |
* domains such as <code>com.sun.MyDomain</code>. This is essentially |
|
287 |
* the same convention as for Java-language package names.</p> |
|
288 |
* |
|
289 |
* <p>The <b>serialVersionUID</b> of this class is <code>1081892073854801359L</code>. |
|
290 |
* |
|
291 |
* @since 1.5 |
|
292 |
*/ |
|
293 |
@SuppressWarnings("serial") // don't complain serialVersionUID not constant |
|
471
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
287
diff
changeset
|
294 |
public class ObjectName implements Comparable<ObjectName>, QueryExp { |
2 | 295 |
|
296 |
/** |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
297 |
* The sequence of characters used to separate name spaces in a name space |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
298 |
* path. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
299 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
300 |
* @see javax.management.namespace |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
301 |
* @since 1.7 |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
302 |
**/ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
303 |
public static final String NAMESPACE_SEPARATOR = "//"; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
304 |
private static final int NAMESPACE_SEPARATOR_LENGTH = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
305 |
NAMESPACE_SEPARATOR.length(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
306 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
307 |
/** |
2 | 308 |
* A structure recording property structure and |
309 |
* proposing minimal services |
|
310 |
*/ |
|
311 |
private static class Property { |
|
312 |
||
313 |
int _key_index; |
|
314 |
int _key_length; |
|
315 |
int _value_length; |
|
316 |
||
317 |
/** |
|
318 |
* Constructor. |
|
319 |
*/ |
|
320 |
Property(int key_index, int key_length, int value_length) { |
|
321 |
_key_index = key_index; |
|
322 |
_key_length = key_length; |
|
323 |
_value_length = value_length; |
|
324 |
} |
|
325 |
||
326 |
/** |
|
327 |
* Assigns the key index of property |
|
328 |
*/ |
|
329 |
void setKeyIndex(int key_index) { |
|
330 |
_key_index = key_index; |
|
331 |
} |
|
332 |
||
333 |
/** |
|
334 |
* Returns a key string for receiver key |
|
335 |
*/ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
336 |
String getKeyString(String name, int offset) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
337 |
final int start = _key_index+offset; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
338 |
return name.substring(start, start + _key_length); |
2 | 339 |
} |
340 |
||
341 |
/** |
|
342 |
* Returns a value string for receiver key |
|
343 |
*/ |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
344 |
String getValueString(String name, int offset) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
345 |
final int in_begin = _key_index + offset + _key_length + 1; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
346 |
final int out_end = in_begin + _value_length; |
2 | 347 |
return name.substring(in_begin, out_end); |
348 |
} |
|
349 |
} |
|
350 |
||
351 |
/** |
|
352 |
* Marker class for value pattern property. |
|
353 |
*/ |
|
354 |
private static class PatternProperty extends Property { |
|
355 |
/** |
|
356 |
* Constructor. |
|
357 |
*/ |
|
358 |
PatternProperty(int key_index, int key_length, int value_length) { |
|
359 |
super(key_index, key_length, value_length); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
// Inner classes <======================================== |
|
364 |
||
365 |
||
366 |
||
367 |
// Private fields ----------------------------------------> |
|
368 |
||
369 |
||
370 |
// Serialization compatibility stuff --------------------> |
|
371 |
||
372 |
// Two serial forms are supported in this class. The selected form depends |
|
373 |
// on system property "jmx.serial.form": |
|
374 |
// - "1.0" for JMX 1.0 |
|
375 |
// - any other value for JMX 1.1 and higher |
|
376 |
// |
|
377 |
// Serial version for old serial form |
|
378 |
private static final long oldSerialVersionUID = -5467795090068647408L; |
|
379 |
// |
|
380 |
// Serial version for new serial form |
|
381 |
private static final long newSerialVersionUID = 1081892073854801359L; |
|
382 |
// |
|
383 |
// Serializable fields in old serial form |
|
384 |
private static final ObjectStreamField[] oldSerialPersistentFields = |
|
385 |
{ |
|
386 |
new ObjectStreamField("domain", String.class), |
|
387 |
new ObjectStreamField("propertyList", Hashtable.class), |
|
388 |
new ObjectStreamField("propertyListString", String.class), |
|
389 |
new ObjectStreamField("canonicalName", String.class), |
|
390 |
new ObjectStreamField("pattern", Boolean.TYPE), |
|
391 |
new ObjectStreamField("propertyPattern", Boolean.TYPE) |
|
392 |
}; |
|
393 |
// |
|
394 |
// Serializable fields in new serial form |
|
395 |
private static final ObjectStreamField[] newSerialPersistentFields = { }; |
|
396 |
// |
|
397 |
// Actual serial version and serial form |
|
398 |
private static final long serialVersionUID; |
|
399 |
private static final ObjectStreamField[] serialPersistentFields; |
|
400 |
private static boolean compat = false; |
|
401 |
static { |
|
402 |
try { |
|
403 |
GetPropertyAction act = new GetPropertyAction("jmx.serial.form"); |
|
404 |
String form = AccessController.doPrivileged(act); |
|
405 |
compat = (form != null && form.equals("1.0")); |
|
406 |
} catch (Exception e) { |
|
407 |
// OK: exception means no compat with 1.0, too bad |
|
408 |
} |
|
409 |
if (compat) { |
|
410 |
serialPersistentFields = oldSerialPersistentFields; |
|
411 |
serialVersionUID = oldSerialVersionUID; |
|
412 |
} else { |
|
413 |
serialPersistentFields = newSerialPersistentFields; |
|
414 |
serialVersionUID = newSerialVersionUID; |
|
415 |
} |
|
416 |
} |
|
417 |
||
418 |
// |
|
419 |
// Serialization compatibility stuff <============================== |
|
420 |
||
421 |
// Class private fields -----------------------------------> |
|
422 |
||
423 |
/** |
|
424 |
* a shared empty array for empty property lists |
|
425 |
*/ |
|
426 |
static final private Property[] _Empty_property_array = new Property[0]; |
|
427 |
||
428 |
||
429 |
// Class private fields <============================== |
|
430 |
||
431 |
// Instance private fields -----------------------------------> |
|
432 |
||
433 |
/** |
|
434 |
* a String containing the canonical name |
|
435 |
*/ |
|
436 |
private transient String _canonicalName; |
|
437 |
||
438 |
||
439 |
/** |
|
440 |
* An array of properties in the same seq order as time creation |
|
441 |
*/ |
|
442 |
private transient Property[] _kp_array; |
|
443 |
||
444 |
/** |
|
445 |
* An array of properties in the same seq order as canonical order |
|
446 |
*/ |
|
447 |
private transient Property[] _ca_array; |
|
448 |
||
449 |
||
450 |
/** |
|
451 |
* The length of the domain part of built objectname |
|
452 |
*/ |
|
453 |
private transient int _domain_length = 0; |
|
454 |
||
455 |
||
456 |
/** |
|
457 |
* The propertyList of built object name. Initialized lazily. |
|
458 |
* Table that contains all the pairs (key,value) for this ObjectName. |
|
459 |
*/ |
|
460 |
private transient Map<String,String> _propertyList; |
|
461 |
||
462 |
/** |
|
463 |
* boolean that declares if this ObjectName domain part is a pattern |
|
464 |
*/ |
|
465 |
private transient boolean _domain_pattern = false; |
|
466 |
||
467 |
/** |
|
468 |
* boolean that declares if this ObjectName contains a pattern on the |
|
469 |
* key property list |
|
470 |
*/ |
|
471 |
private transient boolean _property_list_pattern = false; |
|
472 |
||
473 |
/** |
|
474 |
* boolean that declares if this ObjectName contains a pattern on the |
|
475 |
* value of at least one key property |
|
476 |
*/ |
|
477 |
private transient boolean _property_value_pattern = false; |
|
478 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
479 |
private ObjectName(String newDomain, ObjectName aname) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
480 |
throws MalformedObjectNameException{ |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
481 |
copyToOtherDomain(newDomain,aname); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
482 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
483 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
484 |
private void copyToOtherDomain(String domain, ObjectName aname) |
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
485 |
throws MalformedObjectNameException { |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
486 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
487 |
// The domain cannot be null |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
488 |
if (domain == null) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
489 |
throw new NullPointerException("domain cannot be null"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
490 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
491 |
// The key property list cannot be null |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
492 |
if (aname == null) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
493 |
throw new MalformedObjectNameException( |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
494 |
"key property list cannot be empty"); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
495 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
496 |
// checks domain validity. A side effect of this method is also to |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
497 |
// set the _domain_pattern flag. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
498 |
if (!isDomain(domain)) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
499 |
throw new MalformedObjectNameException("Invalid domain: " + domain); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
500 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
501 |
// init canonicalname |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
502 |
_domain_length = domain.length(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
503 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
504 |
_canonicalName = (domain + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
505 |
aname._canonicalName.substring(aname._domain_length)).intern(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
506 |
_kp_array = aname._kp_array; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
507 |
_ca_array = aname._ca_array; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
508 |
_propertyList = aname._propertyList; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
509 |
_property_list_pattern = aname._property_list_pattern; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
510 |
_property_value_pattern = aname._property_value_pattern; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
511 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
512 |
|
2 | 513 |
// Instance private fields <======================================= |
514 |
||
515 |
// Private fields <======================================== |
|
516 |
||
517 |
||
518 |
// Private methods ----------------------------------------> |
|
519 |
||
520 |
// Category : Instance construction -------------------------> |
|
521 |
||
522 |
/** |
|
523 |
* Initializes this {@link ObjectName} from the given string |
|
524 |
* representation. |
|
525 |
* |
|
526 |
* @param name A string representation of the {@link ObjectName} |
|
527 |
* |
|
528 |
* @exception MalformedObjectNameException The string passed as a |
|
529 |
* parameter does not have the right format. |
|
530 |
* @exception NullPointerException The <code>name</code> parameter |
|
531 |
* is null. |
|
532 |
*/ |
|
533 |
private void construct(String name) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
534 |
throws MalformedObjectNameException { |
2 | 535 |
|
536 |
// The name cannot be null |
|
537 |
if (name == null) |
|
538 |
throw new NullPointerException("name cannot be null"); |
|
539 |
||
540 |
// Test if the name is empty |
|
541 |
if (name.length() == 0) { |
|
542 |
// this is equivalent to the whole word query object name. |
|
543 |
_canonicalName = "*:*"; |
|
544 |
_kp_array = _Empty_property_array; |
|
545 |
_ca_array = _Empty_property_array; |
|
546 |
_domain_length = 1; |
|
547 |
_propertyList = null; |
|
548 |
_domain_pattern = true; |
|
549 |
_property_list_pattern = true; |
|
550 |
_property_value_pattern = false; |
|
551 |
return; |
|
552 |
} |
|
553 |
||
554 |
// initialize parsing of the string |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
555 |
final char[] name_chars = name.toCharArray(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
556 |
final int len = name_chars.length; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
557 |
final char[] canonical_chars = new char[len]; // canonical form will |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
558 |
// be same length at most |
2 | 559 |
int cname_index = 0; |
560 |
int index = 0; |
|
561 |
char c, c1; |
|
562 |
||
563 |
// parses domain part |
|
564 |
domain_parsing: |
|
565 |
while (index < len) { |
|
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
471
diff
changeset
|
566 |
switch (name_chars[index]) { |
2 | 567 |
case ':' : |
568 |
_domain_length = index++; |
|
569 |
break domain_parsing; |
|
570 |
case '=' : |
|
571 |
// ":" omission check. |
|
572 |
// |
|
573 |
// Although "=" is a valid character in the domain part |
|
574 |
// it is true that it is rarely used in the real world. |
|
575 |
// So check straight away if the ":" has been omitted |
|
576 |
// from the ObjectName. This allows us to provide a more |
|
577 |
// accurate exception message. |
|
578 |
int i = ++index; |
|
579 |
while ((i < len) && (name_chars[i++] != ':')) |
|
580 |
if (i == len) |
|
581 |
throw new MalformedObjectNameException( |
|
582 |
"Domain part must be specified"); |
|
583 |
break; |
|
584 |
case '\n' : |
|
585 |
throw new MalformedObjectNameException( |
|
586 |
"Invalid character '\\n' in domain name"); |
|
587 |
case '*' : |
|
588 |
case '?' : |
|
589 |
_domain_pattern = true; |
|
590 |
index++; |
|
591 |
break; |
|
592 |
default : |
|
593 |
index++; |
|
594 |
break; |
|
595 |
} |
|
596 |
} |
|
597 |
||
598 |
// check for non-empty properties |
|
599 |
if (index == len) |
|
600 |
throw new MalformedObjectNameException( |
|
601 |
"Key properties cannot be empty"); |
|
602 |
||
603 |
// we have got the domain part, begins building of _canonicalName |
|
604 |
System.arraycopy(name_chars, 0, canonical_chars, 0, _domain_length); |
|
605 |
canonical_chars[_domain_length] = ':'; |
|
606 |
cname_index = _domain_length + 1; |
|
607 |
||
608 |
// parses property list |
|
609 |
Property prop; |
|
610 |
Map<String,Property> keys_map = new HashMap<String,Property>(); |
|
611 |
String[] keys; |
|
612 |
String key_name; |
|
613 |
boolean quoted_value; |
|
614 |
int property_index = 0; |
|
615 |
int in_index; |
|
616 |
int key_index, key_length, value_index, value_length; |
|
617 |
||
618 |
keys = new String[10]; |
|
619 |
_kp_array = new Property[10]; |
|
620 |
_property_list_pattern = false; |
|
621 |
_property_value_pattern = false; |
|
622 |
||
623 |
while (index < len) { |
|
624 |
c = name_chars[index]; |
|
625 |
||
626 |
// case of pattern properties |
|
627 |
if (c == '*') { |
|
628 |
if (_property_list_pattern) |
|
629 |
throw new MalformedObjectNameException( |
|
630 |
"Cannot have several '*' characters in pattern " + |
|
631 |
"property list"); |
|
632 |
else { |
|
633 |
_property_list_pattern = true; |
|
634 |
if ((++index < len ) && (name_chars[index] != ',')) |
|
635 |
throw new MalformedObjectNameException( |
|
636 |
"Invalid character found after '*': end of " + |
|
637 |
"name or ',' expected"); |
|
638 |
else if (index == len) { |
|
639 |
if (property_index == 0) { |
|
640 |
// empty properties case |
|
641 |
_kp_array = _Empty_property_array; |
|
642 |
_ca_array = _Empty_property_array; |
|
643 |
_propertyList = Collections.emptyMap(); |
|
644 |
} |
|
645 |
break; |
|
646 |
} else { |
|
647 |
// correct pattern spec in props, continue |
|
648 |
index++; |
|
649 |
continue; |
|
650 |
} |
|
651 |
} |
|
652 |
} |
|
653 |
||
654 |
// standard property case, key part |
|
655 |
in_index = index; |
|
656 |
key_index = in_index; |
|
657 |
if (name_chars[in_index] == '=') |
|
658 |
throw new MalformedObjectNameException("Invalid key (empty)"); |
|
659 |
while ((in_index < len) && ((c1 = name_chars[in_index++]) != '=')) |
|
660 |
switch (c1) { |
|
661 |
// '=' considered to introduce value part |
|
662 |
case '*' : |
|
663 |
case '?' : |
|
664 |
case ',' : |
|
665 |
case ':' : |
|
666 |
case '\n' : |
|
667 |
final String ichar = ((c1=='\n')?"\\n":""+c1); |
|
668 |
throw new MalformedObjectNameException( |
|
669 |
"Invalid character '" + ichar + |
|
670 |
"' in key part of property"); |
|
671 |
} |
|
672 |
if (name_chars[in_index - 1] != '=') |
|
673 |
throw new MalformedObjectNameException( |
|
674 |
"Unterminated key property part"); |
|
675 |
value_index = in_index; // in_index pointing after '=' char |
|
676 |
key_length = value_index - key_index - 1; // found end of key |
|
677 |
||
678 |
// standard property case, value part |
|
679 |
boolean value_pattern = false; |
|
680 |
if (in_index < len && name_chars[in_index] == '\"') { |
|
681 |
quoted_value = true; |
|
682 |
// the case of quoted value part |
|
683 |
quoted_value_parsing: |
|
684 |
while ((++in_index < len) && |
|
685 |
((c1 = name_chars[in_index]) != '\"')) { |
|
686 |
// the case of an escaped character |
|
687 |
if (c1 == '\\') { |
|
688 |
if (++in_index == len) |
|
689 |
throw new MalformedObjectNameException( |
|
690 |
"Unterminated quoted value"); |
|
691 |
switch (c1 = name_chars[in_index]) { |
|
692 |
case '\\' : |
|
693 |
case '\"' : |
|
694 |
case '?' : |
|
695 |
case '*' : |
|
696 |
case 'n' : |
|
697 |
break; // valid character |
|
698 |
default : |
|
699 |
throw new MalformedObjectNameException( |
|
700 |
"Invalid escape sequence '\\" + |
|
701 |
c1 + "' in quoted value"); |
|
702 |
} |
|
703 |
} else if (c1 == '\n') { |
|
704 |
throw new MalformedObjectNameException( |
|
705 |
"Newline in quoted value"); |
|
706 |
} else { |
|
707 |
switch (c1) { |
|
708 |
case '?' : |
|
709 |
case '*' : |
|
710 |
value_pattern = true; |
|
711 |
break; |
|
712 |
} |
|
713 |
} |
|
714 |
} |
|
715 |
if (in_index == len) |
|
716 |
throw new MalformedObjectNameException( |
|
717 |
"Unterminated quoted value"); |
|
718 |
else value_length = ++in_index - value_index; |
|
719 |
} else { |
|
720 |
// the case of standard value part |
|
721 |
quoted_value = false; |
|
722 |
while ((in_index < len) && ((c1 = name_chars[in_index]) != ',')) |
|
723 |
switch (c1) { |
|
724 |
// ',' considered to be the value separator |
|
725 |
case '*' : |
|
726 |
case '?' : |
|
727 |
value_pattern = true; |
|
728 |
in_index++; |
|
729 |
break; |
|
730 |
case '=' : |
|
731 |
case ':' : |
|
732 |
case '"' : |
|
733 |
case '\n' : |
|
734 |
final String ichar = ((c1=='\n')?"\\n":""+c1); |
|
735 |
throw new MalformedObjectNameException( |
|
526
61ba2d5ea9da
6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents:
471
diff
changeset
|
736 |
"Invalid character '" + ichar + |
2 | 737 |
"' in value part of property"); |
738 |
default : |
|
739 |
in_index++; |
|
740 |
break; |
|
741 |
} |
|
742 |
value_length = in_index - value_index; |
|
743 |
} |
|
744 |
||
745 |
// Parsed property, checks the end of name |
|
746 |
if (in_index == len - 1) { |
|
747 |
if (quoted_value) |
|
748 |
throw new MalformedObjectNameException( |
|
749 |
"Invalid ending character `" + |
|
750 |
name_chars[in_index] + "'"); |
|
751 |
else throw new MalformedObjectNameException( |
|
752 |
"Invalid ending comma"); |
|
753 |
} else in_index++; |
|
754 |
||
755 |
// we got the key and value part, prepare a property for this |
|
756 |
if (!value_pattern) { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
757 |
prop = new Property(key_index-_domain_length, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
758 |
key_length, value_length); |
2 | 759 |
} else { |
760 |
_property_value_pattern = true; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
761 |
prop = new PatternProperty(key_index-_domain_length, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
762 |
key_length, value_length); |
2 | 763 |
} |
764 |
key_name = name.substring(key_index, key_index + key_length); |
|
765 |
||
766 |
if (property_index == keys.length) { |
|
767 |
String[] tmp_string_array = new String[property_index + 10]; |
|
768 |
System.arraycopy(keys, 0, tmp_string_array, 0, property_index); |
|
769 |
keys = tmp_string_array; |
|
770 |
} |
|
771 |
keys[property_index] = key_name; |
|
772 |
||
773 |
addProperty(prop, property_index, keys_map, key_name); |
|
774 |
property_index++; |
|
775 |
index = in_index; |
|
776 |
} |
|
777 |
||
778 |
// computes and set canonical name |
|
779 |
setCanonicalName(name_chars, canonical_chars, keys, |
|
780 |
keys_map, cname_index, property_index); |
|
781 |
} |
|
782 |
||
783 |
/** |
|
784 |
* Construct an ObjectName from a domain and a Hashtable. |
|
785 |
* |
|
786 |
* @param domain Domain of the ObjectName. |
|
787 |
* @param props Map containing couples <i>key</i> -> <i>value</i>. |
|
788 |
* |
|
789 |
* @exception MalformedObjectNameException The <code>domain</code> |
|
790 |
* contains an illegal character, or one of the keys or values in |
|
791 |
* <code>table</code> contains an illegal character, or one of the |
|
792 |
* values in <code>table</code> does not follow the rules for quoting. |
|
793 |
* @exception NullPointerException One of the parameters is null. |
|
794 |
*/ |
|
795 |
private void construct(String domain, Map<String,String> props) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
796 |
throws MalformedObjectNameException { |
2 | 797 |
|
798 |
// The domain cannot be null |
|
799 |
if (domain == null) |
|
800 |
throw new NullPointerException("domain cannot be null"); |
|
801 |
||
802 |
// The key property list cannot be null |
|
803 |
if (props == null) |
|
804 |
throw new NullPointerException("key property list cannot be null"); |
|
805 |
||
806 |
// The key property list cannot be empty |
|
807 |
if (props.isEmpty()) |
|
808 |
throw new MalformedObjectNameException( |
|
809 |
"key property list cannot be empty"); |
|
810 |
||
811 |
// checks domain validity |
|
812 |
if (!isDomain(domain)) |
|
813 |
throw new MalformedObjectNameException("Invalid domain: " + domain); |
|
814 |
||
815 |
// init canonicalname |
|
816 |
final StringBuilder sb = new StringBuilder(); |
|
817 |
sb.append(domain).append(':'); |
|
818 |
_domain_length = domain.length(); |
|
819 |
||
820 |
// allocates the property array |
|
821 |
int nb_props = props.size(); |
|
822 |
_kp_array = new Property[nb_props]; |
|
823 |
||
824 |
String[] keys = new String[nb_props]; |
|
825 |
final Map<String,Property> keys_map = new HashMap<String,Property>(); |
|
826 |
Property prop; |
|
827 |
int key_index; |
|
828 |
int i = 0; |
|
829 |
for (Map.Entry<String,String> entry : props.entrySet()) { |
|
830 |
if (sb.length() > 0) |
|
831 |
sb.append(","); |
|
832 |
String key = entry.getKey(); |
|
833 |
String value; |
|
834 |
try { |
|
835 |
value = entry.getValue(); |
|
836 |
} catch (ClassCastException e) { |
|
837 |
throw new MalformedObjectNameException(e.getMessage()); |
|
838 |
} |
|
839 |
key_index = sb.length(); |
|
840 |
checkKey(key); |
|
841 |
sb.append(key); |
|
842 |
keys[i] = key; |
|
843 |
sb.append("="); |
|
844 |
boolean value_pattern = checkValue(value); |
|
845 |
sb.append(value); |
|
846 |
if (!value_pattern) { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
847 |
prop = new Property(key_index-_domain_length, |
2 | 848 |
key.length(), |
849 |
value.length()); |
|
850 |
} else { |
|
851 |
_property_value_pattern = true; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
852 |
prop = new PatternProperty(key_index-_domain_length, |
2 | 853 |
key.length(), |
854 |
value.length()); |
|
855 |
} |
|
856 |
addProperty(prop, i, keys_map, key); |
|
857 |
i++; |
|
858 |
} |
|
859 |
||
860 |
// initialize canonical name and data structure |
|
861 |
int len = sb.length(); |
|
862 |
char[] initial_chars = new char[len]; |
|
863 |
sb.getChars(0, len, initial_chars, 0); |
|
864 |
char[] canonical_chars = new char[len]; |
|
865 |
System.arraycopy(initial_chars, 0, canonical_chars, 0, |
|
866 |
_domain_length + 1); |
|
867 |
setCanonicalName(initial_chars, canonical_chars, keys, keys_map, |
|
868 |
_domain_length + 1, _kp_array.length); |
|
869 |
} |
|
870 |
// Category : Instance construction <============================== |
|
871 |
||
872 |
// Category : Internal utilities ------------------------------> |
|
873 |
||
874 |
/** |
|
875 |
* Add passed property to the list at the given index |
|
876 |
* for the passed key name |
|
877 |
*/ |
|
878 |
private void addProperty(Property prop, int index, |
|
879 |
Map<String,Property> keys_map, String key_name) |
|
880 |
throws MalformedObjectNameException { |
|
881 |
||
882 |
if (keys_map.containsKey(key_name)) throw new |
|
883 |
MalformedObjectNameException("key `" + |
|
884 |
key_name +"' already defined"); |
|
885 |
||
886 |
// if no more space for property arrays, have to increase it |
|
887 |
if (index == _kp_array.length) { |
|
888 |
Property[] tmp_prop_array = new Property[index + 10]; |
|
889 |
System.arraycopy(_kp_array, 0, tmp_prop_array, 0, index); |
|
890 |
_kp_array = tmp_prop_array; |
|
891 |
} |
|
892 |
_kp_array[index] = prop; |
|
893 |
keys_map.put(key_name, prop); |
|
894 |
} |
|
895 |
||
896 |
/** |
|
897 |
* Sets the canonical name of receiver from input 'specified_chars' |
|
898 |
* array, by filling 'canonical_chars' array with found 'nb-props' |
|
899 |
* properties starting at position 'prop_index'. |
|
900 |
*/ |
|
901 |
private void setCanonicalName(char[] specified_chars, |
|
902 |
char[] canonical_chars, |
|
903 |
String[] keys, Map<String,Property> keys_map, |
|
904 |
int prop_index, int nb_props) { |
|
905 |
||
906 |
// Sort the list of found properties |
|
907 |
if (_kp_array != _Empty_property_array) { |
|
908 |
String[] tmp_keys = new String[nb_props]; |
|
909 |
Property[] tmp_props = new Property[nb_props]; |
|
910 |
||
911 |
System.arraycopy(keys, 0, tmp_keys, 0, nb_props); |
|
912 |
Arrays.sort(tmp_keys); |
|
913 |
keys = tmp_keys; |
|
914 |
System.arraycopy(_kp_array, 0, tmp_props, 0 , nb_props); |
|
915 |
_kp_array = tmp_props; |
|
916 |
_ca_array = new Property[nb_props]; |
|
917 |
||
918 |
// now assigns _ca_array to the sorted list of keys |
|
919 |
// (there cannot be two identical keys in an objectname. |
|
920 |
for (int i = 0; i < nb_props; i++) |
|
921 |
_ca_array[i] = keys_map.get(keys[i]); |
|
922 |
||
923 |
// now we build the canonical name and set begin indexes of |
|
924 |
// properties to reflect canonical form |
|
925 |
int last_index = nb_props - 1; |
|
926 |
int prop_len; |
|
927 |
Property prop; |
|
928 |
for (int i = 0; i <= last_index; i++) { |
|
929 |
prop = _ca_array[i]; |
|
930 |
// length of prop including '=' char |
|
931 |
prop_len = prop._key_length + prop._value_length + 1; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
932 |
System.arraycopy(specified_chars, prop._key_index+_domain_length, |
2 | 933 |
canonical_chars, prop_index, prop_len); |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
934 |
prop.setKeyIndex(prop_index-_domain_length); |
2 | 935 |
prop_index += prop_len; |
936 |
if (i != last_index) { |
|
937 |
canonical_chars[prop_index] = ','; |
|
938 |
prop_index++; |
|
939 |
} |
|
940 |
} |
|
941 |
} |
|
942 |
||
943 |
// terminate canonicalname with '*' in case of pattern |
|
944 |
if (_property_list_pattern) { |
|
945 |
if (_kp_array != _Empty_property_array) |
|
946 |
canonical_chars[prop_index++] = ','; |
|
947 |
canonical_chars[prop_index++] = '*'; |
|
948 |
} |
|
949 |
||
950 |
// we now build the canonicalname string |
|
951 |
_canonicalName = (new String(canonical_chars, 0, prop_index)).intern(); |
|
952 |
} |
|
953 |
||
954 |
/** |
|
955 |
* Parse a key. |
|
956 |
* <pre>final int endKey=parseKey(s,startKey);</pre> |
|
957 |
* <p>key starts at startKey (included), and ends at endKey (excluded). |
|
958 |
* If (startKey == endKey), then the key is empty. |
|
959 |
* |
|
960 |
* @param s The char array of the original string. |
|
961 |
* @param startKey index at which to begin parsing. |
|
962 |
* @return The index following the last character of the key. |
|
963 |
**/ |
|
964 |
private static int parseKey(final char[] s, final int startKey) |
|
965 |
throws MalformedObjectNameException { |
|
966 |
int next = startKey; |
|
967 |
int endKey = startKey; |
|
968 |
final int len = s.length; |
|
969 |
while (next < len) { |
|
970 |
final char k = s[next++]; |
|
971 |
switch (k) { |
|
972 |
case '*': |
|
973 |
case '?': |
|
974 |
case ',': |
|
975 |
case ':': |
|
976 |
case '\n': |
|
977 |
final String ichar = ((k=='\n')?"\\n":""+k); |
|
978 |
throw new |
|
979 |
MalformedObjectNameException("Invalid character in key: `" |
|
980 |
+ ichar + "'"); |
|
981 |
case '=': |
|
982 |
// we got the key. |
|
983 |
endKey = next-1; |
|
984 |
break; |
|
985 |
default: |
|
986 |
if (next < len) continue; |
|
987 |
else endKey=next; |
|
988 |
} |
|
989 |
break; |
|
990 |
} |
|
991 |
return endKey; |
|
992 |
} |
|
993 |
||
994 |
/** |
|
995 |
* Parse a value. |
|
996 |
* <pre>final int endVal=parseValue(s,startVal);</pre> |
|
997 |
* <p>value starts at startVal (included), and ends at endVal (excluded). |
|
998 |
* If (startVal == endVal), then the key is empty. |
|
999 |
* |
|
1000 |
* @param s The char array of the original string. |
|
1001 |
* @param startValue index at which to begin parsing. |
|
1002 |
* @return The first element of the int array indicates the index |
|
1003 |
* following the last character of the value. The second |
|
1004 |
* element of the int array indicates that the value is |
|
1005 |
* a pattern when its value equals 1. |
|
1006 |
**/ |
|
1007 |
private static int[] parseValue(final char[] s, final int startValue) |
|
1008 |
throws MalformedObjectNameException { |
|
1009 |
||
1010 |
boolean value_pattern = false; |
|
1011 |
||
1012 |
int next = startValue; |
|
1013 |
int endValue = startValue; |
|
1014 |
||
1015 |
final int len = s.length; |
|
1016 |
final char q=s[startValue]; |
|
1017 |
||
1018 |
if (q == '"') { |
|
1019 |
// quoted value |
|
1020 |
if (++next == len) throw new |
|
1021 |
MalformedObjectNameException("Invalid quote"); |
|
1022 |
while (next < len) { |
|
1023 |
char last = s[next]; |
|
1024 |
if (last == '\\') { |
|
1025 |
if (++next == len) throw new |
|
1026 |
MalformedObjectNameException( |
|
1027 |
"Invalid unterminated quoted character sequence"); |
|
1028 |
last = s[next]; |
|
1029 |
switch (last) { |
|
1030 |
case '\\' : |
|
1031 |
case '?' : |
|
1032 |
case '*' : |
|
1033 |
case 'n' : |
|
1034 |
break; |
|
1035 |
case '\"' : |
|
1036 |
// We have an escaped quote. If this escaped |
|
1037 |
// quote is the last character, it does not |
|
1038 |
// qualify as a valid termination quote. |
|
1039 |
// |
|
1040 |
if (next+1 == len) throw new |
|
1041 |
MalformedObjectNameException( |
|
1042 |
"Missing termination quote"); |
|
1043 |
break; |
|
1044 |
default: |
|
1045 |
throw new |
|
1046 |
MalformedObjectNameException( |
|
1047 |
"Invalid quoted character sequence '\\" + |
|
1048 |
last + "'"); |
|
1049 |
} |
|
1050 |
} else if (last == '\n') { |
|
1051 |
throw new MalformedObjectNameException( |
|
1052 |
"Newline in quoted value"); |
|
1053 |
} else if (last == '\"') { |
|
1054 |
next++; |
|
1055 |
break; |
|
1056 |
} else { |
|
1057 |
switch (last) { |
|
1058 |
case '?' : |
|
1059 |
case '*' : |
|
1060 |
value_pattern = true; |
|
1061 |
break; |
|
1062 |
} |
|
1063 |
} |
|
1064 |
next++; |
|
1065 |
||
1066 |
// Check that last character is a termination quote. |
|
1067 |
// We have already handled the case were the last |
|
1068 |
// character is an escaped quote earlier. |
|
1069 |
// |
|
1070 |
if ((next >= len) && (last != '\"')) throw new |
|
1071 |
MalformedObjectNameException("Missing termination quote"); |
|
1072 |
} |
|
1073 |
endValue = next; |
|
1074 |
if (next < len) { |
|
1075 |
if (s[next++] != ',') throw new |
|
1076 |
MalformedObjectNameException("Invalid quote"); |
|
1077 |
} |
|
1078 |
} else { |
|
1079 |
// Non quoted value. |
|
1080 |
while (next < len) { |
|
1081 |
final char v=s[next++]; |
|
1082 |
switch(v) { |
|
1083 |
case '*': |
|
1084 |
case '?': |
|
1085 |
value_pattern = true; |
|
1086 |
if (next < len) continue; |
|
1087 |
else endValue=next; |
|
1088 |
break; |
|
1089 |
case '=': |
|
1090 |
case ':': |
|
1091 |
case '\n' : |
|
1092 |
final String ichar = ((v=='\n')?"\\n":""+v); |
|
1093 |
throw new |
|
1094 |
MalformedObjectNameException("Invalid character `" + |
|
1095 |
ichar + "' in value"); |
|
1096 |
case ',': |
|
1097 |
endValue = next-1; |
|
1098 |
break; |
|
1099 |
default: |
|
1100 |
if (next < len) continue; |
|
1101 |
else endValue=next; |
|
1102 |
} |
|
1103 |
break; |
|
1104 |
} |
|
1105 |
} |
|
1106 |
return new int[] { endValue, value_pattern ? 1 : 0 }; |
|
1107 |
} |
|
1108 |
||
1109 |
/** |
|
1110 |
* Check if the supplied value is a valid value. |
|
1111 |
* |
|
1112 |
* @return true if the value is a pattern, otherwise false. |
|
1113 |
*/ |
|
1114 |
private static boolean checkValue(String val) |
|
1115 |
throws MalformedObjectNameException { |
|
1116 |
||
1117 |
if (val == null) throw new |
|
1118 |
NullPointerException("Invalid value (null)"); |
|
1119 |
||
1120 |
final int len = val.length(); |
|
1121 |
if (len == 0) |
|
1122 |
return false; |
|
1123 |
||
1124 |
final char[] s = val.toCharArray(); |
|
1125 |
final int[] result = parseValue(s,0); |
|
1126 |
final int endValue = result[0]; |
|
1127 |
final boolean value_pattern = result[1] == 1; |
|
1128 |
if (endValue < len) throw new |
|
1129 |
MalformedObjectNameException("Invalid character in value: `" + |
|
1130 |
s[endValue] + "'"); |
|
1131 |
return value_pattern; |
|
1132 |
} |
|
1133 |
||
1134 |
/** |
|
1135 |
* Check if the supplied key is a valid key. |
|
1136 |
*/ |
|
1137 |
private static void checkKey(String key) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1138 |
throws MalformedObjectNameException { |
2 | 1139 |
|
1140 |
if (key == null) throw new |
|
1141 |
NullPointerException("Invalid key (null)"); |
|
1142 |
||
1143 |
final int len = key.length(); |
|
1144 |
if (len == 0) throw new |
|
1145 |
MalformedObjectNameException("Invalid key (empty)"); |
|
1146 |
final char[] k=key.toCharArray(); |
|
1147 |
final int endKey = parseKey(k,0); |
|
1148 |
if (endKey < len) throw new |
|
1149 |
MalformedObjectNameException("Invalid character in value: `" + |
|
1150 |
k[endKey] + "'"); |
|
1151 |
} |
|
1152 |
||
1153 |
||
1154 |
// Category : Internal utilities <============================== |
|
1155 |
||
1156 |
// Category : Internal accessors ------------------------------> |
|
1157 |
||
1158 |
/** |
|
1159 |
* Check if domain is a valid domain. Set _domain_pattern if appropriate. |
|
1160 |
*/ |
|
1161 |
private boolean isDomain(String domain) { |
|
1162 |
if (domain == null) return true; |
|
1709
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1163 |
final int len = domain.length(); |
2 | 1164 |
int next = 0; |
1165 |
while (next < len) { |
|
1709
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1166 |
final char c = domain.charAt(next++); |
2 | 1167 |
switch (c) { |
1168 |
case ':' : |
|
1169 |
case '\n' : |
|
1170 |
return false; |
|
1171 |
case '*' : |
|
1172 |
case '?' : |
|
1173 |
_domain_pattern = true; |
|
1174 |
break; |
|
1175 |
} |
|
1176 |
} |
|
1177 |
return true; |
|
1178 |
} |
|
1179 |
||
1180 |
// Category : Internal accessors <============================== |
|
1181 |
||
1182 |
// Category : Serialization -----------------------------------> |
|
1183 |
||
1184 |
/** |
|
1185 |
* Deserializes an {@link ObjectName} from an {@link ObjectInputStream}. |
|
1186 |
* @serialData <ul> |
|
1187 |
* <li>In the current serial form (value of property |
|
1188 |
* <code>jmx.serial.form</code> differs from |
|
1189 |
* <code>1.0</code>): the string |
|
1190 |
* "<domain>:<properties><wild>", |
|
1191 |
* where: <ul> |
|
1192 |
* <li><domain> represents the domain part |
|
1193 |
* of the {@link ObjectName}</li> |
|
1194 |
* <li><properties> represents the list of |
|
1195 |
* properties, as returned by |
|
1196 |
* {@link #getKeyPropertyListString} |
|
1197 |
* <li><wild> is empty if not |
|
1198 |
* <code>isPropertyPattern</code>, or |
|
1199 |
* is the character "<code>*</code>" if |
|
1200 |
* <code>isPropertyPattern</code> |
|
1201 |
* and <properties> is empty, or |
|
1202 |
* is "<code>,*</code>" if |
|
1203 |
* <code>isPropertyPattern</code> and |
|
1204 |
* <properties> is not empty. |
|
1205 |
* </li> |
|
1206 |
* </ul> |
|
1207 |
* The intent is that this string could be supplied |
|
1208 |
* to the {@link #ObjectName(String)} constructor to |
|
1209 |
* produce an equivalent {@link ObjectName}. |
|
1210 |
* </li> |
|
1211 |
* <li>In the old serial form (value of property |
|
1212 |
* <code>jmx.serial.form</code> is |
|
1213 |
* <code>1.0</code>): <domain> <propertyList> |
|
1214 |
* <propertyListString> <canonicalName> |
|
1215 |
* <pattern> <propertyPattern>, |
|
1216 |
* where: <ul> |
|
1217 |
* <li><domain> represents the domain part |
|
1218 |
* of the {@link ObjectName}</li> |
|
1219 |
* <li><propertyList> is the |
|
1220 |
* {@link Hashtable} that contains all the |
|
1221 |
* pairs (key,value) for this |
|
1222 |
* {@link ObjectName}</li> |
|
1223 |
* <li><propertyListString> is the |
|
1224 |
* {@link String} representation of the |
|
1225 |
* list of properties in any order (not |
|
1226 |
* mandatorily a canonical representation) |
|
1227 |
* </li> |
|
1228 |
* <li><canonicalName> is the |
|
1229 |
* {@link String} containing this |
|
1230 |
* {@link ObjectName}'s canonical name</li> |
|
1231 |
* <li><pattern> is a boolean which is |
|
1232 |
* <code>true</code> if this |
|
1233 |
* {@link ObjectName} contains a pattern</li> |
|
1234 |
* <li><propertyPattern> is a boolean which |
|
1235 |
* is <code>true</code> if this |
|
1236 |
* {@link ObjectName} contains a pattern in |
|
1237 |
* the list of properties</li> |
|
1238 |
* </ul> |
|
1239 |
* </li> |
|
1240 |
* </ul> |
|
1241 |
*/ |
|
1242 |
private void readObject(ObjectInputStream in) |
|
1243 |
throws IOException, ClassNotFoundException { |
|
1244 |
||
1245 |
String cn; |
|
1246 |
if (compat) { |
|
1247 |
// Read an object serialized in the old serial form |
|
1248 |
// |
|
1249 |
//in.defaultReadObject(); |
|
1250 |
final ObjectInputStream.GetField fields = in.readFields(); |
|
1005
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1251 |
String propListString = |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1252 |
(String)fields.get("propertyListString", ""); |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1253 |
|
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1254 |
// 6616825: take care of property patterns |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1255 |
final boolean propPattern = |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1256 |
fields.get("propertyPattern" , false); |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1257 |
if (propPattern) { |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1258 |
propListString = |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1259 |
(propListString.length()==0?"*":(propListString+",*")); |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1260 |
} |
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1261 |
|
2 | 1262 |
cn = (String)fields.get("domain", "default")+ |
1005
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
1263 |
":"+ propListString; |
2 | 1264 |
} else { |
1265 |
// Read an object serialized in the new serial form |
|
1266 |
// |
|
1267 |
in.defaultReadObject(); |
|
1268 |
cn = (String)in.readObject(); |
|
1269 |
} |
|
1270 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1271 |
final JMXNamespaceContext ctxt = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1272 |
JMXNamespaceContext.getDeserializationContext(); |
2 | 1273 |
try { |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1274 |
construct(changeContext(ctxt,cn)); |
2 | 1275 |
} catch (NullPointerException e) { |
1276 |
throw new InvalidObjectException(e.toString()); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1277 |
} catch (IllegalArgumentException e) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1278 |
throw new InvalidObjectException(e.toString()); |
2 | 1279 |
} catch (MalformedObjectNameException e) { |
1280 |
throw new InvalidObjectException(e.toString()); |
|
1281 |
} |
|
1282 |
} |
|
1283 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1284 |
private String changeContext(JMXNamespaceContext context, String nameString) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1285 |
final String old = context.prefixToRemove; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1286 |
final String nw = context.prefixToAdd; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1287 |
final int ol = old.length(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1288 |
if (nameString.startsWith(NAMESPACE_SEPARATOR)) return nameString; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1289 |
if (ol>0) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1290 |
if (!nameString.startsWith(old) || |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1291 |
!nameString.startsWith(NAMESPACE_SEPARATOR,ol)) |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1292 |
throw new IllegalArgumentException( |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1293 |
"Serialized ObjectName does not start with " + old + |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1294 |
": " + nameString); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1295 |
nameString = nameString.substring(ol+NAMESPACE_SEPARATOR_LENGTH); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1296 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1297 |
if (!nw.equals("")) { |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1298 |
nameString = nw + NAMESPACE_SEPARATOR + nameString; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1299 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1300 |
return nameString; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1301 |
} |
2 | 1302 |
|
1303 |
/** |
|
1304 |
* Serializes an {@link ObjectName} to an {@link ObjectOutputStream}. |
|
1305 |
* @serialData <ul> |
|
1306 |
* <li>In the current serial form (value of property |
|
1307 |
* <code>jmx.serial.form</code> differs from |
|
1308 |
* <code>1.0</code>): the string |
|
1309 |
* "<domain>:<properties><wild>", |
|
1310 |
* where: <ul> |
|
1311 |
* <li><domain> represents the domain part |
|
1312 |
* of the {@link ObjectName}</li> |
|
1313 |
* <li><properties> represents the list of |
|
1314 |
* properties, as returned by |
|
1315 |
* {@link #getKeyPropertyListString} |
|
1316 |
* <li><wild> is empty if not |
|
1317 |
* <code>isPropertyPattern</code>, or |
|
1318 |
* is the character "<code>*</code>" if |
|
1319 |
* this <code>isPropertyPattern</code> |
|
1320 |
* and <properties> is empty, or |
|
1321 |
* is "<code>,*</code>" if |
|
1322 |
* <code>isPropertyPattern</code> and |
|
1323 |
* <properties> is not empty. |
|
1324 |
* </li> |
|
1325 |
* </ul> |
|
1326 |
* The intent is that this string could be supplied |
|
1327 |
* to the {@link #ObjectName(String)} constructor to |
|
1328 |
* produce an equivalent {@link ObjectName}. |
|
1329 |
* </li> |
|
1330 |
* <li>In the old serial form (value of property |
|
1331 |
* <code>jmx.serial.form</code> is |
|
1332 |
* <code>1.0</code>): <domain> <propertyList> |
|
1333 |
* <propertyListString> <canonicalName> |
|
1334 |
* <pattern> <propertyPattern>, |
|
1335 |
* where: <ul> |
|
1336 |
* <li><domain> represents the domain part |
|
1337 |
* of the {@link ObjectName}</li> |
|
1338 |
* <li><propertyList> is the |
|
1339 |
* {@link Hashtable} that contains all the |
|
1340 |
* pairs (key,value) for this |
|
1341 |
* {@link ObjectName}</li> |
|
1342 |
* <li><propertyListString> is the |
|
1343 |
* {@link String} representation of the |
|
1344 |
* list of properties in any order (not |
|
1345 |
* mandatorily a canonical representation) |
|
1346 |
* </li> |
|
1347 |
* <li><canonicalName> is the |
|
1348 |
* {@link String} containing this |
|
1349 |
* {@link ObjectName}'s canonical name</li> |
|
1350 |
* <li><pattern> is a boolean which is |
|
1351 |
* <code>true</code> if this |
|
1352 |
* {@link ObjectName} contains a pattern</li> |
|
1353 |
* <li><propertyPattern> is a boolean which |
|
1354 |
* is <code>true</code> if this |
|
1355 |
* {@link ObjectName} contains a pattern in |
|
1356 |
* the list of properties</li> |
|
1357 |
* </ul> |
|
1358 |
* </li> |
|
1359 |
* </ul> |
|
1360 |
*/ |
|
1361 |
private void writeObject(ObjectOutputStream out) |
|
1362 |
throws IOException { |
|
1363 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1364 |
final JMXNamespaceContext ctxt = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1365 |
JMXNamespaceContext.getSerializationContext(); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1366 |
|
2 | 1367 |
if (compat) |
1368 |
{ |
|
1369 |
// Serializes this instance in the old serial form |
|
1370 |
// Read CR 6441274 before making any changes to this code |
|
1371 |
ObjectOutputStream.PutField fields = out.putFields(); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1372 |
final String domain = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1373 |
changeContext(ctxt,_canonicalName.substring(0, _domain_length)); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1374 |
final String cn = |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1375 |
changeContext(ctxt,_canonicalName); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1376 |
fields.put("domain", domain); |
2 | 1377 |
fields.put("propertyList", getKeyPropertyList()); |
1378 |
fields.put("propertyListString", getKeyPropertyListString()); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1379 |
fields.put("canonicalName", cn); |
2 | 1380 |
fields.put("pattern", (_domain_pattern || _property_list_pattern)); |
1381 |
fields.put("propertyPattern", _property_list_pattern); |
|
1382 |
out.writeFields(); |
|
1383 |
} |
|
1384 |
else |
|
1385 |
{ |
|
1386 |
// Serializes this instance in the new serial form |
|
1387 |
// |
|
1388 |
out.defaultWriteObject(); |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1389 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1390 |
out.writeObject(changeContext(ctxt,getSerializedNameString())); |
2 | 1391 |
} |
1392 |
} |
|
1393 |
||
1394 |
// Category : Serialization <=================================== |
|
1395 |
||
1396 |
// Private methods <======================================== |
|
1397 |
||
1398 |
// Public methods ----------------------------------------> |
|
1399 |
||
1400 |
// Category : ObjectName Construction ------------------------------> |
|
1401 |
||
1402 |
/** |
|
1403 |
* <p>Return an instance of ObjectName that can be used anywhere |
|
1404 |
* an object obtained with {@link #ObjectName(String) new |
|
1405 |
* ObjectName(name)} can be used. The returned object may be of |
|
1406 |
* a subclass of ObjectName. Calling this method twice with the |
|
1407 |
* same parameters may return the same object or two equal but |
|
1408 |
* not identical objects.</p> |
|
1409 |
* |
|
1410 |
* @param name A string representation of the object name. |
|
1411 |
* |
|
1412 |
* @return an ObjectName corresponding to the given String. |
|
1413 |
* |
|
1414 |
* @exception MalformedObjectNameException The string passed as a |
|
1415 |
* parameter does not have the right format. |
|
1416 |
* @exception NullPointerException The <code>name</code> parameter |
|
1417 |
* is null. |
|
1418 |
* |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1419 |
* @see #valueOf(String) |
2 | 1420 |
*/ |
1421 |
public static ObjectName getInstance(String name) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1422 |
throws MalformedObjectNameException { |
2 | 1423 |
return new ObjectName(name); |
1424 |
} |
|
1425 |
||
1426 |
/** |
|
1427 |
* <p>Return an instance of ObjectName that can be used anywhere |
|
1428 |
* an object obtained with {@link #ObjectName(String, String, |
|
1429 |
* String) new ObjectName(domain, key, value)} can be used. The |
|
1430 |
* returned object may be of a subclass of ObjectName. Calling |
|
1431 |
* this method twice with the same parameters may return the same |
|
1432 |
* object or two equal but not identical objects.</p> |
|
1433 |
* |
|
1434 |
* @param domain The domain part of the object name. |
|
1435 |
* @param key The attribute in the key property of the object name. |
|
1436 |
* @param value The value in the key property of the object name. |
|
1437 |
* |
|
1438 |
* @return an ObjectName corresponding to the given domain, |
|
1439 |
* key, and value. |
|
1440 |
* |
|
1441 |
* @exception MalformedObjectNameException The |
|
1442 |
* <code>domain</code>, <code>key</code>, or <code>value</code> |
|
1443 |
* contains an illegal character, or <code>value</code> does not |
|
1444 |
* follow the rules for quoting. |
|
1445 |
* @exception NullPointerException One of the parameters is null. |
|
1446 |
* |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1447 |
* @see #valueOf(String, String, String) |
2 | 1448 |
*/ |
1449 |
public static ObjectName getInstance(String domain, String key, |
|
1450 |
String value) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1451 |
throws MalformedObjectNameException { |
2 | 1452 |
return new ObjectName(domain, key, value); |
1453 |
} |
|
1454 |
||
1455 |
/** |
|
1456 |
* <p>Return an instance of ObjectName that can be used anywhere |
|
1457 |
* an object obtained with {@link #ObjectName(String, Hashtable) |
|
1458 |
* new ObjectName(domain, table)} can be used. The returned |
|
1459 |
* object may be of a subclass of ObjectName. Calling this method |
|
1460 |
* twice with the same parameters may return the same object or |
|
1461 |
* two equal but not identical objects.</p> |
|
1462 |
* |
|
1463 |
* @param domain The domain part of the object name. |
|
1464 |
* @param table A hash table containing one or more key |
|
1465 |
* properties. The key of each entry in the table is the key of a |
|
1466 |
* key property in the object name. The associated value in the |
|
1467 |
* table is the associated value in the object name. |
|
1468 |
* |
|
1469 |
* @return an ObjectName corresponding to the given domain and |
|
1470 |
* key mappings. |
|
1471 |
* |
|
1472 |
* @exception MalformedObjectNameException The <code>domain</code> |
|
1473 |
* contains an illegal character, or one of the keys or values in |
|
1474 |
* <code>table</code> contains an illegal character, or one of the |
|
1475 |
* values in <code>table</code> does not follow the rules for |
|
1476 |
* quoting. |
|
1477 |
* @exception NullPointerException One of the parameters is null. |
|
1478 |
* |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1479 |
* @see #valueOf(String, Hashtable) |
2 | 1480 |
*/ |
1481 |
public static ObjectName getInstance(String domain, |
|
1482 |
Hashtable<String,String> table) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1483 |
throws MalformedObjectNameException { |
2 | 1484 |
return new ObjectName(domain, table); |
1485 |
} |
|
1486 |
||
1487 |
/** |
|
1488 |
* <p>Return an instance of ObjectName that can be used anywhere |
|
1489 |
* the given object can be used. The returned object may be of a |
|
1490 |
* subclass of ObjectName. If <code>name</code> is of a subclass |
|
1491 |
* of ObjectName, it is not guaranteed that the returned object |
|
1492 |
* will be of the same class.</p> |
|
1493 |
* |
|
1494 |
* <p>The returned value may or may not be identical to |
|
1495 |
* <code>name</code>. Calling this method twice with the same |
|
1496 |
* parameters may return the same object or two equal but not |
|
1497 |
* identical objects.</p> |
|
1498 |
* |
|
1499 |
* <p>Since ObjectName is immutable, it is not usually useful to |
|
1500 |
* make a copy of an ObjectName. The principal use of this method |
|
1501 |
* is to guard against a malicious caller who might pass an |
|
1502 |
* instance of a subclass with surprising behavior to sensitive |
|
1503 |
* code. Such code can call this method to obtain an ObjectName |
|
1504 |
* that is known not to have surprising behavior.</p> |
|
1505 |
* |
|
1506 |
* @param name an instance of the ObjectName class or of a subclass |
|
1507 |
* |
|
1508 |
* @return an instance of ObjectName or a subclass that is known to |
|
1509 |
* have the same semantics. If <code>name</code> respects the |
|
1510 |
* semantics of ObjectName, then the returned object is equal |
|
1511 |
* (though not necessarily identical) to <code>name</code>. |
|
1512 |
* |
|
1513 |
* @exception NullPointerException The <code>name</code> is null. |
|
1514 |
* |
|
1515 |
*/ |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1516 |
public static ObjectName getInstance(ObjectName name) { |
2 | 1517 |
if (name.getClass().equals(ObjectName.class)) |
1518 |
return name; |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1519 |
return valueOf(name.getSerializedNameString()); |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1520 |
} |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1521 |
|
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1522 |
/** |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1523 |
* <p>Return an instance of ObjectName that can be used anywhere |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1524 |
* an object obtained with {@link #ObjectName(String) new |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1525 |
* ObjectName(name)} can be used. The returned object may be of |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1526 |
* a subclass of ObjectName. Calling this method twice with the |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1527 |
* same parameters may return the same object or two equal but |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1528 |
* not identical objects.</p> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1529 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1530 |
* <p>This method is equivalent to {@link #getInstance(String)} except that |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1531 |
* it does not throw any checked exceptions.</p> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1532 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1533 |
* @param name A string representation of the object name. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1534 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1535 |
* @return an ObjectName corresponding to the given String. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1536 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1537 |
* @exception IllegalArgumentException The string passed as a |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1538 |
* parameter does not have the right format. The {@linkplain |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1539 |
* Throwable#getCause() cause} of this exception will be a |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1540 |
* {@link MalformedObjectNameException}. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1541 |
* @exception NullPointerException The <code>name</code> parameter |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1542 |
* is null. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1543 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1544 |
* @since 1.7 |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1545 |
*/ |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1546 |
public static ObjectName valueOf(String name) { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1547 |
try { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1548 |
return getInstance(name); |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1549 |
} catch (MalformedObjectNameException e) { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1550 |
throw new IllegalArgumentException(e.getMessage(), e); |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1551 |
// Just plain IllegalArgumentException(e) produces an exception |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1552 |
// message "javax.management.MalformedObjectNameException: ..." |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1553 |
// which is distracting. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1554 |
} |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1555 |
} |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1556 |
|
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1557 |
/** |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1558 |
* <p>Return an instance of ObjectName that can be used anywhere |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1559 |
* an object obtained with {@link #ObjectName(String, String, |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1560 |
* String) new ObjectName(domain, key, value)} can be used. The |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1561 |
* returned object may be of a subclass of ObjectName. Calling |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1562 |
* this method twice with the same parameters may return the same |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1563 |
* object or two equal but not identical objects.</p> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1564 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1565 |
* <p>This method is equivalent to {@link #getInstance(String, String, |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1566 |
* String)} except that it does not throw any checked exceptions.</p> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1567 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1568 |
* @param domain The domain part of the object name. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1569 |
* @param key The attribute in the key property of the object name. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1570 |
* @param value The value in the key property of the object name. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1571 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1572 |
* @return an ObjectName corresponding to the given domain, |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1573 |
* key, and value. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1574 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1575 |
* @exception IllegalArgumentException The |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1576 |
* <code>domain</code>, <code>key</code>, or <code>value</code> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1577 |
* contains an illegal character, or <code>value</code> does not |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1578 |
* follow the rules for quoting. The {@linkplain |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1579 |
* Throwable#getCause() cause} of this exception will be a |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1580 |
* {@link MalformedObjectNameException}. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1581 |
* @exception NullPointerException One of the parameters is null. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1582 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1583 |
* @since 1.7 |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1584 |
*/ |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1585 |
public static ObjectName valueOf(String domain, String key, String value) { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1586 |
try { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1587 |
return getInstance(domain, key, value); |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1588 |
} catch (MalformedObjectNameException e) { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1589 |
throw new IllegalArgumentException(e.getMessage(), e); |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1590 |
} |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1591 |
} |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1592 |
|
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1593 |
/** |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1594 |
* <p>Return an instance of ObjectName that can be used anywhere |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1595 |
* an object obtained with {@link #ObjectName(String, Hashtable) |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1596 |
* new ObjectName(domain, table)} can be used. The returned |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1597 |
* object may be of a subclass of ObjectName. Calling this method |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1598 |
* twice with the same parameters may return the same object or |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1599 |
* two equal but not identical objects.</p> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1600 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1601 |
* <p>This method is equivalent to {@link #getInstance(String, Hashtable)} |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1602 |
* except that it does not throw any checked exceptions.</p> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1603 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1604 |
* @param domain The domain part of the object name. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1605 |
* @param table A hash table containing one or more key |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1606 |
* properties. The key of each entry in the table is the key of a |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1607 |
* key property in the object name. The associated value in the |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1608 |
* table is the associated value in the object name. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1609 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1610 |
* @return an ObjectName corresponding to the given domain and |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1611 |
* key mappings. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1612 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1613 |
* @exception IllegalArgumentException The <code>domain</code> |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1614 |
* contains an illegal character, or one of the keys or values in |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1615 |
* <code>table</code> contains an illegal character, or one of the |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1616 |
* values in <code>table</code> does not follow the rules for |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1617 |
* quoting. The {@linkplain Throwable#getCause() cause} of this exception |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1618 |
* will be a {@link MalformedObjectNameException}. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1619 |
* @exception NullPointerException One of the parameters is null. |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1620 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1621 |
* @since 1.7 |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1622 |
*/ |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1623 |
public static ObjectName valueOf(String domain, |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1624 |
Hashtable<String,String> table) { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1625 |
try { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1626 |
return new ObjectName(domain, table); |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1627 |
} catch (MalformedObjectNameException e) { |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1628 |
throw new IllegalArgumentException(e.getMessage(), e); |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1629 |
} |
2 | 1630 |
} |
1631 |
||
1632 |
/** |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1633 |
* Returns an {@code ObjectName} that is the same as this one but |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1634 |
* with the specified domain. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1635 |
* This method preserves the original key order in the new instance. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1636 |
* If the provided name has a key property pattern, it will also be |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1637 |
* preserved in the returned instance. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1638 |
* |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1639 |
* @param newDomain The new domain for the returned instance; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1640 |
* must not be null. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1641 |
* @return A new {@code ObjectName} that is the same as {@code this} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1642 |
* except the domain is {@code newDomain}. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1643 |
* @throws NullPointerException if {@code newDomain} is null. |
1709
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1644 |
* @exception IllegalArgumentException The {@code newDomain} passed as a |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1645 |
* parameter does not have the right format. The {@linkplain |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1646 |
* Throwable#getCause() cause} of this exception will be a |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1647 |
* {@link MalformedObjectNameException}. |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1648 |
* @since 1.7 |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1649 |
**/ |
1709
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1650 |
public final ObjectName withDomain(String newDomain) { |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1651 |
try { |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1652 |
return new ObjectName(newDomain, this); |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1653 |
} catch (MalformedObjectNameException x) { |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1654 |
throw new IllegalArgumentException(x.getMessage(),x); |
392dd6db361a
6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents:
1225
diff
changeset
|
1655 |
} |
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1656 |
} |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1657 |
|
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1658 |
/** |
2 | 1659 |
* Construct an object name from the given string. |
1660 |
* |
|
1661 |
* @param name A string representation of the object name. |
|
1662 |
* |
|
1663 |
* @exception MalformedObjectNameException The string passed as a |
|
1664 |
* parameter does not have the right format. |
|
1665 |
* @exception NullPointerException The <code>name</code> parameter |
|
1666 |
* is null. |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1667 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1668 |
* @see #valueOf(String) |
2 | 1669 |
*/ |
1670 |
public ObjectName(String name) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1671 |
throws MalformedObjectNameException { |
2 | 1672 |
construct(name); |
1673 |
} |
|
1674 |
||
1675 |
/** |
|
1676 |
* Construct an object name with exactly one key property. |
|
1677 |
* |
|
1678 |
* @param domain The domain part of the object name. |
|
1679 |
* @param key The attribute in the key property of the object name. |
|
1680 |
* @param value The value in the key property of the object name. |
|
1681 |
* |
|
1682 |
* @exception MalformedObjectNameException The |
|
1683 |
* <code>domain</code>, <code>key</code>, or <code>value</code> |
|
1684 |
* contains an illegal character, or <code>value</code> does not |
|
1685 |
* follow the rules for quoting. |
|
1686 |
* @exception NullPointerException One of the parameters is null. |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1687 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1688 |
* @see #valueOf(String, String, String) |
2 | 1689 |
*/ |
1690 |
public ObjectName(String domain, String key, String value) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1691 |
throws MalformedObjectNameException { |
2 | 1692 |
// If key or value are null a NullPointerException |
1693 |
// will be thrown by the put method in Hashtable. |
|
1694 |
// |
|
1695 |
Map<String,String> table = Collections.singletonMap(key, value); |
|
1696 |
construct(domain, table); |
|
1697 |
} |
|
1698 |
||
1699 |
/** |
|
1700 |
* Construct an object name with several key properties from a Hashtable. |
|
1701 |
* |
|
1702 |
* @param domain The domain part of the object name. |
|
1703 |
* @param table A hash table containing one or more key |
|
1704 |
* properties. The key of each entry in the table is the key of a |
|
1705 |
* key property in the object name. The associated value in the |
|
1706 |
* table is the associated value in the object name. |
|
1707 |
* |
|
1708 |
* @exception MalformedObjectNameException The <code>domain</code> |
|
1709 |
* contains an illegal character, or one of the keys or values in |
|
1710 |
* <code>table</code> contains an illegal character, or one of the |
|
1711 |
* values in <code>table</code> does not follow the rules for |
|
1712 |
* quoting. |
|
1713 |
* @exception NullPointerException One of the parameters is null. |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1714 |
* |
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1715 |
* @see #valueOf(String, Hashtable) |
2 | 1716 |
*/ |
1717 |
public ObjectName(String domain, Hashtable<String,String> table) |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1718 |
throws MalformedObjectNameException { |
2 | 1719 |
construct(domain, table); |
1720 |
/* The exception for when a key or value in the table is not a |
|
1721 |
String is now ClassCastException rather than |
|
1722 |
MalformedObjectNameException. This was not previously |
|
1723 |
specified. */ |
|
1724 |
} |
|
1725 |
||
1726 |
// Category : ObjectName Construction <============================== |
|
1727 |
||
1728 |
||
1729 |
// Category : Getter methods ------------------------------> |
|
1730 |
||
1731 |
/** |
|
1732 |
* Checks whether the object name is a pattern. |
|
1733 |
* <p> |
|
1734 |
* An object name is a pattern if its domain contains a |
|
1735 |
* wildcard or if the object name is a property pattern. |
|
1736 |
* |
|
1737 |
* @return True if the name is a pattern, otherwise false. |
|
1738 |
*/ |
|
1739 |
public boolean isPattern() { |
|
1740 |
return (_domain_pattern || |
|
1741 |
_property_list_pattern || |
|
1742 |
_property_value_pattern); |
|
1743 |
} |
|
1744 |
||
1745 |
/** |
|
1746 |
* Checks whether the object name is a pattern on the domain part. |
|
1747 |
* |
|
1748 |
* @return True if the name is a domain pattern, otherwise false. |
|
1749 |
* |
|
1750 |
*/ |
|
1751 |
public boolean isDomainPattern() { |
|
1752 |
return _domain_pattern; |
|
1753 |
} |
|
1754 |
||
1755 |
/** |
|
1756 |
* Checks whether the object name is a pattern on the key properties. |
|
1757 |
* <p> |
|
1758 |
* An object name is a pattern on the key properties if it is a |
|
1759 |
* pattern on the key property list (e.g. "d:k=v,*") or on the |
|
1760 |
* property values (e.g. "d:k=*") or on both (e.g. "d:k=*,*"). |
|
1761 |
* |
|
1762 |
* @return True if the name is a property pattern, otherwise false. |
|
1763 |
*/ |
|
1764 |
public boolean isPropertyPattern() { |
|
1765 |
return _property_list_pattern || _property_value_pattern; |
|
1766 |
} |
|
1767 |
||
1768 |
/** |
|
1769 |
* Checks whether the object name is a pattern on the key property list. |
|
1770 |
* <p> |
|
1771 |
* For example, "d:k=v,*" and "d:k=*,*" are key property list patterns |
|
1772 |
* whereas "d:k=*" is not. |
|
1773 |
* |
|
1774 |
* @return True if the name is a property list pattern, otherwise false. |
|
1775 |
* |
|
1776 |
* @since 1.6 |
|
1777 |
*/ |
|
1778 |
public boolean isPropertyListPattern() { |
|
1779 |
return _property_list_pattern; |
|
1780 |
} |
|
1781 |
||
1782 |
/** |
|
1783 |
* Checks whether the object name is a pattern on the value part |
|
1784 |
* of at least one of the key properties. |
|
1785 |
* <p> |
|
1786 |
* For example, "d:k=*" and "d:k=*,*" are property value patterns |
|
1787 |
* whereas "d:k=v,*" is not. |
|
1788 |
* |
|
1789 |
* @return True if the name is a property value pattern, otherwise false. |
|
1790 |
* |
|
1791 |
* @since 1.6 |
|
1792 |
*/ |
|
1793 |
public boolean isPropertyValuePattern() { |
|
1794 |
return _property_value_pattern; |
|
1795 |
} |
|
1796 |
||
1797 |
/** |
|
1798 |
* Checks whether the value associated with a key in a key |
|
1799 |
* property is a pattern. |
|
1800 |
* |
|
1801 |
* @param property The property whose value is to be checked. |
|
1802 |
* |
|
1803 |
* @return True if the value associated with the given key property |
|
1804 |
* is a pattern, otherwise false. |
|
1805 |
* |
|
1806 |
* @exception NullPointerException If <code>property</code> is null. |
|
1807 |
* @exception IllegalArgumentException If <code>property</code> is not |
|
1808 |
* a valid key property for this ObjectName. |
|
1809 |
* |
|
1810 |
* @since 1.6 |
|
1811 |
*/ |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1812 |
public boolean isPropertyValuePattern(String property) { |
2 | 1813 |
if (property == null) |
1814 |
throw new NullPointerException("key property can't be null"); |
|
1815 |
for (int i = 0; i < _ca_array.length; i++) { |
|
1816 |
Property prop = _ca_array[i]; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1817 |
String key = prop.getKeyString(_canonicalName,_domain_length); |
2 | 1818 |
if (key.equals(property)) |
1819 |
return (prop instanceof PatternProperty); |
|
1820 |
} |
|
1821 |
throw new IllegalArgumentException("key property not found"); |
|
1822 |
} |
|
1823 |
||
1824 |
/** |
|
1825 |
* <p>Returns the canonical form of the name; that is, a string |
|
1826 |
* representation where the properties are sorted in lexical |
|
1827 |
* order.</p> |
|
1828 |
* |
|
1829 |
* <p>More precisely, the canonical form of the name is a String |
|
1830 |
* consisting of the <em>domain part</em>, a colon |
|
1831 |
* (<code>:</code>), the <em>canonical key property list</em>, and |
|
1832 |
* a <em>pattern indication</em>.</p> |
|
1833 |
* |
|
1834 |
* <p>The <em>canonical key property list</em> is the same string |
|
1835 |
* as described for {@link #getCanonicalKeyPropertyListString()}.</p> |
|
1836 |
* |
|
1837 |
* <p>The <em>pattern indication</em> is: |
|
1838 |
* <ul> |
|
1839 |
* <li>empty for an ObjectName |
|
1840 |
* that is not a property list pattern; |
|
1841 |
* <li>an asterisk for an ObjectName |
|
1842 |
* that is a property list pattern with no keys; or |
|
1843 |
* <li>a comma and an |
|
1844 |
* asterisk (<code>,*</code>) for an ObjectName that is a property |
|
1845 |
* list pattern with at least one key. |
|
1846 |
* </ul></p> |
|
1847 |
* |
|
1848 |
* @return The canonical form of the name. |
|
1849 |
*/ |
|
1850 |
public String getCanonicalName() { |
|
1851 |
return _canonicalName; |
|
1852 |
} |
|
1853 |
||
1854 |
/** |
|
1855 |
* Returns the domain part. |
|
1856 |
* |
|
1857 |
* @return The domain. |
|
1858 |
*/ |
|
1859 |
public String getDomain() { |
|
1860 |
return _canonicalName.substring(0, _domain_length); |
|
1861 |
} |
|
1862 |
||
1863 |
/** |
|
1864 |
* Obtains the value associated with a key in a key property. |
|
1865 |
* |
|
1866 |
* @param property The property whose value is to be obtained. |
|
1867 |
* |
|
1868 |
* @return The value of the property, or null if there is no such |
|
1869 |
* property in this ObjectName. |
|
1870 |
* |
|
1871 |
* @exception NullPointerException If <code>property</code> is null. |
|
1872 |
*/ |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
1873 |
public String getKeyProperty(String property) { |
2 | 1874 |
return _getKeyPropertyList().get(property); |
1875 |
} |
|
1876 |
||
1877 |
/** |
|
1878 |
* <p>Returns the key properties as a Map. The returned |
|
1879 |
* value is a Map in which each key is a key in the |
|
1880 |
* ObjectName's key property list and each value is the associated |
|
1881 |
* value.</p> |
|
1882 |
* |
|
1883 |
* <p>The returned value must not be modified.</p> |
|
1884 |
* |
|
1885 |
* @return The table of key properties. |
|
1886 |
*/ |
|
1887 |
private Map<String,String> _getKeyPropertyList() { |
|
1888 |
synchronized (this) { |
|
1889 |
if (_propertyList == null) { |
|
1890 |
// build (lazy eval) the property list from the canonical |
|
1891 |
// properties array |
|
1892 |
_propertyList = new HashMap<String,String>(); |
|
1893 |
int len = _ca_array.length; |
|
1894 |
Property prop; |
|
1895 |
for (int i = len - 1; i >= 0; i--) { |
|
1896 |
prop = _ca_array[i]; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1897 |
_propertyList.put(prop.getKeyString(_canonicalName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1898 |
_domain_length), |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1899 |
prop.getValueString(_canonicalName, |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1900 |
_domain_length)); |
2 | 1901 |
} |
1902 |
} |
|
1903 |
} |
|
1904 |
return _propertyList; |
|
1905 |
} |
|
1906 |
||
1907 |
/** |
|
1908 |
* <p>Returns the key properties as a Hashtable. The returned |
|
1909 |
* value is a Hashtable in which each key is a key in the |
|
1910 |
* ObjectName's key property list and each value is the associated |
|
1911 |
* value.</p> |
|
1912 |
* |
|
1913 |
* <p>The returned value may be unmodifiable. If it is |
|
1914 |
* modifiable, changing it has no effect on this ObjectName.</p> |
|
1915 |
* |
|
1916 |
* @return The table of key properties. |
|
1917 |
*/ |
|
1918 |
// CR 6441274 depends on the modification property defined above |
|
1919 |
public Hashtable<String,String> getKeyPropertyList() { |
|
1920 |
return new Hashtable<String,String>(_getKeyPropertyList()); |
|
1921 |
} |
|
1922 |
||
1923 |
/** |
|
1924 |
* <p>Returns a string representation of the list of key |
|
1925 |
* properties specified at creation time. If this ObjectName was |
|
1926 |
* constructed with the constructor {@link #ObjectName(String)}, |
|
1927 |
* the key properties in the returned String will be in the same |
|
1928 |
* order as in the argument to the constructor.</p> |
|
1929 |
* |
|
1930 |
* @return The key property list string. This string is |
|
1931 |
* independent of whether the ObjectName is a pattern. |
|
1932 |
*/ |
|
1933 |
public String getKeyPropertyListString() { |
|
1934 |
// BEWARE : we rebuild the propertyliststring at each call !! |
|
1935 |
if (_kp_array.length == 0) return ""; |
|
1936 |
||
1937 |
// the size of the string is the canonical one minus domain |
|
1938 |
// part and pattern part |
|
1939 |
final int total_size = _canonicalName.length() - _domain_length - 1 |
|
1940 |
- (_property_list_pattern?2:0); |
|
1941 |
||
1942 |
final char[] dest_chars = new char[total_size]; |
|
1943 |
final char[] value = _canonicalName.toCharArray(); |
|
1944 |
writeKeyPropertyListString(value,dest_chars,0); |
|
1945 |
return new String(dest_chars); |
|
1946 |
} |
|
1947 |
||
1948 |
/** |
|
1949 |
* <p>Returns the serialized string of the ObjectName. |
|
1950 |
* properties specified at creation time. If this ObjectName was |
|
1951 |
* constructed with the constructor {@link #ObjectName(String)}, |
|
1952 |
* the key properties in the returned String will be in the same |
|
1953 |
* order as in the argument to the constructor.</p> |
|
1954 |
* |
|
1955 |
* @return The key property list string. This string is |
|
1956 |
* independent of whether the ObjectName is a pattern. |
|
1957 |
*/ |
|
1958 |
private String getSerializedNameString() { |
|
1959 |
||
1960 |
// the size of the string is the canonical one |
|
1961 |
final int total_size = _canonicalName.length(); |
|
1962 |
final char[] dest_chars = new char[total_size]; |
|
1963 |
final char[] value = _canonicalName.toCharArray(); |
|
1964 |
final int offset = _domain_length+1; |
|
1965 |
||
1966 |
// copy "domain:" into dest_chars |
|
1967 |
// |
|
1968 |
System.arraycopy(value, 0, dest_chars, 0, offset); |
|
1969 |
||
1970 |
// Add property list string |
|
1971 |
final int end = writeKeyPropertyListString(value,dest_chars,offset); |
|
1972 |
||
1973 |
// Add ",*" if necessary |
|
1974 |
if (_property_list_pattern) { |
|
1975 |
if (end == offset) { |
|
1976 |
// Property list string is empty. |
|
1977 |
dest_chars[end] = '*'; |
|
1978 |
} else { |
|
1979 |
// Property list string is not empty. |
|
1980 |
dest_chars[end] = ','; |
|
1981 |
dest_chars[end+1] = '*'; |
|
1982 |
} |
|
1983 |
} |
|
1984 |
||
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1985 |
final String name = new String(dest_chars); |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
1986 |
return name; |
2 | 1987 |
} |
1988 |
||
1989 |
/** |
|
1990 |
* <p>Write a string representation of the list of key |
|
1991 |
* properties specified at creation time in the given array, starting |
|
1992 |
* at the specified offset. If this ObjectName was |
|
1993 |
* constructed with the constructor {@link #ObjectName(String)}, |
|
1994 |
* the key properties in the returned String will be in the same |
|
1995 |
* order as in the argument to the constructor.</p> |
|
1996 |
* |
|
1997 |
* @return offset + #of chars written |
|
1998 |
*/ |
|
1999 |
private int writeKeyPropertyListString(char[] canonicalChars, |
|
2000 |
char[] data, int offset) { |
|
2001 |
if (_kp_array.length == 0) return offset; |
|
2002 |
||
2003 |
final char[] dest_chars = data; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2004 |
final char[] value = canonicalChars; |
2 | 2005 |
|
2006 |
int index = offset; |
|
2007 |
final int len = _kp_array.length; |
|
2008 |
final int last = len - 1; |
|
2009 |
for (int i = 0; i < len; i++) { |
|
2010 |
final Property prop = _kp_array[i]; |
|
2011 |
final int prop_len = prop._key_length + prop._value_length + 1; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2012 |
System.arraycopy(value, prop._key_index+_domain_length, dest_chars, index, |
2 | 2013 |
prop_len); |
2014 |
index += prop_len; |
|
2015 |
if (i < last ) dest_chars[index++] = ','; |
|
2016 |
} |
|
2017 |
return index; |
|
2018 |
} |
|
2019 |
||
2020 |
||
2021 |
||
2022 |
/** |
|
2023 |
* Returns a string representation of the list of key properties, |
|
2024 |
* in which the key properties are sorted in lexical order. This |
|
2025 |
* is used in lexicographic comparisons performed in order to |
|
2026 |
* select MBeans based on their key property list. Lexical order |
|
2027 |
* is the order implied by {@link String#compareTo(String) |
|
2028 |
* String.compareTo(String)}. |
|
2029 |
* |
|
2030 |
* @return The canonical key property list string. This string is |
|
2031 |
* independent of whether the ObjectName is a pattern. |
|
2032 |
*/ |
|
2033 |
public String getCanonicalKeyPropertyListString() { |
|
2034 |
if (_ca_array.length == 0) return ""; |
|
2035 |
||
2036 |
int len = _canonicalName.length(); |
|
2037 |
if (_property_list_pattern) len -= 2; |
|
2038 |
return _canonicalName.substring(_domain_length +1, len); |
|
2039 |
} |
|
2040 |
// Category : Getter methods <=================================== |
|
2041 |
||
2042 |
// Category : Utilities ----------------------------------------> |
|
2043 |
||
2044 |
/** |
|
2045 |
* <p>Returns a string representation of the object name. The |
|
2046 |
* format of this string is not specified, but users can expect |
|
2047 |
* that two ObjectNames return the same string if and only if they |
|
2048 |
* are equal.</p> |
|
2049 |
* |
|
2050 |
* @return a string representation of this object name. |
|
2051 |
*/ |
|
34 | 2052 |
@Override |
2 | 2053 |
public String toString() { |
2054 |
return getSerializedNameString(); |
|
2055 |
} |
|
2056 |
||
34 | 2057 |
String toQueryString() { |
686
d0c74839e1bd
6701498: Change JMX query language to use * and ? as wildcards rather than % and _
emcmanus
parents:
526
diff
changeset
|
2058 |
return "like " + Query.value(toString()); |
34 | 2059 |
} |
2060 |
||
2 | 2061 |
/** |
2062 |
* Compares the current object name with another object name. Two |
|
2063 |
* ObjectName instances are equal if and only if their canonical |
|
2064 |
* forms are equal. The canonical form is the string described |
|
2065 |
* for {@link #getCanonicalName()}. |
|
2066 |
* |
|
2067 |
* @param object The object name that the current object name is to be |
|
2068 |
* compared with. |
|
2069 |
* |
|
2070 |
* @return True if <code>object</code> is an ObjectName whose |
|
2071 |
* canonical form is equal to that of this ObjectName. |
|
2072 |
*/ |
|
1005
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
2073 |
@Override |
2 | 2074 |
public boolean equals(Object object) { |
2075 |
||
2076 |
// same object case |
|
2077 |
if (this == object) return true; |
|
2078 |
||
2079 |
// object is not an object name case |
|
2080 |
if (!(object instanceof ObjectName)) return false; |
|
2081 |
||
2082 |
// equality when canonical names are the same |
|
2083 |
// (because usage of intern()) |
|
2084 |
ObjectName on = (ObjectName) object; |
|
2085 |
String on_string = on._canonicalName; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2086 |
if (_canonicalName == on_string) return true; // ES: OK |
2 | 2087 |
|
2088 |
// Because we are sharing canonical form between object names, |
|
2089 |
// we have finished the comparison at this stage ==> unequal |
|
2090 |
return false; |
|
2091 |
} |
|
2092 |
||
2093 |
/** |
|
2094 |
* Returns a hash code for this object name. |
|
2095 |
* |
|
2096 |
*/ |
|
1005
1a39b4e3f2fc
6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents:
715
diff
changeset
|
2097 |
@Override |
2 | 2098 |
public int hashCode() { |
2099 |
return _canonicalName.hashCode(); |
|
2100 |
} |
|
2101 |
||
2102 |
/** |
|
2103 |
* <p>Returns a quoted form of the given String, suitable for |
|
2104 |
* inclusion in an ObjectName. The returned value can be used as |
|
2105 |
* the value associated with a key in an ObjectName. The String |
|
2106 |
* <code>s</code> may contain any character. Appropriate quoting |
|
2107 |
* ensures that the returned value is legal in an ObjectName.</p> |
|
2108 |
* |
|
2109 |
* <p>The returned value consists of a quote ('"'), a sequence of |
|
2110 |
* characters corresponding to the characters of <code>s</code>, |
|
2111 |
* and another quote. Characters in <code>s</code> appear |
|
2112 |
* unchanged within the returned value except:</p> |
|
2113 |
* |
|
2114 |
* <ul> |
|
2115 |
* <li>A quote ('"') is replaced by a backslash (\) followed by a quote.</li> |
|
2116 |
* <li>An asterisk ('*') is replaced by a backslash (\) followed by an |
|
2117 |
* asterisk.</li> |
|
2118 |
* <li>A question mark ('?') is replaced by a backslash (\) followed by |
|
2119 |
* a question mark.</li> |
|
2120 |
* <li>A backslash ('\') is replaced by two backslashes.</li> |
|
2121 |
* <li>A newline character (the character '\n' in Java) is replaced |
|
2122 |
* by a backslash followed by the character '\n'.</li> |
|
2123 |
* </ul> |
|
2124 |
* |
|
2125 |
* @param s the String to be quoted. |
|
2126 |
* |
|
2127 |
* @return the quoted String. |
|
2128 |
* |
|
2129 |
* @exception NullPointerException if <code>s</code> is null. |
|
2130 |
* |
|
2131 |
*/ |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
2132 |
public static String quote(String s) { |
2 | 2133 |
final StringBuilder buf = new StringBuilder("\""); |
2134 |
final int len = s.length(); |
|
2135 |
for (int i = 0; i < len; i++) { |
|
2136 |
char c = s.charAt(i); |
|
2137 |
switch (c) { |
|
2138 |
case '\n': |
|
2139 |
c = 'n'; |
|
2140 |
buf.append('\\'); |
|
2141 |
break; |
|
2142 |
case '\\': |
|
2143 |
case '\"': |
|
2144 |
case '*': |
|
2145 |
case '?': |
|
2146 |
buf.append('\\'); |
|
2147 |
break; |
|
2148 |
} |
|
2149 |
buf.append(c); |
|
2150 |
} |
|
2151 |
buf.append('"'); |
|
2152 |
return buf.toString(); |
|
2153 |
} |
|
2154 |
||
2155 |
/** |
|
2156 |
* <p>Returns an unquoted form of the given String. If |
|
2157 |
* <code>q</code> is a String returned by {@link #quote quote(s)}, |
|
2158 |
* then <code>unquote(q).equals(s)</code>. If there is no String |
|
2159 |
* <code>s</code> for which <code>quote(s).equals(q)</code>, then |
|
2160 |
* unquote(q) throws an IllegalArgumentException.</p> |
|
2161 |
* |
|
2162 |
* <p>These rules imply that there is a one-to-one mapping between |
|
2163 |
* quoted and unquoted forms.</p> |
|
2164 |
* |
|
2165 |
* @param q the String to be unquoted. |
|
2166 |
* |
|
2167 |
* @return the unquoted String. |
|
2168 |
* |
|
2169 |
* @exception IllegalArgumentException if <code>q</code> could not |
|
2170 |
* have been returned by the {@link #quote} method, for instance |
|
2171 |
* if it does not begin and end with a quote ("). |
|
2172 |
* |
|
2173 |
* @exception NullPointerException if <code>q</code> is null. |
|
2174 |
* |
|
2175 |
*/ |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
2176 |
public static String unquote(String q) { |
2 | 2177 |
final StringBuilder buf = new StringBuilder(); |
2178 |
final int len = q.length(); |
|
2179 |
if (len < 2 || q.charAt(0) != '"' || q.charAt(len - 1) != '"') |
|
2180 |
throw new IllegalArgumentException("Argument not quoted"); |
|
2181 |
for (int i = 1; i < len - 1; i++) { |
|
2182 |
char c = q.charAt(i); |
|
2183 |
if (c == '\\') { |
|
2184 |
if (i == len - 2) |
|
2185 |
throw new IllegalArgumentException("Trailing backslash"); |
|
2186 |
c = q.charAt(++i); |
|
2187 |
switch (c) { |
|
2188 |
case 'n': |
|
2189 |
c = '\n'; |
|
2190 |
break; |
|
2191 |
case '\\': |
|
2192 |
case '\"': |
|
2193 |
case '*': |
|
2194 |
case '?': |
|
2195 |
break; |
|
2196 |
default: |
|
2197 |
throw new IllegalArgumentException( |
|
2198 |
"Bad character '" + c + "' after backslash"); |
|
2199 |
} |
|
2200 |
} else { |
|
2201 |
switch (c) { |
|
2202 |
case '*' : |
|
2203 |
case '?' : |
|
2204 |
case '\"': |
|
2205 |
case '\n': |
|
2206 |
throw new IllegalArgumentException( |
|
2207 |
"Invalid unescaped character '" + c + |
|
2208 |
"' in the string to unquote"); |
|
2209 |
} |
|
2210 |
} |
|
2211 |
buf.append(c); |
|
2212 |
} |
|
2213 |
return buf.toString(); |
|
2214 |
} |
|
2215 |
||
2216 |
/** |
|
2217 |
* Defines the wildcard "*:*" ObjectName. |
|
2218 |
* |
|
2219 |
* @since 1.6 |
|
2220 |
*/ |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
2221 |
public static final ObjectName WILDCARD = valueOf("*:*"); |
2 | 2222 |
|
2223 |
// Category : Utilities <=================================== |
|
2224 |
||
2225 |
// Category : QueryExp Interface ----------------------------------------> |
|
2226 |
||
2227 |
/** |
|
2228 |
* <p>Test whether this ObjectName, which may be a pattern, |
|
2229 |
* matches another ObjectName. If <code>name</code> is a pattern, |
|
2230 |
* the result is false. If this ObjectName is a pattern, the |
|
2231 |
* result is true if and only if <code>name</code> matches the |
|
2232 |
* pattern. If neither this ObjectName nor <code>name</code> is |
|
2233 |
* a pattern, the result is true if and only if the two |
|
2234 |
* ObjectNames are equal as described for the {@link |
|
2235 |
* #equals(Object)} method.</p> |
|
2236 |
* |
|
2237 |
* @param name The name of the MBean to compare to. |
|
2238 |
* |
|
2239 |
* @return True if <code>name</code> matches this ObjectName. |
|
2240 |
* |
|
2241 |
* @exception NullPointerException if <code>name</code> is null. |
|
2242 |
* |
|
2243 |
*/ |
|
1225
6ef6227d36eb
6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents:
1156
diff
changeset
|
2244 |
public boolean apply(ObjectName name) { |
2 | 2245 |
|
2246 |
if (name == null) throw new NullPointerException(); |
|
2247 |
||
2248 |
if (name._domain_pattern || |
|
2249 |
name._property_list_pattern || |
|
2250 |
name._property_value_pattern) |
|
2251 |
return false; |
|
2252 |
||
2253 |
// No pattern |
|
2254 |
if (!_domain_pattern && |
|
2255 |
!_property_list_pattern && |
|
2256 |
!_property_value_pattern) |
|
2257 |
return _canonicalName.equals(name._canonicalName); |
|
2258 |
||
2259 |
return matchDomains(name) && matchKeys(name); |
|
2260 |
} |
|
2261 |
||
2262 |
private final boolean matchDomains(ObjectName name) { |
|
2263 |
if (_domain_pattern) { |
|
2264 |
// wildmatch domains |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2265 |
// This ObjectName is the pattern |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2266 |
// The other ObjectName is the string. |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2267 |
return Util.wildpathmatch(name.getDomain(),getDomain()); |
2 | 2268 |
} |
2269 |
return getDomain().equals(name.getDomain()); |
|
2270 |
} |
|
2271 |
||
2272 |
private final boolean matchKeys(ObjectName name) { |
|
2273 |
// If key property value pattern but not key property list |
|
2274 |
// pattern, then the number of key properties must be equal |
|
2275 |
// |
|
2276 |
if (_property_value_pattern && |
|
2277 |
!_property_list_pattern && |
|
2278 |
(name._ca_array.length != _ca_array.length)) |
|
2279 |
return false; |
|
2280 |
||
2281 |
// If key property value pattern or key property list pattern, |
|
2282 |
// then every property inside pattern should exist in name |
|
2283 |
// |
|
2284 |
if (_property_value_pattern || _property_list_pattern) { |
|
2285 |
final Map<String,String> nameProps = name._getKeyPropertyList(); |
|
2286 |
final Property[] props = _ca_array; |
|
2287 |
final String cn = _canonicalName; |
|
2288 |
for (int i = props.length - 1; i >= 0 ; i--) { |
|
2289 |
// Find value in given object name for key at current |
|
2290 |
// index in receiver |
|
2291 |
// |
|
2292 |
final Property p = props[i]; |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2293 |
final String k = p.getKeyString(cn,_domain_length); |
2 | 2294 |
final String v = nameProps.get(k); |
2295 |
// Did we find a value for this key ? |
|
2296 |
// |
|
2297 |
if (v == null) return false; |
|
2298 |
// If this property is ok (same key, same value), go to next |
|
2299 |
// |
|
2300 |
if (_property_value_pattern && (p instanceof PatternProperty)) { |
|
2301 |
// wildmatch key property values |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2302 |
// p is the property pattern, v is the string |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2303 |
if (Util.wildmatch(v,p.getValueString(cn,_domain_length))) |
2 | 2304 |
continue; |
2305 |
else |
|
2306 |
return false; |
|
2307 |
} |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2308 |
if (v.equals(p.getValueString(cn,_domain_length))) continue; |
2 | 2309 |
return false; |
2310 |
} |
|
2311 |
return true; |
|
2312 |
} |
|
2313 |
||
2314 |
// If no pattern, then canonical names must be equal |
|
2315 |
// |
|
2316 |
final String p1 = name.getCanonicalKeyPropertyListString(); |
|
2317 |
final String p2 = getCanonicalKeyPropertyListString(); |
|
2318 |
return (p1.equals(p2)); |
|
2319 |
} |
|
2320 |
||
2321 |
/* Method inherited from QueryExp, no implementation needed here |
|
2322 |
because ObjectName is not relative to an MBeanServer and does |
|
2323 |
not contain a subquery. |
|
2324 |
*/ |
|
2325 |
public void setMBeanServer(MBeanServer mbs) { } |
|
2326 |
||
2327 |
// Category : QueryExp Interface <========================= |
|
2328 |
||
2329 |
// Category : Comparable Interface ----------------------------------------> |
|
2330 |
||
2331 |
/** |
|
2332 |
* <p>Compares two ObjectName instances. The ordering relation between |
|
2333 |
* ObjectNames is not completely specified but is intended to be such |
|
2334 |
* that a sorted list of ObjectNames will appear in an order that is |
|
2335 |
* convenient for a person to read.</p> |
|
2336 |
* |
|
2337 |
* <p>In particular, if the two ObjectName instances have different |
|
2338 |
* domains then their order is the lexicographical order of the domains. |
|
2339 |
* The ordering of the key property list remains unspecified.</p> |
|
2340 |
* |
|
2341 |
* <p>For example, the ObjectName instances below:</p> |
|
2342 |
* <ul> |
|
2343 |
* <li>Shapes:type=Square,name=3</li> |
|
2344 |
* <li>Colors:type=Red,name=2</li> |
|
2345 |
* <li>Shapes:type=Triangle,side=isosceles,name=2</li> |
|
2346 |
* <li>Colors:type=Red,name=1</li> |
|
2347 |
* <li>Shapes:type=Square,name=1</li> |
|
2348 |
* <li>Colors:type=Blue,name=1</li> |
|
2349 |
* <li>Shapes:type=Square,name=2</li> |
|
2350 |
* <li>JMImplementation:type=MBeanServerDelegate</li> |
|
2351 |
* <li>Shapes:type=Triangle,side=scalene,name=1</li> |
|
2352 |
* </ul> |
|
2353 |
* <p>could be ordered as follows:</p> |
|
2354 |
* <ul> |
|
2355 |
* <li>Colors:type=Blue,name=1</li> |
|
2356 |
* <li>Colors:type=Red,name=1</li> |
|
2357 |
* <li>Colors:type=Red,name=2</li> |
|
2358 |
* <li>JMImplementation:type=MBeanServerDelegate</li> |
|
2359 |
* <li>Shapes:type=Square,name=1</li> |
|
2360 |
* <li>Shapes:type=Square,name=2</li> |
|
2361 |
* <li>Shapes:type=Square,name=3</li> |
|
2362 |
* <li>Shapes:type=Triangle,side=scalene,name=1</li> |
|
2363 |
* <li>Shapes:type=Triangle,side=isosceles,name=2</li> |
|
2364 |
* </ul> |
|
2365 |
* |
|
2366 |
* @param name the ObjectName to be compared. |
|
2367 |
* |
|
2368 |
* @return a negative integer, zero, or a positive integer as this |
|
2369 |
* ObjectName is less than, equal to, or greater than the |
|
2370 |
* specified ObjectName. |
|
2371 |
* |
|
2372 |
* @since 1.6 |
|
2373 |
*/ |
|
2374 |
public int compareTo(ObjectName name) { |
|
1156
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2375 |
// Quick optimization: |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2376 |
// |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2377 |
if (name == this) return 0; |
bbc2d15aaf7a
5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
1005
diff
changeset
|
2378 |
|
2 | 2379 |
// (1) Compare domains |
2380 |
// |
|
2381 |
int domainValue = this.getDomain().compareTo(name.getDomain()); |
|
2382 |
if (domainValue != 0) |
|
2383 |
return domainValue; |
|
2384 |
||
2385 |
// (2) Compare "type=" keys |
|
2386 |
// |
|
2387 |
// Within a given domain, all names with missing or empty "type=" |
|
2388 |
// come before all names with non-empty type. |
|
2389 |
// |
|
2390 |
// When both types are missing or empty, canonical-name ordering |
|
2391 |
// applies which is a total order. |
|
2392 |
// |
|
2393 |
String thisTypeKey = this.getKeyProperty("type"); |
|
2394 |
String anotherTypeKey = name.getKeyProperty("type"); |
|
2395 |
if (thisTypeKey == null) |
|
2396 |
thisTypeKey = ""; |
|
2397 |
if (anotherTypeKey == null) |
|
2398 |
anotherTypeKey = ""; |
|
2399 |
int typeKeyValue = thisTypeKey.compareTo(anotherTypeKey); |
|
2400 |
if (typeKeyValue != 0) |
|
2401 |
return typeKeyValue; |
|
2402 |
||
2403 |
// (3) Compare canonical names |
|
2404 |
// |
|
2405 |
return this.getCanonicalName().compareTo(name.getCanonicalName()); |
|
2406 |
} |
|
2407 |
||
2408 |
// Category : Comparable Interface <========================= |
|
2409 |
||
2410 |
// Public methods <======================================== |
|
2411 |
||
2412 |
} |