001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package javax.management;
010:
011: /**
012: * Factory class for constructing query expressions.
013: *
014: * @version $Revision: 1.9 $
015: */
016: public class Query {
017: public static final int GT = 0;
018: public static final int LT = 1;
019: public static final int GE = 2;
020: public static final int LE = 3;
021: public static final int EQ = 4;
022:
023: public static final int PLUS = 0;
024: public static final int MINUS = 1;
025: public static final int TIMES = 2;
026: public static final int DIV = 3;
027:
028: /**
029: * Returns a query expression for the result of the NOT operation on the given expression.
030: */
031: public static QueryExp not(QueryExp queryExp) {
032: return new NotQueryExp(queryExp);
033: }
034:
035: /**
036: * Returns a query expression for the result of the AND operation on the two given expressions.
037: */
038: public static QueryExp and(QueryExp q1, QueryExp q2) {
039: return new AndQueryExp(q1, q2);
040: }
041:
042: /**
043: * Returns a query expression for the result of the OR operation on the two given expressions.
044: */
045: public static QueryExp or(QueryExp q1, QueryExp q2) {
046: return new OrQueryExp(q1, q2);
047: }
048:
049: /**
050: * Returns a query expression for the result of <code>v1</code> GREATER-THAN <code>v2</code>.
051: */
052: public static QueryExp gt(ValueExp v1, ValueExp v2) {
053: return new BinaryRelQueryExp(GT, v1, v2);
054: }
055:
056: /**
057: * Returns a query expression for the result of <code>v1</code> GREATER-THAN-OR-EQUAL <code>v2</code>.
058: */
059: public static QueryExp geq(ValueExp v1, ValueExp v2) {
060: return new BinaryRelQueryExp(GE, v1, v2);
061: }
062:
063: /**
064: * Returns a query expression for the result of <code>v1</code> LESS-THAN-OR-EQUAL <code>v2</code>.
065: */
066: public static QueryExp leq(ValueExp v1, ValueExp v2) {
067: return new BinaryRelQueryExp(LE, v1, v2);
068: }
069:
070: /**
071: * Returns a query expression for the result of <code>v1</code> LESS-THAN <code>v2</code>.
072: */
073: public static QueryExp lt(ValueExp v1, ValueExp v2) {
074: return new BinaryRelQueryExp(LT, v1, v2);
075: }
076:
077: /**
078: * Returns a query expression for the result of <code>v1</code> EQUAL <code>v2</code>.
079: */
080: public static QueryExp eq(ValueExp v1, ValueExp v2) {
081: return new BinaryRelQueryExp(EQ, v1, v2);
082: }
083:
084: /**
085: * Returns a query expression for the result of <code>v1</code> LESS-THAN-OR-EQUAL <code>v2</code> LESS-THAN-OR-EQUAL <code>v3</code>
086: */
087: public static QueryExp between(ValueExp v1, ValueExp v2, ValueExp v3) {
088: return new BetweenQueryExp(v1, v2, v3);
089: }
090:
091: /**
092: * Returns a query expression for the result of <code>val</code> being present as one element of the given array.
093: */
094: public static QueryExp in(ValueExp val, ValueExp valueList[]) {
095: return new InQueryExp(val, valueList);
096: }
097:
098: /**
099: * Returns the expression value that represent the value of an attribute of a generic MBean.
100: */
101: public static AttributeValueExp attr(String name) {
102: return new AttributeValueExp(name);
103: }
104:
105: /**
106: * Returns the expression value that represent the value of an attribute of an MBean of the specified class.
107: */
108: public static AttributeValueExp attr(String className, String name) {
109: return new QualifiedAttributeValueExp(className, name);
110: }
111:
112: /**
113: * Returns the expression value that represent the class name of an MBean.
114: */
115: public static AttributeValueExp classattr() {
116: return new ClassAttributeValueExp();
117: }
118:
119: /**
120: * Returns the expression value that represent the given string.
121: */
122: public static StringValueExp value(String val) {
123: return new StringValueExp(val);
124: }
125:
126: /**
127: * Returns the expression value that represent the given number.
128: */
129: public static ValueExp value(Number val) {
130: return new NumericValueExp(val);
131: }
132:
133: /**
134: * Returns the expression value that represent the given number.
135: */
136: public static ValueExp value(int val) {
137: return value(new Integer(val));
138: }
139:
140: /**
141: * Returns the expression value that represent the given number.
142: */
143: public static ValueExp value(long val) {
144: return value(new Long(val));
145: }
146:
147: /**
148: * Returns the expression value that represent the given number.
149: */
150: public static ValueExp value(float val) {
151: return value(new Float(val));
152: }
153:
154: /**
155: * Returns the expression value that represent the given number.
156: */
157: public static ValueExp value(double val) {
158: return value(new Double(val));
159: }
160:
161: /**
162: * Returns the expression value that represent the given boolean.
163: */
164: public static ValueExp value(boolean val) {
165: return new BooleanValueExp(val);
166: }
167:
168: /**
169: * Returns a expression value for the result of <code>value1</code> PLUS <code>value2</code>
170: */
171: public static ValueExp plus(ValueExp value1, ValueExp value2) {
172: return new BinaryOpValueExp(PLUS, value1, value2);
173: }
174:
175: /**
176: * Returns a expression value for the result of <code>value1</code> MINUS <code>value2</code>
177: */
178: public static ValueExp minus(ValueExp value1, ValueExp value2) {
179: return new BinaryOpValueExp(MINUS, value1, value2);
180: }
181:
182: /**
183: * Returns a expression value for the result of <code>value1</code> TIMES <code>value2</code>
184: */
185: public static ValueExp times(ValueExp value1, ValueExp value2) {
186: return new BinaryOpValueExp(TIMES, value1, value2);
187: }
188:
189: /**
190: * Returns a expression value for the result of <code>value1</code> DIVIDED <code>value2</code>
191: */
192: public static ValueExp div(ValueExp value1, ValueExp value2) {
193: return new BinaryOpValueExp(DIV, value1, value2);
194: }
195:
196: /**
197: * Returns a query expression for the result of the wildcard match between the given attribute value and the string pattern.
198: */
199: public static QueryExp match(AttributeValueExp a, StringValueExp s) {
200: return new MatchQueryExp(a, s);
201: }
202:
203: /**
204: * Returns a query expression for the result of the match, as initial string, between the given attribute value and the string pattern.
205: */
206: public static QueryExp initialSubString(AttributeValueExp a,
207: StringValueExp s) {
208: return new MatchQueryExp(a, new StringValueExp(s.getValue()
209: + "*"));
210: }
211:
212: /**
213: * Returns a query expression for the result of the match, as contained string, between the given attribute value and the string pattern.
214: */
215: public static QueryExp anySubString(AttributeValueExp a,
216: StringValueExp s) {
217: return new MatchQueryExp(a, new StringValueExp("*"
218: + s.getValue() + "*"));
219: }
220:
221: /**
222: * Returns a query expression for the result of the match, as final string, between the given attribute value and the string pattern.
223: */
224: public static QueryExp finalSubString(AttributeValueExp a,
225: StringValueExp s) {
226: return new MatchQueryExp(a, new StringValueExp("*"
227: + s.getValue()));
228: }
229: }
|