author | xdono |
Wed, 02 Jul 2008 12:55:45 -0700 | |
changeset 715 | f16baef3a20e |
parent 686 | d0c74839e1bd |
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 |
||
29 |
/** |
|
34 | 30 |
* <p>Constructs query object constraints.</p> |
31 |
* |
|
32 |
* <p>The MBean Server can be queried for MBeans that meet a particular |
|
33 |
* condition, using its {@link MBeanServer#queryNames queryNames} or |
|
34 |
* {@link MBeanServer#queryMBeans queryMBeans} method. The {@link QueryExp} |
|
35 |
* parameter to the method can be any implementation of the interface |
|
36 |
* {@code QueryExp}, but it is usually best to obtain the {@code QueryExp} |
|
37 |
* value by calling the static methods in this class. This is particularly |
|
38 |
* true when querying a remote MBean Server: a custom implementation of the |
|
39 |
* {@code QueryExp} interface might not be present in the remote MBean Server, |
|
40 |
* but the methods in this class return only standard classes that are |
|
41 |
* part of the JMX implementation.</p> |
|
42 |
* |
|
43 |
* <p>There are two ways to create {@code QueryExp} objects using the methods |
|
44 |
* in this class. The first is to build them by chaining together calls to |
|
45 |
* the various methods. The second is to use the Query Language described |
|
46 |
* <a href="#ql">below</a> and produce the {@code QueryExp} by calling |
|
47 |
* {@link #fromString Query.fromString}. The two ways are equivalent: |
|
48 |
* every {@code QueryExp} returned by {@code fromString} can also be |
|
49 |
* constructed by chaining method calls.</p> |
|
50 |
* |
|
51 |
* <p>As an example, suppose you wanted to find all MBeans where the {@code |
|
52 |
* Enabled} attribute is {@code true} and the {@code Owner} attribute is {@code |
|
53 |
* "Duke"}. Here is how you could construct the appropriate {@code QueryExp} by |
|
54 |
* chaining together method calls:</p> |
|
55 |
* |
|
56 |
* <pre> |
|
57 |
* QueryExp query = |
|
58 |
* Query.and(Query.eq(Query.attr("Enabled"), Query.value(true)), |
|
59 |
* Query.eq(Query.attr("Owner"), Query.value("Duke"))); |
|
60 |
* </pre> |
|
61 |
* |
|
62 |
* <p>Here is how you could construct the same {@code QueryExp} using the |
|
63 |
* Query Language:</p> |
|
2 | 64 |
* |
65 |
* <pre> |
|
34 | 66 |
* QueryExp query = Query.fromString("Enabled = true and Owner = 'Duke'"); |
2 | 67 |
* </pre> |
68 |
* |
|
34 | 69 |
* <p>The principal advantage of the method-chaining approach is that the |
70 |
* compiler will check that the query makes sense. The principal advantage |
|
71 |
* of the Query Language approach is that it is easier to write and especially |
|
72 |
* read.</p> |
|
73 |
* |
|
74 |
* |
|
75 |
* <h4 id="ql">Query Language</h4> |
|
76 |
* |
|
77 |
* <p>The query language is closely modeled on the WHERE clause of |
|
78 |
* SQL SELECT statements. The formal specification of the language |
|
79 |
* appears <a href="#formal-ql">below</a>, but it is probably easier to |
|
80 |
* understand it with examples such as the following.</p> |
|
81 |
* |
|
82 |
* <dl> |
|
83 |
* <dt>{@code Message = 'OK'} |
|
84 |
* <dd>Selects MBeans that have a {@code Message} attribute whose value |
|
85 |
* is the string {@code OK}. |
|
86 |
* |
|
87 |
* <dt>{@code FreeSpacePercent < 10} |
|
88 |
* <dd>Selects MBeans that have a {@code FreeSpacePercent} attribute whose |
|
89 |
* value is a number less than 10. |
|
90 |
* |
|
91 |
* <dt>{@code FreeSpacePercent < 10 and WarningSent = false} |
|
92 |
* <dd>Selects the same MBeans as the previous example, but they must |
|
93 |
* also have a boolean attribute {@code WarningSent} whose value |
|
94 |
* is false. |
|
95 |
* |
|
96 |
* <dt>{@code SpaceUsed > TotalSpace * (2.0 / 3.0)} |
|
97 |
* <dd>Selects MBeans that have {@code SpaceUsed} and {@code TotalSpace} |
|
98 |
* attributes where the first is more than two-thirds the second. |
|
99 |
* |
|
100 |
* <dt>{@code not (FreeSpacePercent between 10 and 90)} |
|
101 |
* <dd>Selects MBeans that have a {@code FreeSpacePercent} attribute whose |
|
102 |
* value is not between 10 and 90, inclusive. |
|
103 |
* |
|
104 |
* <dt>{@code FreeSpacePercent not between 10 and 90} |
|
105 |
* <dd>Another way of writing the previous query. |
|
106 |
* |
|
107 |
* <dt>{@code Status in ('STOPPED', 'STARTING', 'STARTED')} |
|
108 |
* <dd>Selects MBeans that have a {@code Status} attribute whose value |
|
109 |
* is one of those three strings. |
|
110 |
* |
|
686
d0c74839e1bd
6701498: Change JMX query language to use * and ? as wildcards rather than % and _
emcmanus
parents:
471
diff
changeset
|
111 |
* <dt>{@code Message like 'OK: *'} |
34 | 112 |
* <dd>Selects MBeans that have a {@code Message} attribute whose value |
113 |
* is a string beginning with {@code "OK: "}. <b>Notice that the |
|
686
d0c74839e1bd
6701498: Change JMX query language to use * and ? as wildcards rather than % and _
emcmanus
parents:
471
diff
changeset
|
114 |
* wildcard characters are not the ones that SQL uses.</b> In SQL, |
34 | 115 |
* {@code %} means "any sequence of characters" and {@code _} |
686
d0c74839e1bd
6701498: Change JMX query language to use * and ? as wildcards rather than % and _
emcmanus
parents:
471
diff
changeset
|
116 |
* means "any single character". Here, as in the rest of the JMX API, |
d0c74839e1bd
6701498: Change JMX query language to use * and ? as wildcards rather than % and _
emcmanus
parents:
471
diff
changeset
|
117 |
* those are represented by {@code *} and {@code ?} respectively. |
34 | 118 |
* |
119 |
* <dt>{@code instanceof 'javax.management.NotificationBroadcaster'} |
|
120 |
* <dd>Selects MBeans that are instances of |
|
121 |
* {@link javax.management.NotificationBroadcaster}, as reported by |
|
122 |
* {@link javax.management.MBeanServer#isInstanceOf MBeanServer.isInstanceOf}. |
|
123 |
* |
|
124 |
* <dt>{@code like 'mydomain:*'} |
|
125 |
* <dd>Selects MBeans whose {@link ObjectName}s have the domain {@code mydomain}. |
|
126 |
* |
|
127 |
* </dl> |
|
128 |
* |
|
129 |
* <p>The last two examples do not correspond to valid SQL syntax, but all |
|
130 |
* the others do.</p> |
|
131 |
* |
|
132 |
* <p>The remainder of this description is a formal specification of the |
|
133 |
* query language.</p> |
|
134 |
* |
|
135 |
* |
|
136 |
* <h4 id="formal-ql">Lexical elements</h4> |
|
137 |
* |
|
138 |
* <p>Keywords such as <b>and</b>, <b>like</b>, and <b>between</b> are not |
|
139 |
* case sensitive. You can write <b>between</b>, <b>BETWEEN</b>, or |
|
140 |
* <b>BeTwEeN</b> with the same effect.</p> |
|
141 |
* |
|
142 |
* <p>On the other hand, attribute names <i>are</i> case sensitive. The |
|
143 |
* attribute {@code Name} is not the same as the attribute {@code name}.</p> |
|
144 |
* |
|
145 |
* <p>To access an attribute whose name, ignoring case, is the same as one of |
|
146 |
* the keywords {@code not}, {@code instanceof}, {@code like}, {@code true}, |
|
147 |
* or {@code false}, you can use double quotes, for example {@code "not"}. |
|
148 |
* Double quotes can also be used to include non-identifier characters in |
|
149 |
* the name of an attribute, for example {@code "attribute-name-with-hyphens"}. |
|
150 |
* To include the double quote character in the attribute name, write it |
|
151 |
* twice. {@code "foo""bar""baz"} represents the attribute called |
|
152 |
* {@code foo"bar"baz}. |
|
153 |
* |
|
154 |
* <p>String constants are written with single quotes like {@code 'this'}. A |
|
155 |
* single quote within a string constant must be doubled, for example |
|
156 |
* {@code 'can''t'}.</p> |
|
157 |
* |
|
158 |
* <p>Integer constants are written as a sequence of decimal digits, |
|
159 |
* optionally preceded by a plus or minus sign. An integer constant must be |
|
160 |
* a valid input to {@link Long#valueOf(String)}.</p> |
|
161 |
* |
|
162 |
* <p>Floating-point constants are written using the Java syntax. A |
|
163 |
* floating-point constant must be a valid input to |
|
164 |
* {@link Double#valueOf(String)}.</p> |
|
165 |
* |
|
166 |
* <p>A boolean constant is either {@code true} or {@code false}, ignoring |
|
167 |
* case.</p> |
|
168 |
* |
|
169 |
* <p>Spaces cannot appear inside identifiers (unless written with double |
|
170 |
* quotes) or keywords or multi-character tokens such as {@code <=}. Spaces can |
|
171 |
* appear anywhere else, but are not required except to separate tokens. For |
|
172 |
* example, the query {@code a < b and 5 = c} could also be written {@code a<b |
|
173 |
* and 5=c}, but no further spaces can be removed.</p> |
|
174 |
* |
|
175 |
* |
|
176 |
* <h4 id="grammar-ql">Grammar</h4> |
|
177 |
* |
|
178 |
* <dl> |
|
179 |
* <dt id="query">query: |
|
180 |
* <dd><a href="#andquery">andquery</a> [<b>OR</b> <a href="#query">query</a>] |
|
181 |
* |
|
182 |
* <dt id="andquery">andquery: |
|
183 |
* <dd><a href="#predicate">predicate</a> [<b>AND</b> <a href="#andquery">andquery</a>] |
|
184 |
* |
|
185 |
* <dt id="predicate">predicate: |
|
186 |
* <dd><b>(</b> <a href="#query">query</a> <b>)</b> |<br> |
|
187 |
* <b>NOT</b> <a href="#predicate">predicate</a> |<br> |
|
188 |
* <b>INSTANCEOF</b> <a href="#stringvalue">stringvalue</a> |<br> |
|
189 |
* <b>LIKE</b> <a href="#objectnamepattern">objectnamepattern</a> |<br> |
|
190 |
* <a href="#value">value</a> <a href="#predrhs">predrhs</a> |
|
191 |
* |
|
192 |
* <dt id="predrhs">predrhs: |
|
193 |
* <dd><a href="#compare">compare</a> <a href="#value">value</a> |<br> |
|
194 |
* [<b>NOT</b>] <b>BETWEEN</b> <a href="#value">value</a> <b>AND</b> |
|
195 |
* <a href="#value">value</a> |<br> |
|
196 |
* [<b>NOT</b>] <b>IN (</b> <a href="#value">value</a> |
|
197 |
* <a href="#commavalues">commavalues</a> <b>)</b> |<br> |
|
198 |
* [<b>NOT</b>] <b>LIKE</b> <a href="#stringvalue">stringvalue</a> |
|
199 |
* |
|
200 |
* <dt id="commavalues">commavalues: |
|
201 |
* <dd>[ <b>,</b> <a href="#value">value</a> <a href="#commavalues">commavalues</a> ] |
|
202 |
* |
|
203 |
* <dt id="compare">compare: |
|
204 |
* <dd><b>=</b> | <b><</b> | <b>></b> | |
|
205 |
* <b><=</b> | <b>>=</b> | <b><></b> | <b>!=</b> |
|
206 |
* |
|
207 |
* <dt id="value">value: |
|
208 |
* <dd><a href="#factor">factor</a> [<a href="#plusorminus">plusorminus</a> |
|
209 |
* <a href="#value">value</a>] |
|
210 |
* |
|
211 |
* <dt id="plusorminus">plusorminus: |
|
212 |
* <dd><b>+</b> | <b>-</b> |
|
213 |
* |
|
214 |
* <dt id="factor">factor: |
|
215 |
* <dd><a href="#term">term</a> [<a href="#timesordivide">timesordivide</a> |
|
216 |
* <a href="#factor">factor</a>] |
|
217 |
* |
|
218 |
* <dt id="timesordivide">timesordivide: |
|
219 |
* <dd><b>*</b> | <b>/</b> |
|
220 |
* |
|
221 |
* <dt id="term">term: |
|
222 |
* <dd><a href="#attr">attr</a> | <a href="#literal">literal</a> | |
|
223 |
* <b>(</b> <a href="#value">value</a> <b>)</b> |
|
224 |
* |
|
225 |
* <dt id="attr">attr: |
|
226 |
* <dd><a href="#name">name</a> [<b>#</b> <a href="#name">name</a>] |
|
227 |
* |
|
228 |
* <dt id="name">name: |
|
229 |
* <dd><a href="#identifier">identifier</a> [<b>.</b><a href="#name">name</a>] |
|
230 |
* |
|
231 |
* <dt id="identifier">identifier: |
|
232 |
* <dd><i>Java-identifier</i> | <i>double-quoted-identifier</i> |
|
233 |
* |
|
234 |
* <dt id="literal">literal: |
|
235 |
* <dd><a href="#booleanlit">booleanlit</a> | <i>longlit</i> | |
|
236 |
* <i>doublelit</i> | <i>stringlit</i> |
|
237 |
* |
|
238 |
* <dt id="booleanlit">booleanlit: |
|
239 |
* <dd><b>FALSE</b> | <b>TRUE</b> |
|
240 |
* |
|
241 |
* <dt id="stringvalue">stringvalue: |
|
242 |
* <dd><i>stringlit</i> |
|
243 |
* |
|
244 |
* <dt id="objectnamepattern">objectnamepattern: |
|
245 |
* <dd><i>stringlit</i> |
|
246 |
* |
|
247 |
* </dl> |
|
248 |
* |
|
249 |
* |
|
250 |
* <h4>Semantics</h4> |
|
251 |
* |
|
252 |
* <p>The meaning of the grammar is described in the table below. |
|
253 |
* This defines a function <i>q</i> that maps a string to a Java object |
|
254 |
* such as a {@link QueryExp} or a {@link ValueExp}.</p> |
|
255 |
* |
|
256 |
* <table border="1" cellpadding="5"> |
|
257 |
* <tr><th>String <i>s</i></th><th><i>q(s)</th></tr> |
|
258 |
* |
|
259 |
* <tr><td><i>query1</i> <b>OR</b> <i>query2</i> |
|
260 |
* <td>{@link Query#or Query.or}(<i>q(query1)</i>, <i>q(query2)</i>) |
|
261 |
* |
|
262 |
* <tr><td><i>query1</i> <b>AND</b> <i>query2</i> |
|
263 |
* <td>{@link Query#and Query.and}(<i>q(query1)</i>, <i>q(query2)</i>) |
|
264 |
* |
|
265 |
* <tr><td><b>(</b> <i>queryOrValue</i> <b>)</b> |
|
266 |
* <td><i>q(queryOrValue)</i> |
|
267 |
* |
|
268 |
* <tr><td><b>NOT</b> <i>query</i> |
|
269 |
* <td>{@link Query#not Query.not}(<i>q(query)</i>) |
|
270 |
* |
|
271 |
* <tr><td><b>INSTANCEOF</b> <i>stringLiteral</i> |
|
272 |
* <td>{@link Query#isInstanceOf Query.isInstanceOf}(<!-- |
|
273 |
* -->{@link Query#value(String) Query.value}(<i>q(stringLiteral)</i>)) |
|
274 |
* |
|
275 |
* <tr><td><b>LIKE</b> <i>stringLiteral</i> |
|
276 |
* <td>{@link ObjectName#ObjectName(String) new ObjectName}(<!-- |
|
277 |
* --><i>q(stringLiteral)</i>) |
|
278 |
* |
|
279 |
* <tr><td><i>value1</i> <b>=</b> <i>value2</i> |
|
280 |
* <td>{@link Query#eq Query.eq}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
281 |
* |
|
282 |
* <tr><td><i>value1</i> <b><</b> <i>value2</i> |
|
283 |
* <td>{@link Query#lt Query.lt}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
284 |
* |
|
285 |
* <tr><td><i>value1</i> <b>></b> <i>value2</i> |
|
286 |
* <td>{@link Query#gt Query.gt}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
287 |
* |
|
288 |
* <tr><td><i>value1</i> <b><=</b> <i>value2</i> |
|
289 |
* <td>{@link Query#leq Query.leq}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
290 |
* |
|
291 |
* <tr><td><i>value1</i> <b>>=</b> <i>value2</i> |
|
292 |
* <td>{@link Query#geq Query.geq}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
293 |
* |
|
294 |
* <tr><td><i>value1</i> <b><></b> <i>value2</i> |
|
295 |
* <td>{@link Query#not Query.not}({@link Query#eq Query.eq}(<!-- |
|
296 |
* --><i>q(value1)</i>, <i>q(value2)</i>)) |
|
297 |
* |
|
298 |
* <tr><td><i>value1</i> <b>!=</b> <i>value2</i> |
|
299 |
* <td>{@link Query#not Query.not}({@link Query#eq Query.eq}(<!-- |
|
300 |
* --><i>q(value1)</i>, <i>q(value2)</i>)) |
|
301 |
* |
|
302 |
* <tr><td><i>value1</i> <b>BETWEEN</b> <i>value2</i> AND <i>value3</i> |
|
303 |
* <td>{@link Query#between Query.between}(<i>q(value1)</i>, |
|
304 |
* <i>q(value2)</i>, <i>q(value3)</i>) |
|
305 |
* |
|
306 |
* <tr><td><i>value1</i> <b>NOT BETWEEN</b> <i>value2</i> AND <i>value3</i> |
|
307 |
* <td>{@link Query#not Query.not}({@link Query#between Query.between}(<!-- |
|
308 |
* --><i>q(value1)</i>, <i>q(value2)</i>, <i>q(value3)</i>)) |
|
309 |
* |
|
310 |
* <tr><td><i>value1</i> <b>IN (</b> <i>value2</i>, <i>value3</i> <b>)</b> |
|
311 |
* <td>{@link Query#in Query.in}(<i>q(value1)</i>, |
|
312 |
* <code>new ValueExp[] {</code> |
|
313 |
* <i>q(value2)</i>, <i>q(value3)</i><code>}</code>) |
|
314 |
* |
|
315 |
* <tr><td><i>value1</i> <b>NOT IN (</b> <i>value2</i>, <i>value3</i> <b>)</b> |
|
316 |
* <td>{@link Query#not Query.not}({@link Query#in Query.in}(<i>q(value1)</i>, |
|
317 |
* <code>new ValueExp[] {</code> |
|
318 |
* <i>q(value2)</i>, <i>q(value3)</i><code>}</code>)) |
|
319 |
* |
|
320 |
* <tr><td><i>value</i> <b>LIKE</b> <i>stringLiteral</i> |
|
321 |
* <td>{@link Query#match Query.match}(<i>q(value)</i>, |
|
686
d0c74839e1bd
6701498: Change JMX query language to use * and ? as wildcards rather than % and _
emcmanus
parents:
471
diff
changeset
|
322 |
* <i>q(stringLiteral)</i>) |
34 | 323 |
* |
324 |
* <tr><td><i>value</i> <b>NOT LIKE</b> <i>stringLiteral</i> |
|
325 |
* <td>{@link Query#not Query.not}({@link Query#match Query.match}(<i>q(value)</i>, |
|
686
d0c74839e1bd
6701498: Change JMX query language to use * and ? as wildcards rather than % and _
emcmanus
parents:
471
diff
changeset
|
326 |
* <i>q(stringLiteral)</i>)) |
34 | 327 |
* |
328 |
* <tr><td><i>value1</i> <b>+</b> <i>value2</i> |
|
329 |
* <td>{@link Query#plus Query.plus}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
330 |
* |
|
331 |
* <tr><td><i>value1</i> <b>-</b> <i>value2</i> |
|
332 |
* <td>{@link Query#minus Query.minus}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
333 |
* |
|
334 |
* <tr><td><i>value1</i> <b>*</b> <i>value2</i> |
|
335 |
* <td>{@link Query#times Query.times}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
336 |
* |
|
337 |
* <tr><td><i>value1</i> <b>/</b> <i>value2</i> |
|
338 |
* <td>{@link Query#div Query.div}(<i>q(value1)</i>, <i>q(value2)</i>) |
|
339 |
* |
|
340 |
* <tr><td><i>name</i> |
|
341 |
* <td>{@link Query#attr(String) Query.attr}(<i>q(name)</i>) |
|
342 |
* |
|
343 |
* <tr><td><i>name1<b>#</b>name2</i> |
|
344 |
* <td>{@link Query#attr(String,String) Query.attr}(<i>q(name1)</i>, |
|
345 |
* <i>q(name2)</i>) |
|
346 |
* |
|
347 |
* <tr><td><b>FALSE</b> |
|
348 |
* <td>{@link Query#value(boolean) Query.value}(false) |
|
349 |
* |
|
350 |
* <tr><td><b>TRUE</b> |
|
351 |
* <td>{@link Query#value(boolean) Query.value}(true) |
|
352 |
* |
|
353 |
* <tr><td><i>decimalLiteral</i> |
|
354 |
* <td>{@link Query#value(long) Query.value}(<!-- |
|
355 |
* -->{@link Long#valueOf(String) Long.valueOf}(<i>decimalLiteral</i>)) |
|
356 |
* |
|
357 |
* <tr><td><i>floatingPointLiteral</i> |
|
358 |
* <td>{@link Query#value(double) Query.value}(<!-- |
|
359 |
* -->{@link Double#valueOf(String) Double.valueOf}(<!-- |
|
360 |
* --><i>floatingPointLiteral</i>)) |
|
361 |
* </table> |
|
362 |
* |
|
2 | 363 |
* @since 1.5 |
364 |
*/ |
|
365 |
public class Query extends Object { |
|
366 |
||
367 |
||
368 |
/** |
|
369 |
* A code representing the {@link Query#gt} query. This is chiefly |
|
370 |
* of interest for the serialized form of queries. |
|
371 |
*/ |
|
372 |
public static final int GT = 0; |
|
373 |
||
374 |
/** |
|
375 |
* A code representing the {@link Query#lt} query. This is chiefly |
|
376 |
* of interest for the serialized form of queries. |
|
377 |
*/ |
|
378 |
public static final int LT = 1; |
|
379 |
||
380 |
/** |
|
381 |
* A code representing the {@link Query#geq} query. This is chiefly |
|
382 |
* of interest for the serialized form of queries. |
|
383 |
*/ |
|
384 |
public static final int GE = 2; |
|
385 |
||
386 |
/** |
|
387 |
* A code representing the {@link Query#leq} query. This is chiefly |
|
388 |
* of interest for the serialized form of queries. |
|
389 |
*/ |
|
390 |
public static final int LE = 3; |
|
391 |
||
392 |
/** |
|
393 |
* A code representing the {@link Query#eq} query. This is chiefly |
|
394 |
* of interest for the serialized form of queries. |
|
395 |
*/ |
|
396 |
public static final int EQ = 4; |
|
397 |
||
398 |
||
399 |
/** |
|
400 |
* A code representing the {@link Query#plus} expression. This |
|
401 |
* is chiefly of interest for the serialized form of queries. |
|
402 |
*/ |
|
403 |
public static final int PLUS = 0; |
|
404 |
||
405 |
/** |
|
406 |
* A code representing the {@link Query#minus} expression. This |
|
407 |
* is chiefly of interest for the serialized form of queries. |
|
408 |
*/ |
|
409 |
public static final int MINUS = 1; |
|
410 |
||
411 |
/** |
|
412 |
* A code representing the {@link Query#times} expression. This |
|
413 |
* is chiefly of interest for the serialized form of queries. |
|
414 |
*/ |
|
415 |
public static final int TIMES = 2; |
|
416 |
||
417 |
/** |
|
418 |
* A code representing the {@link Query#div} expression. This is |
|
419 |
* chiefly of interest for the serialized form of queries. |
|
420 |
*/ |
|
421 |
public static final int DIV = 3; |
|
422 |
||
423 |
||
424 |
/** |
|
425 |
* Basic constructor. |
|
426 |
*/ |
|
427 |
public Query() { |
|
428 |
} |
|
429 |
||
430 |
||
431 |
/** |
|
432 |
* Returns a query expression that is the conjunction of two other query |
|
433 |
* expressions. |
|
434 |
* |
|
435 |
* @param q1 A query expression. |
|
436 |
* @param q2 Another query expression. |
|
437 |
* |
|
438 |
* @return The conjunction of the two arguments. The returned object |
|
439 |
* will be serialized as an instance of the non-public class {@link |
|
440 |
* <a href="../../serialized-form.html#javax.management.AndQueryExp"> |
|
441 |
* javax.management.AndQueryExp</a>}. |
|
442 |
*/ |
|
443 |
public static QueryExp and(QueryExp q1, QueryExp q2) { |
|
444 |
return new AndQueryExp(q1, q2); |
|
445 |
} |
|
446 |
||
447 |
/** |
|
448 |
* Returns a query expression that is the disjunction of two other query |
|
449 |
* expressions. |
|
450 |
* |
|
451 |
* @param q1 A query expression. |
|
452 |
* @param q2 Another query expression. |
|
453 |
* |
|
454 |
* @return The disjunction of the two arguments. The returned object |
|
455 |
* will be serialized as an instance of the non-public class {@link |
|
456 |
* <a href="../../serialized-form.html#javax.management.OrQueryExp"> |
|
457 |
* javax.management.OrQueryExp</a>}. |
|
458 |
*/ |
|
459 |
public static QueryExp or(QueryExp q1, QueryExp q2) { |
|
460 |
return new OrQueryExp(q1, q2); |
|
461 |
} |
|
462 |
||
463 |
/** |
|
464 |
* Returns a query expression that represents a "greater than" constraint on |
|
465 |
* two values. |
|
466 |
* |
|
467 |
* @param v1 A value expression. |
|
468 |
* @param v2 Another value expression. |
|
469 |
* |
|
470 |
* @return A "greater than" constraint on the arguments. The |
|
471 |
* returned object will be serialized as an instance of the |
|
472 |
* non-public class {@link <a |
|
473 |
* href="../../serialized-form.html#javax.management.BinaryRelQueryExp"> |
|
474 |
* javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal |
|
475 |
* to {@link #GT}. |
|
476 |
*/ |
|
477 |
public static QueryExp gt(ValueExp v1, ValueExp v2) { |
|
478 |
return new BinaryRelQueryExp(GT, v1, v2); |
|
479 |
} |
|
480 |
||
481 |
/** |
|
482 |
* Returns a query expression that represents a "greater than or equal |
|
483 |
* to" constraint on two values. |
|
484 |
* |
|
485 |
* @param v1 A value expression. |
|
486 |
* @param v2 Another value expression. |
|
487 |
* |
|
488 |
* @return A "greater than or equal to" constraint on the |
|
489 |
* arguments. The returned object will be serialized as an |
|
490 |
* instance of the non-public class {@link <a |
|
491 |
* href="../../serialized-form.html#javax.management.BinaryRelQueryExp"> |
|
492 |
* javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal |
|
493 |
* to {@link #GE}. |
|
494 |
*/ |
|
495 |
public static QueryExp geq(ValueExp v1, ValueExp v2) { |
|
496 |
return new BinaryRelQueryExp(GE, v1, v2); |
|
497 |
} |
|
498 |
||
499 |
/** |
|
500 |
* Returns a query expression that represents a "less than or equal to" |
|
501 |
* constraint on two values. |
|
502 |
* |
|
503 |
* @param v1 A value expression. |
|
504 |
* @param v2 Another value expression. |
|
505 |
* |
|
506 |
* @return A "less than or equal to" constraint on the arguments. |
|
507 |
* The returned object will be serialized as an instance of the |
|
508 |
* non-public class {@link <a |
|
509 |
* href="../../serialized-form.html#javax.management.BinaryRelQueryExp"> |
|
510 |
* javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal |
|
511 |
* to {@link #LE}. |
|
512 |
*/ |
|
513 |
public static QueryExp leq(ValueExp v1, ValueExp v2) { |
|
514 |
return new BinaryRelQueryExp(LE, v1, v2); |
|
515 |
} |
|
516 |
||
517 |
/** |
|
518 |
* Returns a query expression that represents a "less than" constraint on |
|
519 |
* two values. |
|
520 |
* |
|
521 |
* @param v1 A value expression. |
|
522 |
* @param v2 Another value expression. |
|
523 |
* |
|
524 |
* @return A "less than" constraint on the arguments. The |
|
525 |
* returned object will be serialized as an instance of the |
|
526 |
* non-public class {@link <a |
|
527 |
* href="../../serialized-form.html#javax.management.BinaryRelQueryExp"> |
|
528 |
* javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal |
|
529 |
* to {@link #LT}. |
|
530 |
*/ |
|
531 |
public static QueryExp lt(ValueExp v1, ValueExp v2) { |
|
532 |
return new BinaryRelQueryExp(LT, v1, v2); |
|
533 |
} |
|
534 |
||
535 |
/** |
|
536 |
* Returns a query expression that represents an equality constraint on |
|
537 |
* two values. |
|
538 |
* |
|
539 |
* @param v1 A value expression. |
|
540 |
* @param v2 Another value expression. |
|
541 |
* |
|
542 |
* @return A "equal to" constraint on the arguments. The |
|
543 |
* returned object will be serialized as an instance of the |
|
544 |
* non-public class {@link <a |
|
545 |
* href="../../serialized-form.html#javax.management.BinaryRelQueryExp"> |
|
546 |
* javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal |
|
547 |
* to {@link #EQ}. |
|
548 |
*/ |
|
549 |
public static QueryExp eq(ValueExp v1, ValueExp v2) { |
|
550 |
return new BinaryRelQueryExp(EQ, v1, v2); |
|
551 |
} |
|
552 |
||
553 |
/** |
|
554 |
* Returns a query expression that represents the constraint that one |
|
555 |
* value is between two other values. |
|
556 |
* |
|
557 |
* @param v1 A value expression that is "between" v2 and v3. |
|
558 |
* @param v2 Value expression that represents a boundary of the constraint. |
|
559 |
* @param v3 Value expression that represents a boundary of the constraint. |
|
560 |
* |
|
561 |
* @return The constraint that v1 lies between v2 and v3. The |
|
562 |
* returned object will be serialized as an instance of the |
|
563 |
* non-public class {@link <a |
|
564 |
* href="../../serialized-form.html#javax.management.BetweenQueryExp"> |
|
565 |
* javax.management.BetweenQueryExp</a>}. |
|
566 |
*/ |
|
567 |
public static QueryExp between(ValueExp v1, ValueExp v2, ValueExp v3) { |
|
568 |
return new BetweenQueryExp(v1, v2, v3); |
|
569 |
} |
|
570 |
||
571 |
/** |
|
572 |
* Returns a query expression that represents a matching constraint on |
|
573 |
* a string argument. The matching syntax is consistent with file globbing: |
|
574 |
* supports "<code>?</code>", "<code>*</code>", "<code>[</code>", |
|
575 |
* each of which may be escaped with "<code>\</code>"; |
|
576 |
* character classes may use "<code>!</code>" for negation and |
|
577 |
* "<code>-</code>" for range. |
|
578 |
* (<code>*</code> for any character sequence, |
|
579 |
* <code>?</code> for a single arbitrary character, |
|
580 |
* <code>[...]</code> for a character sequence). |
|
581 |
* For example: <code>a*b?c</code> would match a string starting |
|
582 |
* with the character <code>a</code>, followed |
|
583 |
* by any number of characters, followed by a <code>b</code>, |
|
584 |
* any single character, and a <code>c</code>. |
|
585 |
* |
|
586 |
* @param a An attribute expression |
|
587 |
* @param s A string value expression representing a matching constraint |
|
588 |
* |
|
589 |
* @return A query expression that represents the matching |
|
590 |
* constraint on the string argument. The returned object will |
|
591 |
* be serialized as an instance of the non-public class {@link <a |
|
592 |
* href="../../serialized-form.html#javax.management.MatchQueryExp"> |
|
593 |
* javax.management.MatchQueryExp</a>}. |
|
594 |
*/ |
|
595 |
public static QueryExp match(AttributeValueExp a, StringValueExp s) { |
|
596 |
return new MatchQueryExp(a, s); |
|
597 |
} |
|
598 |
||
599 |
/** |
|
34 | 600 |
* <p>Returns a new attribute expression. See {@link AttributeValueExp} |
601 |
* for a detailed description of the semantics of the expression.</p> |
|
2 | 602 |
* |
603 |
* @param name The name of the attribute. |
|
604 |
* |
|
34 | 605 |
* @return An attribute expression for the attribute named {@code name}. |
2 | 606 |
*/ |
607 |
public static AttributeValueExp attr(String name) { |
|
608 |
return new AttributeValueExp(name); |
|
609 |
} |
|
610 |
||
611 |
/** |
|
612 |
* <p>Returns a new qualified attribute expression.</p> |
|
613 |
* |
|
614 |
* <p>Evaluating this expression for a given |
|
615 |
* <code>objectName</code> includes performing {@link |
|
616 |
* MBeanServer#getObjectInstance |
|
617 |
* MBeanServer.getObjectInstance(objectName)} and {@link |
|
618 |
* MBeanServer#getAttribute MBeanServer.getAttribute(objectName, |
|
619 |
* name)}.</p> |
|
620 |
* |
|
621 |
* @param className The name of the class possessing the attribute. |
|
622 |
* @param name The name of the attribute. |
|
623 |
* |
|
624 |
* @return An attribute expression for the attribute named name. |
|
625 |
* The returned object will be serialized as an instance of the |
|
626 |
* non-public class {@link <a |
|
627 |
* href="../../serialized-form.html#javax.management.QualifiedAttributeValueExp"> |
|
628 |
* javax.management.QualifiedAttributeValueExp</a>}. |
|
629 |
*/ |
|
630 |
public static AttributeValueExp attr(String className, String name) { |
|
631 |
return new QualifiedAttributeValueExp(className, name); |
|
632 |
} |
|
633 |
||
634 |
/** |
|
635 |
* <p>Returns a new class attribute expression which can be used in any |
|
636 |
* Query call that expects a ValueExp.</p> |
|
637 |
* |
|
638 |
* <p>Evaluating this expression for a given |
|
639 |
* <code>objectName</code> includes performing {@link |
|
640 |
* MBeanServer#getObjectInstance |
|
641 |
* MBeanServer.getObjectInstance(objectName)}.</p> |
|
642 |
* |
|
643 |
* @return A class attribute expression. The returned object |
|
644 |
* will be serialized as an instance of the non-public class |
|
645 |
* {@link <a |
|
646 |
* href="../../serialized-form.html#javax.management.ClassAttributeValueExp"> |
|
647 |
* javax.management.ClassAttributeValueExp</a>}. |
|
648 |
*/ |
|
649 |
public static AttributeValueExp classattr() { |
|
650 |
return new ClassAttributeValueExp(); |
|
651 |
} |
|
652 |
||
653 |
/** |
|
654 |
* Returns a constraint that is the negation of its argument. |
|
655 |
* |
|
656 |
* @param queryExp The constraint to negate. |
|
657 |
* |
|
658 |
* @return A negated constraint. The returned object will be |
|
659 |
* serialized as an instance of the non-public class {@link <a |
|
660 |
* href="../../serialized-form.html#javax.management.NotQueryExp"> |
|
661 |
* javax.management.NotQueryExp</a>}. |
|
662 |
*/ |
|
663 |
public static QueryExp not(QueryExp queryExp) { |
|
664 |
return new NotQueryExp(queryExp); |
|
665 |
} |
|
666 |
||
667 |
/** |
|
668 |
* Returns an expression constraining a value to be one of an explicit list. |
|
669 |
* |
|
670 |
* @param val A value to be constrained. |
|
671 |
* @param valueList An array of ValueExps. |
|
672 |
* |
|
673 |
* @return A QueryExp that represents the constraint. The |
|
674 |
* returned object will be serialized as an instance of the |
|
675 |
* non-public class {@link <a |
|
676 |
* href="../../serialized-form.html#javax.management.InQueryExp"> |
|
677 |
* javax.management.InQueryExp</a>}. |
|
678 |
*/ |
|
679 |
public static QueryExp in(ValueExp val, ValueExp valueList[]) { |
|
680 |
return new InQueryExp(val, valueList); |
|
681 |
} |
|
682 |
||
683 |
/** |
|
684 |
* Returns a new string expression. |
|
685 |
* |
|
686 |
* @param val The string value. |
|
687 |
* |
|
688 |
* @return A ValueExp object containing the string argument. |
|
689 |
*/ |
|
690 |
public static StringValueExp value(String val) { |
|
691 |
return new StringValueExp(val); |
|
692 |
} |
|
693 |
||
694 |
/** |
|
695 |
* Returns a numeric value expression that can be used in any Query call |
|
696 |
* that expects a ValueExp. |
|
697 |
* |
|
698 |
* @param val An instance of Number. |
|
699 |
* |
|
700 |
* @return A ValueExp object containing the argument. The |
|
701 |
* returned object will be serialized as an instance of the |
|
702 |
* non-public class {@link <a |
|
703 |
* href="../../serialized-form.html#javax.management.NumericValueExp"> |
|
704 |
* javax.management.NumericValueExp</a>}. |
|
705 |
*/ |
|
706 |
public static ValueExp value(Number val) { |
|
707 |
return new NumericValueExp(val); |
|
708 |
} |
|
709 |
||
710 |
/** |
|
711 |
* Returns a numeric value expression that can be used in any Query call |
|
712 |
* that expects a ValueExp. |
|
713 |
* |
|
714 |
* @param val An int value. |
|
715 |
* |
|
716 |
* @return A ValueExp object containing the argument. The |
|
717 |
* returned object will be serialized as an instance of the |
|
718 |
* non-public class {@link <a |
|
719 |
* href="../../serialized-form.html#javax.management.NumericValueExp"> |
|
720 |
* javax.management.NumericValueExp</a>}. |
|
721 |
*/ |
|
722 |
public static ValueExp value(int val) { |
|
723 |
return new NumericValueExp((long) val); |
|
724 |
} |
|
725 |
||
726 |
/** |
|
727 |
* Returns a numeric value expression that can be used in any Query call |
|
728 |
* that expects a ValueExp. |
|
729 |
* |
|
730 |
* @param val A long value. |
|
731 |
* |
|
732 |
* @return A ValueExp object containing the argument. The |
|
733 |
* returned object will be serialized as an instance of the |
|
734 |
* non-public class {@link <a |
|
735 |
* href="../../serialized-form.html#javax.management.NumericValueExp"> |
|
736 |
* javax.management.NumericValueExp</a>}. |
|
737 |
*/ |
|
738 |
public static ValueExp value(long val) { |
|
739 |
return new NumericValueExp(val); |
|
740 |
} |
|
741 |
||
742 |
/** |
|
743 |
* Returns a numeric value expression that can be used in any Query call |
|
744 |
* that expects a ValueExp. |
|
745 |
* |
|
746 |
* @param val A float value. |
|
747 |
* |
|
748 |
* @return A ValueExp object containing the argument. The |
|
749 |
* returned object will be serialized as an instance of the |
|
750 |
* non-public class {@link <a |
|
751 |
* href="../../serialized-form.html#javax.management.NumericValueExp"> |
|
752 |
* javax.management.NumericValueExp</a>}. |
|
753 |
*/ |
|
754 |
public static ValueExp value(float val) { |
|
755 |
return new NumericValueExp((double) val); |
|
756 |
} |
|
757 |
||
758 |
/** |
|
759 |
* Returns a numeric value expression that can be used in any Query call |
|
760 |
* that expects a ValueExp. |
|
761 |
* |
|
762 |
* @param val A double value. |
|
763 |
* |
|
764 |
* @return A ValueExp object containing the argument. The |
|
765 |
* returned object will be serialized as an instance of the |
|
766 |
* non-public class {@link <a |
|
767 |
* href="../../serialized-form.html#javax.management.NumericValueExp"> |
|
768 |
* javax.management.NumericValueExp</a>}. |
|
769 |
*/ |
|
770 |
public static ValueExp value(double val) { |
|
771 |
return new NumericValueExp(val); |
|
772 |
} |
|
773 |
||
774 |
/** |
|
775 |
* Returns a boolean value expression that can be used in any Query call |
|
776 |
* that expects a ValueExp. |
|
777 |
* |
|
778 |
* @param val A boolean value. |
|
779 |
* |
|
780 |
* @return A ValueExp object containing the argument. The |
|
781 |
* returned object will be serialized as an instance of the |
|
782 |
* non-public class {@link <a |
|
783 |
* href="../../serialized-form.html#javax.management.BooleanValueExp"> |
|
784 |
* javax.management.BooleanValueExp</a>}. |
|
785 |
*/ |
|
786 |
public static ValueExp value(boolean val) { |
|
787 |
return new BooleanValueExp(val); |
|
788 |
} |
|
789 |
||
790 |
/** |
|
791 |
* Returns a binary expression representing the sum of two numeric values, |
|
792 |
* or the concatenation of two string values. |
|
793 |
* |
|
794 |
* @param value1 The first '+' operand. |
|
795 |
* @param value2 The second '+' operand. |
|
796 |
* |
|
797 |
* @return A ValueExp representing the sum or concatenation of |
|
798 |
* the two arguments. The returned object will be serialized as |
|
799 |
* an instance of the non-public class {@link <a |
|
800 |
* href="../../serialized-form.html#javax.management.BinaryOpValueExp"> |
|
801 |
* javax.management.BinaryOpValueExp</a>} with an {@code op} equal to |
|
802 |
* {@link #PLUS}. |
|
803 |
*/ |
|
804 |
public static ValueExp plus(ValueExp value1, ValueExp value2) { |
|
805 |
return new BinaryOpValueExp(PLUS, value1, value2); |
|
806 |
} |
|
807 |
||
808 |
/** |
|
809 |
* Returns a binary expression representing the product of two numeric values. |
|
810 |
* |
|
811 |
* |
|
812 |
* @param value1 The first '*' operand. |
|
813 |
* @param value2 The second '*' operand. |
|
814 |
* |
|
815 |
* @return A ValueExp representing the product. The returned |
|
816 |
* object will be serialized as an instance of the non-public |
|
817 |
* class {@link <a |
|
818 |
* href="../../serialized-form.html#javax.management.BinaryOpValueExp"> |
|
819 |
* javax.management.BinaryOpValueExp</a>} with an {@code op} equal to |
|
820 |
* {@link #TIMES}. |
|
821 |
*/ |
|
822 |
public static ValueExp times(ValueExp value1,ValueExp value2) { |
|
823 |
return new BinaryOpValueExp(TIMES, value1, value2); |
|
824 |
} |
|
825 |
||
826 |
/** |
|
827 |
* Returns a binary expression representing the difference between two numeric |
|
828 |
* values. |
|
829 |
* |
|
830 |
* @param value1 The first '-' operand. |
|
831 |
* @param value2 The second '-' operand. |
|
832 |
* |
|
833 |
* @return A ValueExp representing the difference between two |
|
834 |
* arguments. The returned object will be serialized as an |
|
835 |
* instance of the non-public class {@link <a |
|
836 |
* href="../../serialized-form.html#javax.management.BinaryOpValueExp"> |
|
837 |
* javax.management.BinaryOpValueExp</a>} with an {@code op} equal to |
|
838 |
* {@link #MINUS}. |
|
839 |
*/ |
|
840 |
public static ValueExp minus(ValueExp value1, ValueExp value2) { |
|
841 |
return new BinaryOpValueExp(MINUS, value1, value2); |
|
842 |
} |
|
843 |
||
844 |
/** |
|
845 |
* Returns a binary expression representing the quotient of two numeric |
|
846 |
* values. |
|
847 |
* |
|
848 |
* @param value1 The first '/' operand. |
|
849 |
* @param value2 The second '/' operand. |
|
850 |
* |
|
851 |
* @return A ValueExp representing the quotient of two arguments. |
|
852 |
* The returned object will be serialized as an instance of the |
|
853 |
* non-public class {@link <a |
|
854 |
* href="../../serialized-form.html#javax.management.BinaryOpValueExp"> |
|
855 |
* javax.management.BinaryOpValueExp</a>} with an {@code op} equal to |
|
856 |
* {@link #DIV}. |
|
857 |
*/ |
|
858 |
public static ValueExp div(ValueExp value1, ValueExp value2) { |
|
859 |
return new BinaryOpValueExp(DIV, value1, value2); |
|
860 |
} |
|
861 |
||
862 |
/** |
|
863 |
* Returns a query expression that represents a matching constraint on |
|
864 |
* a string argument. The value must start with the given literal string |
|
865 |
* value. |
|
866 |
* |
|
867 |
* @param a An attribute expression. |
|
868 |
* @param s A string value expression representing the beginning of the |
|
869 |
* string value. |
|
870 |
* |
|
871 |
* @return The constraint that a matches s. The returned object |
|
872 |
* will be serialized as an instance of the non-public class |
|
873 |
* {@link <a |
|
874 |
* href="../../serialized-form.html#javax.management.MatchQueryExp"> |
|
875 |
* javax.management.MatchQueryExp</a>}. |
|
876 |
*/ |
|
877 |
public static QueryExp initialSubString(AttributeValueExp a, StringValueExp s) { |
|
878 |
return new MatchQueryExp(a, |
|
879 |
new StringValueExp(escapeString(s.getValue()) + "*")); |
|
880 |
} |
|
881 |
||
882 |
/** |
|
883 |
* Returns a query expression that represents a matching constraint on |
|
884 |
* a string argument. The value must contain the given literal string |
|
885 |
* value. |
|
886 |
* |
|
887 |
* @param a An attribute expression. |
|
888 |
* @param s A string value expression representing the substring. |
|
889 |
* |
|
890 |
* @return The constraint that a matches s. The returned object |
|
891 |
* will be serialized as an instance of the non-public class |
|
892 |
* {@link <a |
|
893 |
* href="../../serialized-form.html#javax.management.MatchQueryExp"> |
|
894 |
* javax.management.MatchQueryExp</a>}. |
|
895 |
*/ |
|
896 |
public static QueryExp anySubString(AttributeValueExp a, StringValueExp s) { |
|
897 |
return new MatchQueryExp(a, |
|
898 |
new StringValueExp("*" + escapeString(s.getValue()) + "*")); |
|
899 |
} |
|
900 |
||
901 |
/** |
|
902 |
* Returns a query expression that represents a matching constraint on |
|
903 |
* a string argument. The value must end with the given literal string |
|
904 |
* value. |
|
905 |
* |
|
906 |
* @param a An attribute expression. |
|
907 |
* @param s A string value expression representing the end of the string |
|
908 |
* value. |
|
909 |
* |
|
910 |
* @return The constraint that a matches s. The returned object |
|
911 |
* will be serialized as an instance of the non-public class |
|
912 |
* {@link <a |
|
913 |
* href="../../serialized-form.html#javax.management.MatchQueryExp"> |
|
914 |
* javax.management.MatchQueryExp</a>}. |
|
915 |
*/ |
|
916 |
public static QueryExp finalSubString(AttributeValueExp a, StringValueExp s) { |
|
917 |
return new MatchQueryExp(a, |
|
918 |
new StringValueExp("*" + escapeString(s.getValue()))); |
|
919 |
} |
|
920 |
||
921 |
/** |
|
922 |
* Returns a query expression that represents an inheritance constraint |
|
923 |
* on an MBean class. |
|
924 |
* <p>Example: to find MBeans that are instances of |
|
925 |
* {@link NotificationBroadcaster}, use |
|
926 |
* {@code Query.isInstanceOf(Query.value(NotificationBroadcaster.class.getName()))}. |
|
927 |
* </p> |
|
928 |
* <p>Evaluating this expression for a given |
|
929 |
* <code>objectName</code> includes performing {@link |
|
930 |
* MBeanServer#isInstanceOf MBeanServer.isInstanceOf(objectName, |
|
931 |
* ((StringValueExp)classNameValue.apply(objectName)).getValue()}.</p> |
|
932 |
* |
|
933 |
* @param classNameValue The {@link StringValueExp} returning the name |
|
934 |
* of the class of which selected MBeans should be instances. |
|
935 |
* @return a query expression that represents an inheritance |
|
936 |
* constraint on an MBean class. The returned object will be |
|
937 |
* serialized as an instance of the non-public class {@link <a |
|
938 |
* href="../../serialized-form.html#javax.management.InstanceOfQueryExp"> |
|
939 |
* javax.management.InstanceOfQueryExp</a>}. |
|
940 |
* @since 1.6 |
|
941 |
*/ |
|
942 |
public static QueryExp isInstanceOf(StringValueExp classNameValue) { |
|
943 |
return new InstanceOfQueryExp(classNameValue); |
|
944 |
} |
|
945 |
||
946 |
/** |
|
34 | 947 |
* <p>Return a string representation of the given query. The string |
948 |
* returned by this method can be converted back into an equivalent |
|
949 |
* query using {@link #fromString fromString}.</p> |
|
950 |
* |
|
951 |
* <p>(Two queries are equivalent if they produce the same result in |
|
952 |
* all cases. Equivalent queries are not necessarily identical: |
|
953 |
* for example the queries {@code Query.lt(Query.attr("A"), Query.attr("B"))} |
|
954 |
* and {@code Query.not(Query.ge(Query.attr("A"), Query.attr("B")))} are |
|
955 |
* equivalent but not identical.)</p> |
|
956 |
* |
|
957 |
* <p>The string returned by this method is only guaranteed to be converted |
|
958 |
* back into an equivalent query if {@code query} was constructed, or |
|
959 |
* could have been constructed, using the methods of this class. |
|
960 |
* If you make a custom query {@code myQuery} by implementing |
|
961 |
* {@link QueryExp} yourself then the result of |
|
962 |
* {@code Query.toString(myQuery)} is unspecified.</p> |
|
963 |
* |
|
964 |
* @param query the query to convert. If it is null, the result will |
|
965 |
* also be null. |
|
966 |
* @return the string representation of the query, or null if the |
|
967 |
* query is null. |
|
968 |
* |
|
969 |
* @since 1.7 |
|
970 |
*/ |
|
971 |
public static String toString(QueryExp query) { |
|
972 |
if (query == null) |
|
973 |
return null; |
|
974 |
||
471
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
975 |
// This is ugly. At one stage we had a non-public class called |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
976 |
// ToQueryString with the toQueryString() method, and every class |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
977 |
// mentioned here inherited from that class. But that interfered |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
978 |
// with serialization of custom subclasses of e.g. QueryEval. Even |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
979 |
// though we could make it work by adding a public constructor to this |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
980 |
// non-public class, that seemed fragile because according to the |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
981 |
// serialization spec it shouldn't work. If only non-public interfaces |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
982 |
// could have non-public methods. |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
983 |
if (query instanceof ObjectName) |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
984 |
return ((ObjectName) query).toQueryString(); |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
985 |
if (query instanceof QueryEval) |
422ff0db58d3
6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents:
34
diff
changeset
|
986 |
return ((QueryEval) query).toQueryString(); |
34 | 987 |
|
988 |
return query.toString(); |
|
989 |
} |
|
990 |
||
991 |
/** |
|
992 |
* <p>Produce a query from the given string. The query returned |
|
993 |
* by this method can be converted back into a string using |
|
994 |
* {@link #toString(QueryExp) toString}. The resultant string will |
|
995 |
* not necessarily be equal to {@code s}.</p> |
|
996 |
* |
|
997 |
* @param s the string to convert. |
|
998 |
* |
|
999 |
* @return a {@code QueryExp} derived by parsing the string, or |
|
1000 |
* null if the string is null. |
|
1001 |
* |
|
1002 |
* @throws IllegalArgumentException if the string is not a valid |
|
1003 |
* query string. |
|
1004 |
* |
|
1005 |
* @since 1.7 |
|
1006 |
*/ |
|
1007 |
public static QueryExp fromString(String s) { |
|
1008 |
if (s == null) |
|
1009 |
return null; |
|
1010 |
return new QueryParser(s).parseQuery(); |
|
1011 |
} |
|
1012 |
||
1013 |
/** |
|
2 | 1014 |
* Utility method to escape strings used with |
1015 |
* Query.{initial|any|final}SubString() methods. |
|
1016 |
*/ |
|
1017 |
private static String escapeString(String s) { |
|
1018 |
if (s == null) |
|
1019 |
return null; |
|
1020 |
s = s.replace("\\", "\\\\"); |
|
1021 |
s = s.replace("*", "\\*"); |
|
1022 |
s = s.replace("?", "\\?"); |
|
1023 |
s = s.replace("[", "\\["); |
|
1024 |
return s; |
|
1025 |
} |
|
1026 |
} |