Query.java revision 11
0N/A/*
0N/A * Copyright 1999-2005 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation. Sun designates this
0N/A * particular file as subject to the "Classpath" exception as provided
0N/A * by Sun in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
0N/A * have any questions.
0N/A */
0N/A
0N/Apackage javax.management;
0N/A
0N/A
0N/A/**
11N/A * <p>Constructs query object constraints.</p>
11N/A *
11N/A * <p>The MBean Server can be queried for MBeans that meet a particular
11N/A * condition, using its {@link MBeanServer#queryNames queryNames} or
11N/A * {@link MBeanServer#queryMBeans queryMBeans} method. The {@link QueryExp}
11N/A * parameter to the method can be any implementation of the interface
11N/A * {@code QueryExp}, but it is usually best to obtain the {@code QueryExp}
11N/A * value by calling the static methods in this class. This is particularly
11N/A * true when querying a remote MBean Server: a custom implementation of the
11N/A * {@code QueryExp} interface might not be present in the remote MBean Server,
11N/A * but the methods in this class return only standard classes that are
11N/A * part of the JMX implementation.</p>
11N/A *
11N/A * <p>There are two ways to create {@code QueryExp} objects using the methods
11N/A * in this class. The first is to build them by chaining together calls to
11N/A * the various methods. The second is to use the Query Language described
11N/A * <a href="#ql">below</a> and produce the {@code QueryExp} by calling
11N/A * {@link #fromString Query.fromString}. The two ways are equivalent:
11N/A * every {@code QueryExp} returned by {@code fromString} can also be
11N/A * constructed by chaining method calls.</p>
11N/A *
11N/A * <p>As an example, suppose you wanted to find all MBeans where the {@code
11N/A * Enabled} attribute is {@code true} and the {@code Owner} attribute is {@code
11N/A * "Duke"}. Here is how you could construct the appropriate {@code QueryExp} by
11N/A * chaining together method calls:</p>
11N/A *
11N/A * <pre>
11N/A * QueryExp query =
11N/A * Query.and(Query.eq(Query.attr("Enabled"), Query.value(true)),
11N/A * Query.eq(Query.attr("Owner"), Query.value("Duke")));
11N/A * </pre>
11N/A *
11N/A * <p>Here is how you could construct the same {@code QueryExp} using the
11N/A * Query Language:</p>
0N/A *
0N/A * <pre>
11N/A * QueryExp query = Query.fromString("Enabled = true and Owner = 'Duke'");
0N/A * </pre>
0N/A *
11N/A * <p>The principal advantage of the method-chaining approach is that the
11N/A * compiler will check that the query makes sense. The principal advantage
11N/A * of the Query Language approach is that it is easier to write and especially
11N/A * read.</p>
11N/A *
11N/A *
11N/A * <h4 id="ql">Query Language</h4>
11N/A *
11N/A * <p>The query language is closely modeled on the WHERE clause of
11N/A * SQL SELECT statements. The formal specification of the language
11N/A * appears <a href="#formal-ql">below</a>, but it is probably easier to
11N/A * understand it with examples such as the following.</p>
11N/A *
11N/A * <dl>
11N/A * <dt>{@code Message = 'OK'}
11N/A * <dd>Selects MBeans that have a {@code Message} attribute whose value
11N/A * is the string {@code OK}.
11N/A *
11N/A * <dt>{@code FreeSpacePercent < 10}
11N/A * <dd>Selects MBeans that have a {@code FreeSpacePercent} attribute whose
11N/A * value is a number less than 10.
11N/A *
11N/A * <dt>{@code FreeSpacePercent < 10 and WarningSent = false}
11N/A * <dd>Selects the same MBeans as the previous example, but they must
11N/A * also have a boolean attribute {@code WarningSent} whose value
11N/A * is false.
11N/A *
11N/A * <dt>{@code SpaceUsed > TotalSpace * (2.0 / 3.0)}
11N/A * <dd>Selects MBeans that have {@code SpaceUsed} and {@code TotalSpace}
11N/A * attributes where the first is more than two-thirds the second.
11N/A *
11N/A * <dt>{@code not (FreeSpacePercent between 10 and 90)}
11N/A * <dd>Selects MBeans that have a {@code FreeSpacePercent} attribute whose
11N/A * value is not between 10 and 90, inclusive.
11N/A *
11N/A * <dt>{@code FreeSpacePercent not between 10 and 90}
11N/A * <dd>Another way of writing the previous query.
11N/A *
11N/A * <dt>{@code Status in ('STOPPED', 'STARTING', 'STARTED')}
11N/A * <dd>Selects MBeans that have a {@code Status} attribute whose value
11N/A * is one of those three strings.
11N/A *
11N/A * <dt>{@code Message like 'OK: %'}
11N/A * <dd>Selects MBeans that have a {@code Message} attribute whose value
11N/A * is a string beginning with {@code "OK: "}. <b>Notice that the
11N/A * wildcard characters are SQL's ones.</b> In the query language,
11N/A * {@code %} means "any sequence of characters" and {@code _}
11N/A * means "any single character". In the rest of the JMX API, these
11N/A * correspond to {@code *} and {@code %} respectively.
11N/A *
11N/A * <dt>{@code instanceof 'javax.management.NotificationBroadcaster'}
11N/A * <dd>Selects MBeans that are instances of
11N/A * {@link javax.management.NotificationBroadcaster}, as reported by
11N/A * {@link javax.management.MBeanServer#isInstanceOf MBeanServer.isInstanceOf}.
11N/A *
11N/A * <dt>{@code like 'mydomain:*'}
11N/A * <dd>Selects MBeans whose {@link ObjectName}s have the domain {@code mydomain}.
11N/A *
11N/A * </dl>
11N/A *
11N/A * <p>The last two examples do not correspond to valid SQL syntax, but all
11N/A * the others do.</p>
11N/A *
11N/A * <p>The remainder of this description is a formal specification of the
11N/A * query language.</p>
11N/A *
11N/A *
11N/A * <h4 id="formal-ql">Lexical elements</h4>
11N/A *
11N/A * <p>Keywords such as <b>and</b>, <b>like</b>, and <b>between</b> are not
11N/A * case sensitive. You can write <b>between</b>, <b>BETWEEN</b>, or
11N/A * <b>BeTwEeN</b> with the same effect.</p>
11N/A *
11N/A * <p>On the other hand, attribute names <i>are</i> case sensitive. The
11N/A * attribute {@code Name} is not the same as the attribute {@code name}.</p>
11N/A *
11N/A * <p>To access an attribute whose name, ignoring case, is the same as one of
11N/A * the keywords {@code not}, {@code instanceof}, {@code like}, {@code true},
11N/A * or {@code false}, you can use double quotes, for example {@code "not"}.
11N/A * Double quotes can also be used to include non-identifier characters in
11N/A * the name of an attribute, for example {@code "attribute-name-with-hyphens"}.
11N/A * To include the double quote character in the attribute name, write it
11N/A * twice. {@code "foo""bar""baz"} represents the attribute called
11N/A * {@code foo"bar"baz}.
11N/A *
11N/A * <p>String constants are written with single quotes like {@code 'this'}. A
11N/A * single quote within a string constant must be doubled, for example
11N/A * {@code 'can''t'}.</p>
11N/A *
11N/A * <p>Integer constants are written as a sequence of decimal digits,
11N/A * optionally preceded by a plus or minus sign. An integer constant must be
11N/A * a valid input to {@link Long#valueOf(String)}.</p>
11N/A *
11N/A * <p>Floating-point constants are written using the Java syntax. A
11N/A * floating-point constant must be a valid input to
11N/A * {@link Double#valueOf(String)}.</p>
11N/A *
11N/A * <p>A boolean constant is either {@code true} or {@code false}, ignoring
11N/A * case.</p>
11N/A *
11N/A * <p>Spaces cannot appear inside identifiers (unless written with double
11N/A * quotes) or keywords or multi-character tokens such as {@code <=}. Spaces can
11N/A * appear anywhere else, but are not required except to separate tokens. For
11N/A * example, the query {@code a < b and 5 = c} could also be written {@code a<b
11N/A * and 5=c}, but no further spaces can be removed.</p>
11N/A *
11N/A *
11N/A * <h4 id="grammar-ql">Grammar</h4>
11N/A *
11N/A * <dl>
11N/A * <dt id="query">query:
11N/A * <dd><a href="#andquery">andquery</a> [<b>OR</b> <a href="#query">query</a>]
11N/A *
11N/A * <dt id="andquery">andquery:
11N/A * <dd><a href="#predicate">predicate</a> [<b>AND</b> <a href="#andquery">andquery</a>]
11N/A *
11N/A * <dt id="predicate">predicate:
11N/A * <dd><b>(</b> <a href="#query">query</a> <b>)</b> |<br>
11N/A * <b>NOT</b> <a href="#predicate">predicate</a> |<br>
11N/A * <b>INSTANCEOF</b> <a href="#stringvalue">stringvalue</a> |<br>
11N/A * <b>LIKE</b> <a href="#objectnamepattern">objectnamepattern</a> |<br>
11N/A * <a href="#value">value</a> <a href="#predrhs">predrhs</a>
11N/A *
11N/A * <dt id="predrhs">predrhs:
11N/A * <dd><a href="#compare">compare</a> <a href="#value">value</a> |<br>
11N/A * [<b>NOT</b>] <b>BETWEEN</b> <a href="#value">value</a> <b>AND</b>
11N/A * <a href="#value">value</a> |<br>
11N/A * [<b>NOT</b>] <b>IN (</b> <a href="#value">value</a>
11N/A * <a href="#commavalues">commavalues</a> <b>)</b> |<br>
11N/A * [<b>NOT</b>] <b>LIKE</b> <a href="#stringvalue">stringvalue</a>
11N/A *
11N/A * <dt id="commavalues">commavalues:
11N/A * <dd>[ <b>,</b> <a href="#value">value</a> <a href="#commavalues">commavalues</a> ]
11N/A *
11N/A * <dt id="compare">compare:
11N/A * <dd><b>=</b> | <b>&lt;</b> | <b>&gt;</b> |
11N/A * <b>&lt;=</b> | <b>&gt;=</b> | <b>&lt;&gt;</b> | <b>!=</b>
11N/A *
11N/A * <dt id="value">value:
11N/A * <dd><a href="#factor">factor</a> [<a href="#plusorminus">plusorminus</a>
11N/A * <a href="#value">value</a>]
11N/A *
11N/A * <dt id="plusorminus">plusorminus:
11N/A * <dd><b>+</b> | <b>-</b>
11N/A *
11N/A * <dt id="factor">factor:
11N/A * <dd><a href="#term">term</a> [<a href="#timesordivide">timesordivide</a>
11N/A * <a href="#factor">factor</a>]
11N/A *
11N/A * <dt id="timesordivide">timesordivide:
11N/A * <dd><b>*</b> | <b>/</b>
11N/A *
11N/A * <dt id="term">term:
11N/A * <dd><a href="#attr">attr</a> | <a href="#literal">literal</a> |
11N/A * <b>(</b> <a href="#value">value</a> <b>)</b>
11N/A *
11N/A * <dt id="attr">attr:
11N/A * <dd><a href="#name">name</a> [<b>#</b> <a href="#name">name</a>]
11N/A *
11N/A * <dt id="name">name:
11N/A * <dd><a href="#identifier">identifier</a> [<b>.</b><a href="#name">name</a>]
11N/A *
11N/A * <dt id="identifier">identifier:
11N/A * <dd><i>Java-identifier</i> | <i>double-quoted-identifier</i>
11N/A *
11N/A * <dt id="literal">literal:
11N/A * <dd><a href="#booleanlit">booleanlit</a> | <i>longlit</i> |
11N/A * <i>doublelit</i> | <i>stringlit</i>
11N/A *
11N/A * <dt id="booleanlit">booleanlit:
11N/A * <dd><b>FALSE</b> | <b>TRUE</b>
11N/A *
11N/A * <dt id="stringvalue">stringvalue:
11N/A * <dd><i>stringlit</i>
11N/A *
11N/A * <dt id="objectnamepattern">objectnamepattern:
11N/A * <dd><i>stringlit</i>
11N/A *
11N/A * </dl>
11N/A *
11N/A *
11N/A * <h4>Semantics</h4>
11N/A *
11N/A * <p>The meaning of the grammar is described in the table below.
11N/A * This defines a function <i>q</i> that maps a string to a Java object
11N/A * such as a {@link QueryExp} or a {@link ValueExp}.</p>
11N/A *
11N/A * <table border="1" cellpadding="5">
11N/A * <tr><th>String <i>s</i></th><th><i>q(s)</th></tr>
11N/A *
11N/A * <tr><td><i>query1</i> <b>OR</b> <i>query2</i>
11N/A * <td>{@link Query#or Query.or}(<i>q(query1)</i>, <i>q(query2)</i>)
11N/A *
11N/A * <tr><td><i>query1</i> <b>AND</b> <i>query2</i>
11N/A * <td>{@link Query#and Query.and}(<i>q(query1)</i>, <i>q(query2)</i>)
11N/A *
11N/A * <tr><td><b>(</b> <i>queryOrValue</i> <b>)</b>
11N/A * <td><i>q(queryOrValue)</i>
11N/A *
11N/A * <tr><td><b>NOT</b> <i>query</i>
11N/A * <td>{@link Query#not Query.not}(<i>q(query)</i>)
11N/A *
11N/A * <tr><td><b>INSTANCEOF</b> <i>stringLiteral</i>
11N/A * <td>{@link Query#isInstanceOf Query.isInstanceOf}(<!--
11N/A * -->{@link Query#value(String) Query.value}(<i>q(stringLiteral)</i>))
11N/A *
11N/A * <tr><td><b>LIKE</b> <i>stringLiteral</i>
11N/A * <td>{@link ObjectName#ObjectName(String) new ObjectName}(<!--
11N/A * --><i>q(stringLiteral)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>=</b> <i>value2</i>
11N/A * <td>{@link Query#eq Query.eq}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>&lt;</b> <i>value2</i>
11N/A * <td>{@link Query#lt Query.lt}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>&gt;</b> <i>value2</i>
11N/A * <td>{@link Query#gt Query.gt}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>&lt;=</b> <i>value2</i>
11N/A * <td>{@link Query#leq Query.leq}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>&gt;=</b> <i>value2</i>
11N/A * <td>{@link Query#geq Query.geq}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>&lt;&gt;</b> <i>value2</i>
11N/A * <td>{@link Query#not Query.not}({@link Query#eq Query.eq}(<!--
11N/A * --><i>q(value1)</i>, <i>q(value2)</i>))
11N/A *
11N/A * <tr><td><i>value1</i> <b>!=</b> <i>value2</i>
11N/A * <td>{@link Query#not Query.not}({@link Query#eq Query.eq}(<!--
11N/A * --><i>q(value1)</i>, <i>q(value2)</i>))
11N/A *
11N/A * <tr><td><i>value1</i> <b>BETWEEN</b> <i>value2</i> AND <i>value3</i>
11N/A * <td>{@link Query#between Query.between}(<i>q(value1)</i>,
11N/A * <i>q(value2)</i>, <i>q(value3)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>NOT BETWEEN</b> <i>value2</i> AND <i>value3</i>
11N/A * <td>{@link Query#not Query.not}({@link Query#between Query.between}(<!--
11N/A * --><i>q(value1)</i>, <i>q(value2)</i>, <i>q(value3)</i>))
11N/A *
11N/A * <tr><td><i>value1</i> <b>IN (</b> <i>value2</i>, <i>value3</i> <b>)</b>
11N/A * <td>{@link Query#in Query.in}(<i>q(value1)</i>,
11N/A * <code>new ValueExp[] {</code>
11N/A * <i>q(value2)</i>, <i>q(value3)</i><code>}</code>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>NOT IN (</b> <i>value2</i>, <i>value3</i> <b>)</b>
11N/A * <td>{@link Query#not Query.not}({@link Query#in Query.in}(<i>q(value1)</i>,
11N/A * <code>new ValueExp[] {</code>
11N/A * <i>q(value2)</i>, <i>q(value3)</i><code>}</code>))
11N/A *
11N/A * <tr><td><i>value</i> <b>LIKE</b> <i>stringLiteral</i>
11N/A * <td>{@link Query#match Query.match}(<i>q(value)</i>,
11N/A * <i><a href="#translateWildcards">translateWildcards</a>(q(stringLiteral))</i>)
11N/A *
11N/A * <tr><td><i>value</i> <b>NOT LIKE</b> <i>stringLiteral</i>
11N/A * <td>{@link Query#not Query.not}({@link Query#match Query.match}(<i>q(value)</i>,
11N/A * <i><a href="#translateWildcards">translateWildcards</a>(q(stringLiteral))</i>))
11N/A *
11N/A * <tr><td><i>value1</i> <b>+</b> <i>value2</i>
11N/A * <td>{@link Query#plus Query.plus}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>-</b> <i>value2</i>
11N/A * <td>{@link Query#minus Query.minus}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>*</b> <i>value2</i>
11N/A * <td>{@link Query#times Query.times}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>value1</i> <b>/</b> <i>value2</i>
11N/A * <td>{@link Query#div Query.div}(<i>q(value1)</i>, <i>q(value2)</i>)
11N/A *
11N/A * <tr><td><i>name</i>
11N/A * <td>{@link Query#attr(String) Query.attr}(<i>q(name)</i>)
11N/A *
11N/A * <tr><td><i>name1<b>#</b>name2</i>
11N/A * <td>{@link Query#attr(String,String) Query.attr}(<i>q(name1)</i>,
11N/A * <i>q(name2)</i>)
11N/A *
11N/A * <tr><td><b>FALSE</b>
11N/A * <td>{@link Query#value(boolean) Query.value}(false)
11N/A *
11N/A * <tr><td><b>TRUE</b>
11N/A * <td>{@link Query#value(boolean) Query.value}(true)
11N/A *
11N/A * <tr><td><i>decimalLiteral</i>
11N/A * <td>{@link Query#value(long) Query.value}(<!--
11N/A * -->{@link Long#valueOf(String) Long.valueOf}(<i>decimalLiteral</i>))
11N/A *
11N/A * <tr><td><i>floatingPointLiteral</i>
11N/A * <td>{@link Query#value(double) Query.value}(<!--
11N/A * -->{@link Double#valueOf(String) Double.valueOf}(<!--
11N/A * --><i>floatingPointLiteral</i>))
11N/A * </table>
11N/A *
11N/A * <p id="translateWildcards">Here, <i>translateWildcards</i> is a function
11N/A * that translates from the SQL notation for wildcards, using {@code %} and
11N/A * {@code _}, to the JMX API notation, using {@code *} and {@code ?}. If the
11N/A * <b>LIKE</b> string already contains {@code *} or {@code ?}, these characters
11N/A * have their literal meanings, and will be quoted in the call to
11N/A * {@link Query#match Query.match}.</p>
11N/A *
0N/A * @since 1.5
0N/A */
0N/A public class Query extends Object {
0N/A
0N/A
0N/A /**
0N/A * A code representing the {@link Query#gt} query. This is chiefly
0N/A * of interest for the serialized form of queries.
0N/A */
0N/A public static final int GT = 0;
0N/A
0N/A /**
0N/A * A code representing the {@link Query#lt} query. This is chiefly
0N/A * of interest for the serialized form of queries.
0N/A */
0N/A public static final int LT = 1;
0N/A
0N/A /**
0N/A * A code representing the {@link Query#geq} query. This is chiefly
0N/A * of interest for the serialized form of queries.
0N/A */
0N/A public static final int GE = 2;
0N/A
0N/A /**
0N/A * A code representing the {@link Query#leq} query. This is chiefly
0N/A * of interest for the serialized form of queries.
0N/A */
0N/A public static final int LE = 3;
0N/A
0N/A /**
0N/A * A code representing the {@link Query#eq} query. This is chiefly
0N/A * of interest for the serialized form of queries.
0N/A */
0N/A public static final int EQ = 4;
0N/A
0N/A
0N/A /**
0N/A * A code representing the {@link Query#plus} expression. This
0N/A * is chiefly of interest for the serialized form of queries.
0N/A */
0N/A public static final int PLUS = 0;
0N/A
0N/A /**
0N/A * A code representing the {@link Query#minus} expression. This
0N/A * is chiefly of interest for the serialized form of queries.
0N/A */
0N/A public static final int MINUS = 1;
0N/A
0N/A /**
0N/A * A code representing the {@link Query#times} expression. This
0N/A * is chiefly of interest for the serialized form of queries.
0N/A */
0N/A public static final int TIMES = 2;
0N/A
0N/A /**
0N/A * A code representing the {@link Query#div} expression. This is
0N/A * chiefly of interest for the serialized form of queries.
0N/A */
0N/A public static final int DIV = 3;
0N/A
0N/A
0N/A /**
0N/A * Basic constructor.
0N/A */
0N/A public Query() {
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a query expression that is the conjunction of two other query
0N/A * expressions.
0N/A *
0N/A * @param q1 A query expression.
0N/A * @param q2 Another query expression.
0N/A *
0N/A * @return The conjunction of the two arguments. The returned object
0N/A * will be serialized as an instance of the non-public class {@link
0N/A * <a href="../../serialized-form.html#javax.management.AndQueryExp">
0N/A * javax.management.AndQueryExp</a>}.
0N/A */
0N/A public static QueryExp and(QueryExp q1, QueryExp q2) {
0N/A return new AndQueryExp(q1, q2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that is the disjunction of two other query
0N/A * expressions.
0N/A *
0N/A * @param q1 A query expression.
0N/A * @param q2 Another query expression.
0N/A *
0N/A * @return The disjunction of the two arguments. The returned object
0N/A * will be serialized as an instance of the non-public class {@link
0N/A * <a href="../../serialized-form.html#javax.management.OrQueryExp">
0N/A * javax.management.OrQueryExp</a>}.
0N/A */
0N/A public static QueryExp or(QueryExp q1, QueryExp q2) {
0N/A return new OrQueryExp(q1, q2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a "greater than" constraint on
0N/A * two values.
0N/A *
0N/A * @param v1 A value expression.
0N/A * @param v2 Another value expression.
0N/A *
0N/A * @return A "greater than" constraint on the arguments. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryRelQueryExp">
0N/A * javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal
0N/A * to {@link #GT}.
0N/A */
0N/A public static QueryExp gt(ValueExp v1, ValueExp v2) {
0N/A return new BinaryRelQueryExp(GT, v1, v2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a "greater than or equal
0N/A * to" constraint on two values.
0N/A *
0N/A * @param v1 A value expression.
0N/A * @param v2 Another value expression.
0N/A *
0N/A * @return A "greater than or equal to" constraint on the
0N/A * arguments. The returned object will be serialized as an
0N/A * instance of the non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryRelQueryExp">
0N/A * javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal
0N/A * to {@link #GE}.
0N/A */
0N/A public static QueryExp geq(ValueExp v1, ValueExp v2) {
0N/A return new BinaryRelQueryExp(GE, v1, v2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a "less than or equal to"
0N/A * constraint on two values.
0N/A *
0N/A * @param v1 A value expression.
0N/A * @param v2 Another value expression.
0N/A *
0N/A * @return A "less than or equal to" constraint on the arguments.
0N/A * The returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryRelQueryExp">
0N/A * javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal
0N/A * to {@link #LE}.
0N/A */
0N/A public static QueryExp leq(ValueExp v1, ValueExp v2) {
0N/A return new BinaryRelQueryExp(LE, v1, v2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a "less than" constraint on
0N/A * two values.
0N/A *
0N/A * @param v1 A value expression.
0N/A * @param v2 Another value expression.
0N/A *
0N/A * @return A "less than" constraint on the arguments. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryRelQueryExp">
0N/A * javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal
0N/A * to {@link #LT}.
0N/A */
0N/A public static QueryExp lt(ValueExp v1, ValueExp v2) {
0N/A return new BinaryRelQueryExp(LT, v1, v2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents an equality constraint on
0N/A * two values.
0N/A *
0N/A * @param v1 A value expression.
0N/A * @param v2 Another value expression.
0N/A *
0N/A * @return A "equal to" constraint on the arguments. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryRelQueryExp">
0N/A * javax.management.BinaryRelQueryExp</a>} with a {@code relOp} equal
0N/A * to {@link #EQ}.
0N/A */
0N/A public static QueryExp eq(ValueExp v1, ValueExp v2) {
0N/A return new BinaryRelQueryExp(EQ, v1, v2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents the constraint that one
0N/A * value is between two other values.
0N/A *
0N/A * @param v1 A value expression that is "between" v2 and v3.
0N/A * @param v2 Value expression that represents a boundary of the constraint.
0N/A * @param v3 Value expression that represents a boundary of the constraint.
0N/A *
0N/A * @return The constraint that v1 lies between v2 and v3. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BetweenQueryExp">
0N/A * javax.management.BetweenQueryExp</a>}.
0N/A */
0N/A public static QueryExp between(ValueExp v1, ValueExp v2, ValueExp v3) {
0N/A return new BetweenQueryExp(v1, v2, v3);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a matching constraint on
0N/A * a string argument. The matching syntax is consistent with file globbing:
0N/A * supports "<code>?</code>", "<code>*</code>", "<code>[</code>",
0N/A * each of which may be escaped with "<code>\</code>";
0N/A * character classes may use "<code>!</code>" for negation and
0N/A * "<code>-</code>" for range.
0N/A * (<code>*</code> for any character sequence,
0N/A * <code>?</code> for a single arbitrary character,
0N/A * <code>[...]</code> for a character sequence).
0N/A * For example: <code>a*b?c</code> would match a string starting
0N/A * with the character <code>a</code>, followed
0N/A * by any number of characters, followed by a <code>b</code>,
0N/A * any single character, and a <code>c</code>.
0N/A *
0N/A * @param a An attribute expression
0N/A * @param s A string value expression representing a matching constraint
0N/A *
0N/A * @return A query expression that represents the matching
0N/A * constraint on the string argument. The returned object will
0N/A * be serialized as an instance of the non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.MatchQueryExp">
0N/A * javax.management.MatchQueryExp</a>}.
0N/A */
0N/A public static QueryExp match(AttributeValueExp a, StringValueExp s) {
0N/A return new MatchQueryExp(a, s);
0N/A }
0N/A
0N/A /**
11N/A * <p>Returns a new attribute expression. See {@link AttributeValueExp}
11N/A * for a detailed description of the semantics of the expression.</p>
0N/A *
0N/A * @param name The name of the attribute.
0N/A *
11N/A * @return An attribute expression for the attribute named {@code name}.
0N/A */
0N/A public static AttributeValueExp attr(String name) {
0N/A return new AttributeValueExp(name);
0N/A }
0N/A
0N/A /**
0N/A * <p>Returns a new qualified attribute expression.</p>
0N/A *
0N/A * <p>Evaluating this expression for a given
0N/A * <code>objectName</code> includes performing {@link
0N/A * MBeanServer#getObjectInstance
0N/A * MBeanServer.getObjectInstance(objectName)} and {@link
0N/A * MBeanServer#getAttribute MBeanServer.getAttribute(objectName,
0N/A * name)}.</p>
0N/A *
0N/A * @param className The name of the class possessing the attribute.
0N/A * @param name The name of the attribute.
0N/A *
0N/A * @return An attribute expression for the attribute named name.
0N/A * The returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.QualifiedAttributeValueExp">
0N/A * javax.management.QualifiedAttributeValueExp</a>}.
0N/A */
0N/A public static AttributeValueExp attr(String className, String name) {
0N/A return new QualifiedAttributeValueExp(className, name);
0N/A }
0N/A
0N/A /**
0N/A * <p>Returns a new class attribute expression which can be used in any
0N/A * Query call that expects a ValueExp.</p>
0N/A *
0N/A * <p>Evaluating this expression for a given
0N/A * <code>objectName</code> includes performing {@link
0N/A * MBeanServer#getObjectInstance
0N/A * MBeanServer.getObjectInstance(objectName)}.</p>
0N/A *
0N/A * @return A class attribute expression. The returned object
0N/A * will be serialized as an instance of the non-public class
0N/A * {@link <a
0N/A * href="../../serialized-form.html#javax.management.ClassAttributeValueExp">
0N/A * javax.management.ClassAttributeValueExp</a>}.
0N/A */
0N/A public static AttributeValueExp classattr() {
0N/A return new ClassAttributeValueExp();
0N/A }
0N/A
0N/A /**
0N/A * Returns a constraint that is the negation of its argument.
0N/A *
0N/A * @param queryExp The constraint to negate.
0N/A *
0N/A * @return A negated constraint. The returned object will be
0N/A * serialized as an instance of the non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.NotQueryExp">
0N/A * javax.management.NotQueryExp</a>}.
0N/A */
0N/A public static QueryExp not(QueryExp queryExp) {
0N/A return new NotQueryExp(queryExp);
0N/A }
0N/A
0N/A /**
0N/A * Returns an expression constraining a value to be one of an explicit list.
0N/A *
0N/A * @param val A value to be constrained.
0N/A * @param valueList An array of ValueExps.
0N/A *
0N/A * @return A QueryExp that represents the constraint. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.InQueryExp">
0N/A * javax.management.InQueryExp</a>}.
0N/A */
0N/A public static QueryExp in(ValueExp val, ValueExp valueList[]) {
0N/A return new InQueryExp(val, valueList);
0N/A }
0N/A
0N/A /**
0N/A * Returns a new string expression.
0N/A *
0N/A * @param val The string value.
0N/A *
0N/A * @return A ValueExp object containing the string argument.
0N/A */
0N/A public static StringValueExp value(String val) {
0N/A return new StringValueExp(val);
0N/A }
0N/A
0N/A /**
0N/A * Returns a numeric value expression that can be used in any Query call
0N/A * that expects a ValueExp.
0N/A *
0N/A * @param val An instance of Number.
0N/A *
0N/A * @return A ValueExp object containing the argument. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.NumericValueExp">
0N/A * javax.management.NumericValueExp</a>}.
0N/A */
0N/A public static ValueExp value(Number val) {
0N/A return new NumericValueExp(val);
0N/A }
0N/A
0N/A /**
0N/A * Returns a numeric value expression that can be used in any Query call
0N/A * that expects a ValueExp.
0N/A *
0N/A * @param val An int value.
0N/A *
0N/A * @return A ValueExp object containing the argument. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.NumericValueExp">
0N/A * javax.management.NumericValueExp</a>}.
0N/A */
0N/A public static ValueExp value(int val) {
0N/A return new NumericValueExp((long) val);
0N/A }
0N/A
0N/A /**
0N/A * Returns a numeric value expression that can be used in any Query call
0N/A * that expects a ValueExp.
0N/A *
0N/A * @param val A long value.
0N/A *
0N/A * @return A ValueExp object containing the argument. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.NumericValueExp">
0N/A * javax.management.NumericValueExp</a>}.
0N/A */
0N/A public static ValueExp value(long val) {
0N/A return new NumericValueExp(val);
0N/A }
0N/A
0N/A /**
0N/A * Returns a numeric value expression that can be used in any Query call
0N/A * that expects a ValueExp.
0N/A *
0N/A * @param val A float value.
0N/A *
0N/A * @return A ValueExp object containing the argument. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.NumericValueExp">
0N/A * javax.management.NumericValueExp</a>}.
0N/A */
0N/A public static ValueExp value(float val) {
0N/A return new NumericValueExp((double) val);
0N/A }
0N/A
0N/A /**
0N/A * Returns a numeric value expression that can be used in any Query call
0N/A * that expects a ValueExp.
0N/A *
0N/A * @param val A double value.
0N/A *
0N/A * @return A ValueExp object containing the argument. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.NumericValueExp">
0N/A * javax.management.NumericValueExp</a>}.
0N/A */
0N/A public static ValueExp value(double val) {
0N/A return new NumericValueExp(val);
0N/A }
0N/A
0N/A /**
0N/A * Returns a boolean value expression that can be used in any Query call
0N/A * that expects a ValueExp.
0N/A *
0N/A * @param val A boolean value.
0N/A *
0N/A * @return A ValueExp object containing the argument. The
0N/A * returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BooleanValueExp">
0N/A * javax.management.BooleanValueExp</a>}.
0N/A */
0N/A public static ValueExp value(boolean val) {
0N/A return new BooleanValueExp(val);
0N/A }
0N/A
0N/A /**
0N/A * Returns a binary expression representing the sum of two numeric values,
0N/A * or the concatenation of two string values.
0N/A *
0N/A * @param value1 The first '+' operand.
0N/A * @param value2 The second '+' operand.
0N/A *
0N/A * @return A ValueExp representing the sum or concatenation of
0N/A * the two arguments. The returned object will be serialized as
0N/A * an instance of the non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryOpValueExp">
0N/A * javax.management.BinaryOpValueExp</a>} with an {@code op} equal to
0N/A * {@link #PLUS}.
0N/A */
0N/A public static ValueExp plus(ValueExp value1, ValueExp value2) {
0N/A return new BinaryOpValueExp(PLUS, value1, value2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a binary expression representing the product of two numeric values.
0N/A *
0N/A *
0N/A * @param value1 The first '*' operand.
0N/A * @param value2 The second '*' operand.
0N/A *
0N/A * @return A ValueExp representing the product. The returned
0N/A * object will be serialized as an instance of the non-public
0N/A * class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryOpValueExp">
0N/A * javax.management.BinaryOpValueExp</a>} with an {@code op} equal to
0N/A * {@link #TIMES}.
0N/A */
0N/A public static ValueExp times(ValueExp value1,ValueExp value2) {
0N/A return new BinaryOpValueExp(TIMES, value1, value2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a binary expression representing the difference between two numeric
0N/A * values.
0N/A *
0N/A * @param value1 The first '-' operand.
0N/A * @param value2 The second '-' operand.
0N/A *
0N/A * @return A ValueExp representing the difference between two
0N/A * arguments. The returned object will be serialized as an
0N/A * instance of the non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryOpValueExp">
0N/A * javax.management.BinaryOpValueExp</a>} with an {@code op} equal to
0N/A * {@link #MINUS}.
0N/A */
0N/A public static ValueExp minus(ValueExp value1, ValueExp value2) {
0N/A return new BinaryOpValueExp(MINUS, value1, value2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a binary expression representing the quotient of two numeric
0N/A * values.
0N/A *
0N/A * @param value1 The first '/' operand.
0N/A * @param value2 The second '/' operand.
0N/A *
0N/A * @return A ValueExp representing the quotient of two arguments.
0N/A * The returned object will be serialized as an instance of the
0N/A * non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.BinaryOpValueExp">
0N/A * javax.management.BinaryOpValueExp</a>} with an {@code op} equal to
0N/A * {@link #DIV}.
0N/A */
0N/A public static ValueExp div(ValueExp value1, ValueExp value2) {
0N/A return new BinaryOpValueExp(DIV, value1, value2);
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a matching constraint on
0N/A * a string argument. The value must start with the given literal string
0N/A * value.
0N/A *
0N/A * @param a An attribute expression.
0N/A * @param s A string value expression representing the beginning of the
0N/A * string value.
0N/A *
0N/A * @return The constraint that a matches s. The returned object
0N/A * will be serialized as an instance of the non-public class
0N/A * {@link <a
0N/A * href="../../serialized-form.html#javax.management.MatchQueryExp">
0N/A * javax.management.MatchQueryExp</a>}.
0N/A */
0N/A public static QueryExp initialSubString(AttributeValueExp a, StringValueExp s) {
0N/A return new MatchQueryExp(a,
0N/A new StringValueExp(escapeString(s.getValue()) + "*"));
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a matching constraint on
0N/A * a string argument. The value must contain the given literal string
0N/A * value.
0N/A *
0N/A * @param a An attribute expression.
0N/A * @param s A string value expression representing the substring.
0N/A *
0N/A * @return The constraint that a matches s. The returned object
0N/A * will be serialized as an instance of the non-public class
0N/A * {@link <a
0N/A * href="../../serialized-form.html#javax.management.MatchQueryExp">
0N/A * javax.management.MatchQueryExp</a>}.
0N/A */
0N/A public static QueryExp anySubString(AttributeValueExp a, StringValueExp s) {
0N/A return new MatchQueryExp(a,
0N/A new StringValueExp("*" + escapeString(s.getValue()) + "*"));
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents a matching constraint on
0N/A * a string argument. The value must end with the given literal string
0N/A * value.
0N/A *
0N/A * @param a An attribute expression.
0N/A * @param s A string value expression representing the end of the string
0N/A * value.
0N/A *
0N/A * @return The constraint that a matches s. The returned object
0N/A * will be serialized as an instance of the non-public class
0N/A * {@link <a
0N/A * href="../../serialized-form.html#javax.management.MatchQueryExp">
0N/A * javax.management.MatchQueryExp</a>}.
0N/A */
0N/A public static QueryExp finalSubString(AttributeValueExp a, StringValueExp s) {
0N/A return new MatchQueryExp(a,
0N/A new StringValueExp("*" + escapeString(s.getValue())));
0N/A }
0N/A
0N/A /**
0N/A * Returns a query expression that represents an inheritance constraint
0N/A * on an MBean class.
0N/A * <p>Example: to find MBeans that are instances of
0N/A * {@link NotificationBroadcaster}, use
0N/A * {@code Query.isInstanceOf(Query.value(NotificationBroadcaster.class.getName()))}.
0N/A * </p>
0N/A * <p>Evaluating this expression for a given
0N/A * <code>objectName</code> includes performing {@link
0N/A * MBeanServer#isInstanceOf MBeanServer.isInstanceOf(objectName,
0N/A * ((StringValueExp)classNameValue.apply(objectName)).getValue()}.</p>
0N/A *
0N/A * @param classNameValue The {@link StringValueExp} returning the name
0N/A * of the class of which selected MBeans should be instances.
0N/A * @return a query expression that represents an inheritance
0N/A * constraint on an MBean class. The returned object will be
0N/A * serialized as an instance of the non-public class {@link <a
0N/A * href="../../serialized-form.html#javax.management.InstanceOfQueryExp">
0N/A * javax.management.InstanceOfQueryExp</a>}.
0N/A * @since 1.6
0N/A */
0N/A public static QueryExp isInstanceOf(StringValueExp classNameValue) {
0N/A return new InstanceOfQueryExp(classNameValue);
0N/A }
0N/A
0N/A /**
11N/A * <p>Return a string representation of the given query. The string
11N/A * returned by this method can be converted back into an equivalent
11N/A * query using {@link #fromString fromString}.</p>
11N/A *
11N/A * <p>(Two queries are equivalent if they produce the same result in
11N/A * all cases. Equivalent queries are not necessarily identical:
11N/A * for example the queries {@code Query.lt(Query.attr("A"), Query.attr("B"))}
11N/A * and {@code Query.not(Query.ge(Query.attr("A"), Query.attr("B")))} are
11N/A * equivalent but not identical.)</p>
11N/A *
11N/A * <p>The string returned by this method is only guaranteed to be converted
11N/A * back into an equivalent query if {@code query} was constructed, or
11N/A * could have been constructed, using the methods of this class.
11N/A * If you make a custom query {@code myQuery} by implementing
11N/A * {@link QueryExp} yourself then the result of
11N/A * {@code Query.toString(myQuery)} is unspecified.</p>
11N/A *
11N/A * @param query the query to convert. If it is null, the result will
11N/A * also be null.
11N/A * @return the string representation of the query, or null if the
11N/A * query is null.
11N/A *
11N/A * @since 1.7
11N/A */
11N/A public static String toString(QueryExp query) {
11N/A if (query == null)
11N/A return null;
11N/A
11N/A if (query instanceof ToQueryString)
11N/A return ((ToQueryString) query).toQueryString();
11N/A
11N/A return query.toString();
11N/A }
11N/A
11N/A /**
11N/A * <p>Produce a query from the given string. The query returned
11N/A * by this method can be converted back into a string using
11N/A * {@link #toString(QueryExp) toString}. The resultant string will
11N/A * not necessarily be equal to {@code s}.</p>
11N/A *
11N/A * @param s the string to convert.
11N/A *
11N/A * @return a {@code QueryExp} derived by parsing the string, or
11N/A * null if the string is null.
11N/A *
11N/A * @throws IllegalArgumentException if the string is not a valid
11N/A * query string.
11N/A *
11N/A * @since 1.7
11N/A */
11N/A public static QueryExp fromString(String s) {
11N/A if (s == null)
11N/A return null;
11N/A return new QueryParser(s).parseQuery();
11N/A }
11N/A
11N/A /**
0N/A * Utility method to escape strings used with
0N/A * Query.{initial|any|final}SubString() methods.
0N/A */
0N/A private static String escapeString(String s) {
0N/A if (s == null)
0N/A return null;
0N/A s = s.replace("\\", "\\\\");
0N/A s = s.replace("*", "\\*");
0N/A s = s.replace("?", "\\?");
0N/A s = s.replace("[", "\\[");
0N/A return s;
0N/A }
0N/A }