/* * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * * * * * * * * * * * * * * * * * * * * */ package javax.management; /** *
Constructs query object constraints.
* *The MBean Server can be queried for MBeans that meet a particular * condition, using its {@link MBeanServer#queryNames queryNames} or * {@link MBeanServer#queryMBeans queryMBeans} method. The {@link QueryExp} * parameter to the method can be any implementation of the interface * {@code QueryExp}, but it is usually best to obtain the {@code QueryExp} * value by calling the static methods in this class. This is particularly * true when querying a remote MBean Server: a custom implementation of the * {@code QueryExp} interface might not be present in the remote MBean Server, * but the methods in this class return only standard classes that are * part of the JMX implementation.
* *As an example, suppose you wanted to find all MBeans where the {@code * Enabled} attribute is {@code true} and the {@code Owner} attribute is {@code * "Duke"}. Here is how you could construct the appropriate {@code QueryExp} by * chaining together method calls:
* *
* QueryExp query =
* Query.and(Query.eq(Query.attr("Enabled"), Query.value(true)),
* Query.eq(Query.attr("Owner"), Query.value("Duke")));
*
*
* @since 1.5
*/
public class Query extends Object {
/**
* A code representing the {@link Query#gt} query. This is chiefly
* of interest for the serialized form of queries.
*/
public static final int GT = 0;
/**
* A code representing the {@link Query#lt} query. This is chiefly
* of interest for the serialized form of queries.
*/
public static final int LT = 1;
/**
* A code representing the {@link Query#geq} query. This is chiefly
* of interest for the serialized form of queries.
*/
public static final int GE = 2;
/**
* A code representing the {@link Query#leq} query. This is chiefly
* of interest for the serialized form of queries.
*/
public static final int LE = 3;
/**
* A code representing the {@link Query#eq} query. This is chiefly
* of interest for the serialized form of queries.
*/
public static final int EQ = 4;
/**
* A code representing the {@link Query#plus} expression. This
* is chiefly of interest for the serialized form of queries.
*/
public static final int PLUS = 0;
/**
* A code representing the {@link Query#minus} expression. This
* is chiefly of interest for the serialized form of queries.
*/
public static final int MINUS = 1;
/**
* A code representing the {@link Query#times} expression. This
* is chiefly of interest for the serialized form of queries.
*/
public static final int TIMES = 2;
/**
* A code representing the {@link Query#div} expression. This is
* chiefly of interest for the serialized form of queries.
*/
public static final int DIV = 3;
/**
* Basic constructor.
*/
public Query() {
}
/**
* Returns a query expression that is the conjunction of two other query
* expressions.
*
* @param q1 A query expression.
* @param q2 Another query expression.
*
* @return The conjunction of the two arguments. The returned object
* will be serialized as an instance of the non-public class {@link
*
* javax.management.AndQueryExp}.
*/
public static QueryExp and(QueryExp q1, QueryExp q2) {
return new AndQueryExp(q1, q2);
}
/**
* Returns a query expression that is the disjunction of two other query
* expressions.
*
* @param q1 A query expression.
* @param q2 Another query expression.
*
* @return The disjunction of the two arguments. The returned object
* will be serialized as an instance of the non-public class {@link
*
* javax.management.OrQueryExp}.
*/
public static QueryExp or(QueryExp q1, QueryExp q2) {
return new OrQueryExp(q1, q2);
}
/**
* Returns a query expression that represents a "greater than" constraint on
* two values.
*
* @param v1 A value expression.
* @param v2 Another value expression.
*
* @return A "greater than" constraint on the arguments. The
* returned object will be serialized as an instance of the
* non-public class {@link
* javax.management.BinaryRelQueryExp} with a {@code relOp} equal
* to {@link #GT}.
*/
public static QueryExp gt(ValueExp v1, ValueExp v2) {
return new BinaryRelQueryExp(GT, v1, v2);
}
/**
* Returns a query expression that represents a "greater than or equal
* to" constraint on two values.
*
* @param v1 A value expression.
* @param v2 Another value expression.
*
* @return A "greater than or equal to" constraint on the
* arguments. The returned object will be serialized as an
* instance of the non-public class {@link
* javax.management.BinaryRelQueryExp} with a {@code relOp} equal
* to {@link #GE}.
*/
public static QueryExp geq(ValueExp v1, ValueExp v2) {
return new BinaryRelQueryExp(GE, v1, v2);
}
/**
* Returns a query expression that represents a "less than or equal to"
* constraint on two values.
*
* @param v1 A value expression.
* @param v2 Another value expression.
*
* @return A "less than or equal to" constraint on the arguments.
* The returned object will be serialized as an instance of the
* non-public class {@link
* javax.management.BinaryRelQueryExp} with a {@code relOp} equal
* to {@link #LE}.
*/
public static QueryExp leq(ValueExp v1, ValueExp v2) {
return new BinaryRelQueryExp(LE, v1, v2);
}
/**
* Returns a query expression that represents a "less than" constraint on
* two values.
*
* @param v1 A value expression.
* @param v2 Another value expression.
*
* @return A "less than" constraint on the arguments. The
* returned object will be serialized as an instance of the
* non-public class {@link
* javax.management.BinaryRelQueryExp} with a {@code relOp} equal
* to {@link #LT}.
*/
public static QueryExp lt(ValueExp v1, ValueExp v2) {
return new BinaryRelQueryExp(LT, v1, v2);
}
/**
* Returns a query expression that represents an equality constraint on
* two values.
*
* @param v1 A value expression.
* @param v2 Another value expression.
*
* @return A "equal to" constraint on the arguments. The
* returned object will be serialized as an instance of the
* non-public class {@link
* javax.management.BinaryRelQueryExp} with a {@code relOp} equal
* to {@link #EQ}.
*/
public static QueryExp eq(ValueExp v1, ValueExp v2) {
return new BinaryRelQueryExp(EQ, v1, v2);
}
/**
* Returns a query expression that represents the constraint that one
* value is between two other values.
*
* @param v1 A value expression that is "between" v2 and v3.
* @param v2 Value expression that represents a boundary of the constraint.
* @param v3 Value expression that represents a boundary of the constraint.
*
* @return The constraint that v1 lies between v2 and v3. The
* returned object will be serialized as an instance of the
* non-public class {@link
* javax.management.BetweenQueryExp}.
*/
public static QueryExp between(ValueExp v1, ValueExp v2, ValueExp v3) {
return new BetweenQueryExp(v1, v2, v3);
}
/**
* Returns a query expression that represents a matching constraint on
* a string argument. The matching syntax is consistent with file globbing:
* supports "?", "*", "[",
* each of which may be escaped with "\";
* character classes may use "!" for negation and
* "-" for range.
* (* for any character sequence,
* ? for a single arbitrary character,
* [...] for a character sequence).
* For example: a*b?c would match a string starting
* with the character a, followed
* by any number of characters, followed by a b,
* any single character, and a c.
*
* @param a An attribute expression
* @param s A string value expression representing a matching constraint
*
* @return A query expression that represents the matching
* constraint on the string argument. The returned object will
* be serialized as an instance of the non-public class {@link
* javax.management.MatchQueryExp}.
*/
public static QueryExp match(AttributeValueExp a, StringValueExp s) {
return new MatchQueryExp(a, s);
}
/**
* Returns a new attribute expression. See {@link AttributeValueExp} * for a detailed description of the semantics of the expression.
* *Evaluating this expression for a given
* objectName includes performing {@link
* MBeanServer#getAttribute MBeanServer.getAttribute(objectName,
* name)}.
Returns a new qualified attribute expression.
* *Evaluating this expression for a given
* objectName includes performing {@link
* MBeanServer#getObjectInstance
* MBeanServer.getObjectInstance(objectName)} and {@link
* MBeanServer#getAttribute MBeanServer.getAttribute(objectName,
* name)}.
Returns a new class attribute expression which can be used in any * Query call that expects a ValueExp.
* *Evaluating this expression for a given
* objectName includes performing {@link
* MBeanServer#getObjectInstance
* MBeanServer.getObjectInstance(objectName)}.
Example: to find MBeans that are instances of * {@link NotificationBroadcaster}, use * {@code Query.isInstanceOf(Query.value(NotificationBroadcaster.class.getName()))}. *
*Evaluating this expression for a given
* objectName includes performing {@link
* MBeanServer#isInstanceOf MBeanServer.isInstanceOf(objectName,
* ((StringValueExp)classNameValue.apply(objectName)).getValue()}.