PageRenderTime 61ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/classpath/javax/management/Query.java

https://bitbucket.org/thelearninglabs/uclinux-distro-tll-public
Java | 1901 lines | 776 code | 134 blank | 991 comment | 155 complexity | e2bf3c1ef969b13c8ffa18f03aa73a04 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, Unlicense, GPL-2.0, GPL-3.0, CC-BY-SA-3.0, AGPL-1.0, ISC, MIT, 0BSD, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /* Query.java -- Static methods for query construction.
  2. Copyright (C) 2007 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.management;
  32. /**
  33. * Provides static methods for constructing queries. Queries
  34. * may be used to list and enumerate management beans, via
  35. * the {@link MBeanServer}. By using the methods in this class,
  36. * complex queries can be created from their more basic
  37. * components.
  38. *
  39. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  40. * @since 1.5
  41. */
  42. public class Query
  43. {
  44. /**
  45. * A code representing the {@link #plus(ValueExp, ValueExp)
  46. * query to be used in serialization.
  47. */
  48. public static final int PLUS = 0;
  49. /**
  50. * A code representing the {@link #minus(ValueExp, ValueExp)
  51. * query to be used in serialization.
  52. */
  53. public static final int MINUS = 1;
  54. /**
  55. * A code representing the {@link #times(ValueExp, ValueExp)
  56. * query to be used in serialization.
  57. */
  58. public static final int TIMES = 2;
  59. /**
  60. * A code representing the {@link #div(ValueExp, ValueExp)
  61. * query to be used in serialization.
  62. */
  63. public static final int DIV = 3;
  64. /**
  65. * A code representing the {@link #gt(ValueExp, ValueExp)
  66. * query to be used in serialization.
  67. */
  68. public static final int GT = 0;
  69. /**
  70. * A code representing the {@link #lt(ValueExp, ValueExp)
  71. * query to be used in serialization.
  72. */
  73. public static final int LT = 1;
  74. /**
  75. * A code representing the {@link #ge(ValueExp, ValueExp)
  76. * query to be used in serialization.
  77. */
  78. public static final int GE = 2;
  79. /**
  80. * A code representing the {@link #le(ValueExp, ValueExp)
  81. * query to be used in serialization.
  82. */
  83. public static final int LE = 3;
  84. /**
  85. * A code representing the {@link #eq(ValueExp, ValueExp)
  86. * query to be used in serialization.
  87. */
  88. public static final int EQ = 4;
  89. /**
  90. * Returns a query expression formed from the conjunction
  91. * of the two supplied query expressions.
  92. *
  93. * @param q1 the first query expression.
  94. * @param q2 the second query expression.
  95. * @return a query expression representing q1 && q2. This
  96. * will be serialized as the non-public class
  97. * {@link AndQueryExp}.
  98. */
  99. public static QueryExp and(QueryExp q1, QueryExp q2)
  100. {
  101. return new AndQueryExp(q1, q2);
  102. }
  103. /**
  104. * Returns a query expression which checks that an
  105. * attribute value held by the specified
  106. * {@link AttributeValueExp} contains the string
  107. * specified by the given {@link StringValueExp}.
  108. *
  109. * @param attrib the attribute to match.
  110. * @param string the substring to find.
  111. * @return a query expression representing
  112. * <code>attrib.matches("*" + string + "*")</code>.
  113. * This will be serialized as the non-public class
  114. * {@link MatchQueryExp}.
  115. */
  116. public static QueryExp anySubString(AttributeValueExp attrib,
  117. StringValueExp string)
  118. {
  119. return new MatchQueryExp(attrib, "*" + string.getValue() + "*");
  120. }
  121. /**
  122. * Returns a value expression for the value of the
  123. * named attribute. Evaluating this using an
  124. * {@link ObjectName} involves an underlying call
  125. * to {@link MBeanServer#getAttribute(ObjectName,String)}.
  126. *
  127. * @param name the name of the attribute.
  128. * @return a value expression which returns the value
  129. * of the named attribute when applied.
  130. */
  131. public static AttributeValueExp attr(String name)
  132. {
  133. return new AttributeValueExp(name);
  134. }
  135. /**
  136. * Returns a value expression for the value of the
  137. * named attribute from the specified class. Evaluating
  138. * this using an {@link ObjectName} involves an underlying call
  139. * to both {@link MBeanServer#getObjectInstance(ObjectName)} and
  140. * {@link MBeanServer#getAttribute(ObjectName,String)}.
  141. *
  142. * @param className the class containing the attribute.
  143. * @param name the name of the attribute.
  144. * @return a value expression which returns the value
  145. * of the named attribute when applied.
  146. * This will be serialized as the non-public class
  147. * {@link QualifiedAttributeValueExp}.
  148. */
  149. public static AttributeValueExp attr(String className,
  150. String name)
  151. {
  152. return new QualifiedAttributeValueExp(className, name);
  153. }
  154. /**
  155. * Returns a query expression representing the constraint
  156. * that the value, <code>v1</code>, lies between <code>v2</code>
  157. * and <code>v3</code>.
  158. *
  159. * @param v1 the value to compare against the boundaries.
  160. * @param v2 the lower boundary.
  161. * @param v3 the upper boundary.
  162. * @return a query expression representing a comparison
  163. * of <code>v1</code> against <code>v2</code>
  164. * and <code>v3</code>. It returns true if
  165. * <code>v2 <= v1 <= v3</code>. This
  166. * will be serialized as the non-public class
  167. * {@link BetweenQueryExp}.
  168. */
  169. public static QueryExp between(ValueExp v1, ValueExp v2,
  170. ValueExp v3)
  171. {
  172. return new BetweenQueryExp(v1, v2, v3);
  173. }
  174. /**
  175. * Returns a value expression which evaluates to the name of
  176. * the class of the bean when applied. Associating the expression
  177. * with an {@link ObjectName} involves an underlying call
  178. * to both {@link MBeanServer#getObjectInstance(ObjectName)}
  179. * to obtain this information.
  180. *
  181. * @return a value expression which returns the class name
  182. * of the bean to which it is applied.
  183. * This will be serialized as the non-public class
  184. * {@link ClassAttributeValueExp}.
  185. */
  186. public static AttributeValueExp classattr()
  187. {
  188. return new ClassAttributeValueExp();
  189. }
  190. /**
  191. * Returns a value expression which evaluates to the result of
  192. * dividing <code>v1</code> by <code>v2</code>.
  193. *
  194. * @param v1 the left-hand operand.
  195. * @param v2 the right-hand operand.
  196. * @return a value expression which returns the result of
  197. * the division when applied. This will be serialized
  198. * as the non-public class {@link BinaryOpValueExp}
  199. * with an operation of {@link #DIV}.
  200. */
  201. public static ValueExp div(ValueExp v1, ValueExp v2)
  202. {
  203. return new BinaryOpValueExp(DIV, v1, v2);
  204. }
  205. /**
  206. * Returns a query expression which evaluates to the result of
  207. * comparing <code>v1</code> to <code>v2</code> for equality.
  208. *
  209. * @param v1 the left-hand operand.
  210. * @param v2 the right-hand operand.
  211. * @return a value expression which returns the result of
  212. * the comparison when applied. This will be serialized
  213. * as the non-public class {@link BinaryRelQueryExp}
  214. * with an operation of {@link #EQ}.
  215. */
  216. public static QueryExp eq(ValueExp v1, ValueExp v2)
  217. {
  218. return new BinaryRelQueryExp(EQ, v1, v2);
  219. }
  220. /**
  221. * Returns a query expression which checks that an
  222. * attribute value held by the specified
  223. * {@link AttributeValueExp} ends with the string
  224. * specified by the given {@link StringValueExp}.
  225. *
  226. * @param attrib the attribute to match.
  227. * @param string the substring to find.
  228. * @return a query expression representing
  229. * <code>attrib.matches("*" + string)</code>.
  230. * This will be serialized as the non-public class
  231. * {@link MatchQueryExp}.
  232. */
  233. public static QueryExp finalSubString(AttributeValueExp attrib,
  234. StringValueExp string)
  235. {
  236. return new MatchQueryExp(attrib, "*" + string.getValue());
  237. }
  238. /**
  239. * Returns a query expression which evaluates to the result of
  240. * comparing <code>v1</code> to <code>v2</code> to see if
  241. * <code>v1</code> is greater than or equal to <code>v2</code>.
  242. *
  243. * @param v1 the left-hand operand.
  244. * @param v2 the right-hand operand.
  245. * @return a value expression which returns the result of
  246. * the comparison when applied. This will be serialized
  247. * as the non-public class {@link BinaryRelQueryExp}
  248. * with an operation of {@link #GE}.
  249. */
  250. public static QueryExp geq(ValueExp v1, ValueExp v2)
  251. {
  252. return new BinaryRelQueryExp(GE, v1, v2);
  253. }
  254. /**
  255. * Returns a query expression which evaluates to the result of
  256. * comparing <code>v1</code> to <code>v2</code> to see if
  257. * <code>v1</code> is greater than <code>v2</code>.
  258. *
  259. * @param v1 the left-hand operand.
  260. * @param v2 the right-hand operand.
  261. * @return a value expression which returns the result of
  262. * the comparison when applied. This will be serialized
  263. * as the non-public class {@link BinaryRelQueryExp}
  264. * with an operation of {@link #GT}.
  265. */
  266. public static QueryExp gt(ValueExp v1, ValueExp v2)
  267. {
  268. return new BinaryRelQueryExp(GT, v1, v2);
  269. }
  270. /**
  271. * Returns a query expression representing the constraint
  272. * that the value, <code>v</code>, is a member of the
  273. * list, <code>vlist</code>.
  274. *
  275. * @param v the value to look for in the list.
  276. * @param vlist the list of allowed values.
  277. * @return a query expression representing a membership check
  278. * of <code>v</code> against the list, <code>vlist</code>.
  279. * This will be serialized as the non-public class
  280. * {@link InQueryExp}.
  281. */
  282. public static QueryExp in(ValueExp v, ValueExp[] vlist)
  283. {
  284. return new InQueryExp(v, vlist);
  285. }
  286. /**
  287. * Returns a query expression which checks that an
  288. * attribute value held by the specified
  289. * {@link AttributeValueExp} starts with the string
  290. * specified by the given {@link StringValueExp}.
  291. *
  292. * @param attrib the attribute to match.
  293. * @param string the substring to find.
  294. * @return a query expression representing
  295. * <code>attrib.matches(string + "*")</code>.
  296. * This will be serialized as the non-public class
  297. * {@link MatchQueryExp}.
  298. */
  299. public static QueryExp initialSubString(AttributeValueExp attrib,
  300. StringValueExp string)
  301. {
  302. return new MatchQueryExp(attrib, string.getValue() + "*");
  303. }
  304. /**
  305. * Returns a query expression which checks that a
  306. * bean is an instance of the class specified
  307. * by the given {@link StringValueExp}. Associating the
  308. * expression with an {@link ObjectName} involves an underlying
  309. * call to {@link MBeanServer#isInstanceOf(ObjectName, String)}
  310. * using the value of <code>((StringValueExp)
  311. * className.apply(objectName)).getValue()</code> as the
  312. * class name.
  313. *
  314. * @param className the name of the class which the bean
  315. * should be an instance of.
  316. * @return a query expression representing
  317. * the inheritance check. This will be serialized
  318. * as the non-public class {@link InstanceOfQueryExp}.
  319. * @since 1.6
  320. */
  321. public static QueryExp isInstanceOf(StringValueExp className)
  322. {
  323. return new InstanceOfQueryExp(className);
  324. }
  325. /**
  326. * Returns a query expression which evaluates to the result of
  327. * comparing <code>v1</code> to <code>v2</code> to see if
  328. * <code>v1</code> is less than or equal to <code>v2</code>.
  329. *
  330. * @param v1 the left-hand operand.
  331. * @param v2 the right-hand operand.
  332. * @return a value expression which returns the result of
  333. * the comparison when applied. This will be serialized
  334. * as the non-public class {@link BinaryRelQueryExp}
  335. * with an operation of {@link #LE}.
  336. */
  337. public static QueryExp leq(ValueExp v1, ValueExp v2)
  338. {
  339. return new BinaryRelQueryExp(LE, v1, v2);
  340. }
  341. /**
  342. * Returns a query expression which evaluates to the result of
  343. * comparing <code>v1</code> to <code>v2</code> to see if
  344. * <code>v1</code> is less than <code>v2</code>.
  345. *
  346. * @param v1 the left-hand operand.
  347. * @param v2 the right-hand operand.
  348. * @return a value expression which returns the result of
  349. * the comparison when applied. This will be serialized
  350. * as the non-public class {@link BinaryRelQueryExp}
  351. * with an operation of {@link #LT}.
  352. */
  353. public static QueryExp lt(ValueExp v1, ValueExp v2)
  354. {
  355. return new BinaryRelQueryExp(LT, v1, v2);
  356. }
  357. /**
  358. * <p>
  359. * Returns a query expression which checks that an
  360. * attribute value matches the pattern
  361. * specified by the given {@link StringValueExp}.
  362. * The pattern uses file-globbing syntax:
  363. * </p>
  364. * <ul>
  365. * <li>'*' stands for any number of arbitrary characters.</li>
  366. * <li>'?' stands for a single arbitrary characters.</li>
  367. * <li>An expression within '[' and ']' specify a character
  368. * class.</li>
  369. * <ul>
  370. * <li>A range of characters can be specified by separating
  371. * the start and end character with '-'.</li>
  372. * <li>The complement of the class can be obtained by using
  373. * '!' as the first character of the class.</li>
  374. * <li>'?', '*' and '[' can occur freely within the class. '-'
  375. * may occur as the first or last character. '!' may occur
  376. * normally in any position other than the first. ']' may occur
  377. * as the first element of the class.</li>
  378. * </ul>
  379. * <li>'?', '*' and '[' may be escaped using a backslash
  380. * character, '\'.</li>
  381. * </ul>
  382. *
  383. * @param attrib the attribute to match.
  384. * @param string the substring to find.
  385. * @return a query expression representing the result of
  386. * matching the pattern against the evaluated
  387. * value of the attribute. This will be serialized
  388. * as the non-public class {@link MatchQueryExp}.
  389. */
  390. public static QueryExp match(AttributeValueExp attrib,
  391. StringValueExp string)
  392. {
  393. return new MatchQueryExp(attrib, string.getValue());
  394. }
  395. /**
  396. * Returns a value expression which evaluates to the result of
  397. * subtracting <code>v2</code> from <code>v1</code>.
  398. *
  399. * @param v1 the left-hand operand.
  400. * @param v2 the right-hand operand.
  401. * @return a value expression which returns the result of
  402. * the subtraction when applied. This will be serialized
  403. * as the non-public class {@link BinaryOpValueExp}
  404. * with an operation of {@link #MINUS}.
  405. */
  406. public static ValueExp minus(ValueExp v1, ValueExp v2)
  407. {
  408. return new BinaryOpValueExp(MINUS, v1, v2);
  409. }
  410. /**
  411. * Returns a query expression representing the negation
  412. * of the specified query expression.
  413. *
  414. * @param q the query to negate.
  415. * @return a query expression representing the negation of
  416. * <code>q</code>. This will be serialized as the
  417. * non-public class {@link NotQueryExp}.
  418. */
  419. public static QueryExp not(QueryExp q)
  420. {
  421. return new NotQueryExp(q);
  422. }
  423. /**
  424. * Returns a query expression formed from the disjunction
  425. * of the two supplied query expressions.
  426. *
  427. * @param q1 the first query expression.
  428. * @param q2 the second query expression.
  429. * @return a query expression representing q1 || q2. This
  430. * will be serialized as the non-public class
  431. * {@link OrQueryExp}.
  432. */
  433. public static QueryExp or(QueryExp q1, QueryExp q2)
  434. {
  435. return new OrQueryExp(q1, q2);
  436. }
  437. /**
  438. * Returns a value expression which evaluates to the result of
  439. * adding <code>v1</code> to <code>v2</code>.
  440. *
  441. * @param v1 the left-hand operand.
  442. * @param v2 the right-hand operand.
  443. * @return a value expression which returns the result of
  444. * the addition when applied. This will be serialized
  445. * as the non-public class {@link BinaryOpValueExp}
  446. * with an operation of {@link #PLUS}.
  447. */
  448. public static ValueExp plus(ValueExp v1, ValueExp v2)
  449. {
  450. return new BinaryOpValueExp(PLUS, v1, v2);
  451. }
  452. /**
  453. * Returns a value expression which evaluates to the result of
  454. * multiplying <code>v1</code> by <code>v2</code>.
  455. *
  456. * @param v1 the left-hand operand.
  457. * @param v2 the right-hand operand.
  458. * @return a value expression which returns the result of
  459. * the multiplication when applied. This will be serialized
  460. * as the non-public class {@link BinaryOpValueExp}
  461. * with an operation of {@link #TIMES}.
  462. */
  463. public static ValueExp times(ValueExp v1, ValueExp v2)
  464. {
  465. return new BinaryOpValueExp(TIMES, v1, v2);
  466. }
  467. /**
  468. * Returns a value expression wrapping the specified value.
  469. *
  470. * @param val the boolean value to wrap.
  471. * @return a value expression wrapping <code>val</code>. This
  472. * will be serialized as the non-public class
  473. * {@link BooleanValueExp}.
  474. */
  475. public static ValueExp value(boolean val)
  476. {
  477. return new BooleanValueExp(val);
  478. }
  479. /**
  480. * Returns a value expression wrapping the specified value.
  481. *
  482. * @param val the double value to wrap.
  483. * @return a value expression wrapping <code>val</code>. This
  484. * will be serialized as the non-public class
  485. * {@link NumericValueExp}.
  486. */
  487. public static ValueExp value(double val)
  488. {
  489. return new NumericValueExp(val);
  490. }
  491. /**
  492. * Returns a value expression wrapping the specified value.
  493. *
  494. * @param val the float value to wrap.
  495. * @return a value expression wrapping <code>val</code>. This
  496. * will be serialized as the non-public class
  497. * {@link NumericValueExp}.
  498. */
  499. public static ValueExp value(float val)
  500. {
  501. return new NumericValueExp(val);
  502. }
  503. /**
  504. * Returns a value expression wrapping the specified value.
  505. *
  506. * @param val the integer value to wrap.
  507. * @return a value expression wrapping <code>val</code>. This
  508. * will be serialized as the non-public class
  509. * {@link NumericValueExp}.
  510. */
  511. public static ValueExp value(int val)
  512. {
  513. return new NumericValueExp(val);
  514. }
  515. /**
  516. * Returns a value expression wrapping the specified value.
  517. *
  518. * @param val the long value to wrap.
  519. * @return a value expression wrapping <code>val</code>. This
  520. * will be serialized as the non-public class
  521. * {@link NumericValueExp}.
  522. */
  523. public static ValueExp value(long val)
  524. {
  525. return new NumericValueExp(val);
  526. }
  527. /**
  528. * Returns a value expression wrapping the specified value.
  529. *
  530. * @param val the {@link Number} value to wrap.
  531. * @return a value expression wrapping <code>val</code>. This
  532. * will be serialized as the non-public class
  533. * {@link NumericValueExp}.
  534. */
  535. public static ValueExp value(Number val)
  536. {
  537. return new NumericValueExp(val);
  538. }
  539. /**
  540. * Returns a value expression wrapping the specified string.
  541. *
  542. * @param val the {@link String} to wrap.
  543. * @return a {@link StringValueExp} wrapping <code>val</code>.
  544. */
  545. public static StringValueExp value(String val)
  546. {
  547. return new StringValueExp(val);
  548. }
  549. /**
  550. * Representation of the conjunction formed using
  551. * {@link #and(QueryExp, QueryExp).
  552. *
  553. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  554. * @since 1.5
  555. */
  556. private static final class AndQueryExp
  557. extends QueryEval
  558. implements QueryExp
  559. {
  560. /**
  561. * Compatible with JDK 1.6
  562. */
  563. private static final long serialVersionUID = -1081892073854801359L;
  564. /**
  565. * The first operand.
  566. */
  567. private QueryExp exp1;
  568. /**
  569. * The second operand.
  570. */
  571. private QueryExp exp2;
  572. /**
  573. * Constructs a new {@link AndQueryExp} using
  574. * the two specified operands.
  575. *
  576. * @param exp1 the first query expression.
  577. * @param exp2 the second query expression.
  578. */
  579. public AndQueryExp(QueryExp exp1, QueryExp exp2)
  580. {
  581. this.exp1 = exp1;
  582. this.exp2 = exp2;
  583. }
  584. /**
  585. * Returns the conjunction of the two query
  586. * expressions.
  587. *
  588. * @param name the {@link ObjectName} to apply
  589. * the query to.
  590. * @return the conjunction of applying the name
  591. * to both operands.
  592. * @throws BadStringOperationException if an invalid string
  593. * operation is used by
  594. * the query.
  595. * @throws BadBinaryOpValueExpException if an invalid expression
  596. * is used by the query.
  597. * @throws BadAttributeValueExpException if an invalid attribute
  598. * is used by the query.
  599. * @throws InvalidApplicationException if the query is applied
  600. * to the wrong type of bean.
  601. */
  602. public boolean apply(ObjectName name)
  603. throws BadStringOperationException, BadBinaryOpValueExpException,
  604. BadAttributeValueExpException, InvalidApplicationException
  605. {
  606. return exp1.apply(name) && exp2.apply(name);
  607. }
  608. }
  609. /**
  610. * Representation of a query that matches an
  611. * attribute's value against a given pattern.
  612. *
  613. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  614. * @since 1.5
  615. */
  616. private static final class MatchQueryExp
  617. extends QueryEval
  618. implements QueryExp
  619. {
  620. /**
  621. * Compatible with JDK 1.6
  622. */
  623. private static final long serialVersionUID = -7156603696948215014L;
  624. /**
  625. * The attribute to match against.
  626. */
  627. private AttributeValueExp exp;
  628. /**
  629. * The pattern to be matched.
  630. */
  631. private String pattern;
  632. /**
  633. * Constructs a new {@link MatchQueryExp} using
  634. * the specified attribute value and pattern.
  635. *
  636. * @param exp the attribute value expression.
  637. * @param pattern the pattern.
  638. */
  639. public MatchQueryExp(AttributeValueExp exp,
  640. String pattern)
  641. {
  642. this.exp = exp;
  643. this.pattern = pattern;
  644. }
  645. /**
  646. * Returns the result of matching the attribute
  647. * value against the pattern.
  648. *
  649. * @param name the {@link ObjectName} to apply
  650. * the query to.
  651. * @return the result of the match.
  652. * @throws BadStringOperationException if an invalid string
  653. * operation is used by
  654. * the query.
  655. * @throws BadBinaryOpValueExpException if an invalid expression
  656. * is used by the query.
  657. * @throws BadAttributeValueExpException if an invalid attribute
  658. * is used by the query.
  659. * @throws InvalidApplicationException if the query is applied
  660. * to the wrong type of bean.
  661. */
  662. public boolean apply(ObjectName name)
  663. throws BadStringOperationException, BadBinaryOpValueExpException,
  664. BadAttributeValueExpException, InvalidApplicationException
  665. {
  666. String val = ((StringValueExp) exp.apply(name)).getValue();
  667. int valPos = 0;
  668. int fallback = -1;
  669. int fallbackP = -1;
  670. boolean backslash = false;
  671. for (int a = 0; a < pattern.length(); ++a)
  672. {
  673. boolean matched = false;
  674. int next = pattern.codePointAt(a);
  675. if (!backslash)
  676. {
  677. if (next == '?' && valPos < val.length())
  678. {
  679. ++valPos;
  680. matched = true;
  681. }
  682. else if (next == '*')
  683. {
  684. fallback = valPos;
  685. fallbackP = a;
  686. matched = true;
  687. }
  688. else if (next == '[' && valPos < val.length())
  689. {
  690. boolean negated = false;
  691. int b = a + 1;
  692. int classChar = pattern.codePointAt(b);
  693. do
  694. {
  695. if (classChar == '!' && b == a + 1)
  696. negated = true;
  697. else if (pattern.codePointAt(b + 1) == '-' &&
  698. pattern.codePointAt(b + 2) != ']')
  699. {
  700. if (classChar > pattern.codePointAt(b + 2))
  701. throw new BadStringOperationException("Invalid range: " +
  702. classChar + " to " +
  703. pattern.codePointAt(b+2));
  704. for (int c = classChar; c <= pattern.codePointAt(b+2); ++c)
  705. if (val.codePointAt(valPos) == c)
  706. matched = true;
  707. b = b + 2;
  708. }
  709. else if (val.codePointAt(valPos) == classChar)
  710. matched = true;
  711. ++b;
  712. classChar = pattern.codePointAt(b);
  713. } while (classChar != ']');
  714. if (negated)
  715. matched = !matched;
  716. ++valPos;
  717. a = b;
  718. }
  719. else if (next == '\\')
  720. backslash = true;
  721. else if (valPos < val.length() && next == val.codePointAt(valPos))
  722. {
  723. matched = true;
  724. ++valPos;
  725. }
  726. }
  727. else
  728. {
  729. backslash = false;
  730. if (valPos < val.length() && next == val.codePointAt(valPos))
  731. {
  732. matched = true;
  733. ++valPos;
  734. }
  735. }
  736. if (!matched)
  737. if (fallback != -1)
  738. {
  739. ++fallback;
  740. valPos = fallback;
  741. a = fallbackP;
  742. if (valPos == val.length())
  743. return false;
  744. continue;
  745. }
  746. else
  747. return false;
  748. }
  749. return true;
  750. }
  751. }
  752. /**
  753. * Representation of the retrieval of an attribute
  754. * value from a certain class for {@link #attr(String,String)}.
  755. *
  756. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  757. * @since 1.5
  758. */
  759. private static final class QualifiedAttributeValueExp
  760. extends AttributeValueExp
  761. {
  762. /**
  763. * Compatible with JDK 1.6
  764. */
  765. private static final long serialVersionUID = 8832517277410933254L;
  766. /**
  767. * The name of the class from which the attribute is taken.
  768. */
  769. private String className;
  770. /**
  771. * Constructs a new {@link QualifiedAttributeValueExp} using
  772. * the specified class name and attribute name.
  773. *
  774. * @param className the class name.
  775. * @param name the attribute name.
  776. */
  777. public QualifiedAttributeValueExp(String className, String name)
  778. {
  779. super(name);
  780. this.className = className;
  781. }
  782. /**
  783. * Applies the {@link AttributeValueExp} to the specified
  784. * management bean by checking that the attribute will be
  785. * obtained from the correct class (by a class to
  786. * {@link MBeanServer#getObjectInstance(ObjectName)} and
  787. * then obtaining the attribute value from the
  788. * {@link MBeanServer}, using it to create a
  789. * {@link StringValueExp}.
  790. *
  791. * @param name the {@link ObjectName} of the bean to obtain
  792. * the value from.
  793. * @return a {@link StringValueExp} containing the result.
  794. * @throws BadStringOperationException if an invalid string
  795. * operation is used by
  796. * the value expression.
  797. * @throws BadBinaryOpValueExpException if an invalid expression
  798. * is used by the value expression.
  799. * @throws BadAttributeValueExpException if an invalid attribute
  800. * is used by the value expression.
  801. * @throws InvalidApplicationException if the value expression is applied
  802. * to the wrong type of bean.
  803. */
  804. public ValueExp apply(ObjectName name)
  805. throws BadStringOperationException, BadBinaryOpValueExpException,
  806. BadAttributeValueExpException, InvalidApplicationException
  807. {
  808. try
  809. {
  810. if (!(QueryEval.getMBeanServer().getObjectInstance(name).getClassName().equals(className)))
  811. throw new BadAttributeValueExpException("The value is not from " +
  812. "the correct class.");
  813. }
  814. catch (InstanceNotFoundException e)
  815. {
  816. throw (BadAttributeValueExpException)
  817. new BadAttributeValueExpException("The named bean is not registered.").initCause(e);
  818. }
  819. return super.apply(name);
  820. }
  821. }
  822. /**
  823. * Representation of the comparison of a value with
  824. * a pair of bounds formed using
  825. * {@link #between(ValueExp, ValueExp, ValueExp).
  826. *
  827. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  828. * @since 1.5
  829. */
  830. private static final class BetweenQueryExp
  831. extends QueryEval
  832. implements QueryExp
  833. {
  834. /**
  835. * Compatible with JDK 1.6
  836. */
  837. private static final long serialVersionUID = -2933597532866307444L;
  838. /**
  839. * The value to compare.
  840. */
  841. private ValueExp exp1;
  842. /**
  843. * The lower boundary.
  844. */
  845. private ValueExp exp2;
  846. /**
  847. * The upper boundary.
  848. */
  849. private ValueExp exp3;
  850. /**
  851. * Constructs a new {@link BetweenQueryExp} using
  852. * the specified comparison value and the given
  853. * bounds.
  854. *
  855. * @param exp1 the value to compare.
  856. * @param exp2 the lower bound.
  857. * @param exp3 the upper bound.
  858. */
  859. public BetweenQueryExp(ValueExp exp1, ValueExp exp2,
  860. ValueExp exp3)
  861. {
  862. this.exp1 = exp1;
  863. this.exp2 = exp2;
  864. this.exp3 = exp3;
  865. }
  866. /**
  867. * Returns the result of the comparison between
  868. * the value and the two bounds.
  869. *
  870. * @param name the {@link ObjectName} to apply
  871. * the query to.
  872. * @return the result of the comparison.
  873. * @throws BadStringOperationException if an invalid string
  874. * operation is used by
  875. * the query.
  876. * @throws BadBinaryOpValueExpException if an invalid expression
  877. * is used by the query.
  878. * @throws BadAttributeValueExpException if an invalid attribute
  879. * is used by the query.
  880. * @throws InvalidApplicationException if the query is applied
  881. * to the wrong type of bean.
  882. */
  883. public boolean apply(ObjectName name)
  884. throws BadStringOperationException, BadBinaryOpValueExpException,
  885. BadAttributeValueExpException, InvalidApplicationException
  886. {
  887. String v1 = exp1.apply(name).toString();
  888. String v2 = exp2.apply(name).toString();
  889. String v3 = exp3.apply(name).toString();
  890. return v1.compareTo(v2) >= 0 && v1.compareTo(v3) <= 0;
  891. }
  892. }
  893. /**
  894. * Representation of the retrieval of the name of
  895. * a bean's class for {@link #classattr()}.
  896. *
  897. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  898. * @since 1.5
  899. */
  900. private static final class ClassAttributeValueExp
  901. extends AttributeValueExp
  902. {
  903. /**
  904. * Compatible with JDK 1.6
  905. */
  906. private static final long serialVersionUID = -1081892073854801359L;
  907. /**
  908. * Obtains the name of the specified bean's class using a call
  909. * to {@link MBeanServer#getObjectInstance(ObjectName)}.
  910. *
  911. * @param name the {@link ObjectName} of the bean to obtain
  912. * the class name from.
  913. * @return a {@link StringValueExp} containing the result.
  914. * @throws BadStringOperationException if an invalid string
  915. * operation is used by
  916. * the value expression.
  917. * @throws BadBinaryOpValueExpException if an invalid expression
  918. * is used by the value expression.
  919. * @throws BadAttributeValueExpException if an invalid attribute
  920. * is used by the value expression.
  921. * @throws InvalidApplicationException if the value expression is applied
  922. * to the wrong type of bean.
  923. */
  924. public ValueExp apply(ObjectName name)
  925. throws BadStringOperationException, BadBinaryOpValueExpException,
  926. BadAttributeValueExpException, InvalidApplicationException
  927. {
  928. try
  929. {
  930. return new StringValueExp(QueryEval.getMBeanServer().getObjectInstance(name).getClassName());
  931. }
  932. catch (InstanceNotFoundException e)
  933. {
  934. throw (BadAttributeValueExpException)
  935. new BadAttributeValueExpException("The named bean is not registered.").initCause(e);
  936. }
  937. }
  938. }
  939. /**
  940. * Representation of a binary operation formed using
  941. * {@link #div(ValueExp, ValueExp), {@link #plus(ValueExp,ValueExp)},
  942. * {@link #minus(ValueExp, ValueExp) or
  943. * {@link #times(ValueExp, ValueExp)}.
  944. *
  945. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  946. * @since 1.5
  947. */
  948. private static final class BinaryOpValueExp
  949. extends QueryEval
  950. implements ValueExp
  951. {
  952. /**
  953. * Compatible with JDK 1.6
  954. */
  955. private static final long serialVersionUID = 1216286847881456786L;
  956. /**
  957. * The operation to perform.
  958. */
  959. private int op;
  960. /**
  961. * The left-hand operand.
  962. */
  963. private ValueExp exp1;
  964. /**
  965. * The right-hand operand.
  966. */
  967. private ValueExp exp2;
  968. /**
  969. * Constructs a new {@link BinaryOpValueExp} using
  970. * the specified operation and the two values supplied.
  971. *
  972. * @param op the operation to perform.
  973. * @param exp1 the left-hand operand.
  974. * @param exp2 the right-hand operand.
  975. */
  976. public BinaryOpValueExp(int op, ValueExp exp1, ValueExp exp2)
  977. {
  978. this.op = op;
  979. this.exp1 = exp1;
  980. this.exp2 = exp2;
  981. }
  982. /**
  983. * Returns the result of performing the operation on
  984. * <code>exp1</code> and <code>exp2</code>.
  985. *
  986. * @param name the {@link ObjectName} to apply
  987. * the query to.
  988. * @return the result of the operation.
  989. * @throws BadStringOperationException if an invalid string
  990. * operation is used by
  991. * the query.
  992. * @throws BadBinaryOpValueExpException if an invalid expression
  993. * is used by the query.
  994. * @throws BadAttributeValueExpException if an invalid attribute
  995. * is used by the query.
  996. * @throws InvalidApplicationException if the query is applied
  997. * to the wrong type of bean.
  998. */
  999. public ValueExp apply(ObjectName name)
  1000. throws BadStringOperationException, BadBinaryOpValueExpException,
  1001. BadAttributeValueExpException, InvalidApplicationException
  1002. {
  1003. NumericValueExp v1 = (NumericValueExp) exp1.apply(name);
  1004. NumericValueExp v2 = (NumericValueExp) exp2.apply(name);
  1005. switch (op)
  1006. {
  1007. case PLUS:
  1008. return v1.plus(v2);
  1009. case MINUS:
  1010. return v1.minus(v2);
  1011. case TIMES:
  1012. return v1.times(v2);
  1013. case DIV:
  1014. return v1.div(v2);
  1015. default:
  1016. throw new BadBinaryOpValueExpException(this);
  1017. }
  1018. }
  1019. /**
  1020. * Returns a textual representation of the operation.
  1021. *
  1022. * @return a textual version of the operation.
  1023. */
  1024. public String toString()
  1025. {
  1026. String opS;
  1027. switch (op)
  1028. {
  1029. case PLUS:
  1030. opS = "+";
  1031. break;
  1032. case MINUS:
  1033. opS = "-";
  1034. break;
  1035. case TIMES:
  1036. opS = "x";
  1037. break;
  1038. case DIV:
  1039. opS = "/";
  1040. break;
  1041. default:
  1042. opS = "?";
  1043. }
  1044. return exp1 + " " + opS + " " + exp2;
  1045. }
  1046. }
  1047. /**
  1048. * Representation of a binary operation formed using
  1049. * {@link #eq(ValueExp, ValueExp), {@link #geq(ValueExp, ValueExp)},
  1050. * {@link #leq(ValueExp, ValueExp), {@link #gt(ValueExp, ValueExp)}
  1051. * or {@link #lt(ValueExp, ValueExp)}.
  1052. *
  1053. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  1054. * @since 1.5
  1055. */
  1056. private static final class BinaryRelQueryExp
  1057. extends QueryEval
  1058. implements QueryExp
  1059. {
  1060. /**
  1061. * Compatible with JDK 1.6
  1062. */
  1063. private static final long serialVersionUID = -5690656271650491000L;
  1064. /**
  1065. * The operation to perform.
  1066. */
  1067. private int relOp;
  1068. /**
  1069. * The left-hand operand.
  1070. */
  1071. private ValueExp exp1;
  1072. /**
  1073. * The right-hand operand.
  1074. */
  1075. private ValueExp exp2;
  1076. /**
  1077. * Constructs a new {@link BinaryRelQueryExp} using
  1078. * the specified operation and the two values supplied.
  1079. *
  1080. * @param relOp the operation to perform.
  1081. * @param exp1 the left-hand operand.
  1082. * @param exp2 the right-hand operand.
  1083. */
  1084. public BinaryRelQueryExp(int relOp, ValueExp exp1, ValueExp exp2)
  1085. {
  1086. this.relOp = relOp;
  1087. this.exp1 = exp1;
  1088. this.exp2 = exp2;
  1089. }
  1090. /**
  1091. * Returns the result of performing the operation on
  1092. * <code>exp1</code> and <code>exp2</code>.
  1093. *
  1094. * @param name the {@link ObjectName} to apply
  1095. * the query to.
  1096. * @return the result of the comparison.
  1097. * @throws BadStringOperationException if an invalid string
  1098. * operation is used by
  1099. * the query.
  1100. * @throws BadBinaryOpValueExpException if an invalid expression
  1101. * is used by the query.
  1102. * @throws BadAttributeValueExpException if an invalid attribute
  1103. * is used by the query.
  1104. * @throws InvalidApplicationException if the query is applied
  1105. * to the wrong type of bean.
  1106. */
  1107. public boolean apply(ObjectName name)
  1108. throws BadStringOperationException, BadBinaryOpValueExpException,
  1109. BadAttributeValueExpException, InvalidApplicationException
  1110. {
  1111. String v1 = exp1.apply(name).toString();
  1112. String v2 = exp2.apply(name).toString();
  1113. switch (relOp)
  1114. {
  1115. case EQ:
  1116. return v1.equals(v2);
  1117. case GT:
  1118. return v1.compareTo(v2) > 0;
  1119. case GE:
  1120. return v1.compareTo(v2) >= 0;
  1121. case LE:
  1122. return v1.compareTo(v2) <= 0;
  1123. case LT:
  1124. return v1.compareTo(v2) < 0;
  1125. default:
  1126. throw new BadStringOperationException("Invalid operator: " + relOp);
  1127. }
  1128. }
  1129. /**
  1130. * Returns a textual representation of the operation.
  1131. *
  1132. * @return a textual version of the operation.
  1133. */
  1134. public String toString()
  1135. {
  1136. String op;
  1137. switch (relOp)
  1138. {
  1139. case EQ:
  1140. op = "=";
  1141. break;
  1142. case GT:
  1143. op = ">";
  1144. break;
  1145. case GE:
  1146. op = ">=";
  1147. break;
  1148. case LE:
  1149. op = "<=";
  1150. break;
  1151. case LT:
  1152. op = "<";
  1153. break;
  1154. default:
  1155. op = "?";
  1156. }
  1157. return exp1 + " " + op + " " + exp2;
  1158. }
  1159. }
  1160. /**
  1161. * Representation of the comparison of a value with
  1162. * the members of a list formed using
  1163. * {@link #in(ValueExp, ValueExp[]).
  1164. *
  1165. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  1166. * @since 1.5
  1167. */
  1168. private static final class InQueryExp
  1169. extends QueryEval
  1170. implements QueryExp
  1171. {
  1172. /**
  1173. * Compatible with JDK 1.6
  1174. */
  1175. private static final long serialVersionUID = -5801329450358952434L;
  1176. /**
  1177. * The value to look for.
  1178. */
  1179. private ValueExp val;
  1180. /**
  1181. * The array to search.
  1182. */
  1183. private ValueExp[] valueList;
  1184. /**
  1185. * Constructs a new {@link InQueryExp} using
  1186. * the specified comparison value and the given
  1187. * list.
  1188. *
  1189. * @param val the value to compare.
  1190. * @param valueList the list of values.
  1191. */
  1192. public InQueryExp(ValueExp val, ValueExp[] valueList)
  1193. {
  1194. this.val = val;
  1195. this.valueList = valueList;
  1196. }
  1197. /**
  1198. * Returns the result of the comparison between
  1199. * the value and the list of allowed values.
  1200. *
  1201. * @param name the {@link ObjectName} to apply
  1202. * the query to.
  1203. * @return the result of the comparison.
  1204. * @throws BadStringOperationException if an invalid string
  1205. * operation is used by
  1206. * the query.
  1207. * @throws BadBinaryOpValueExpException if an invalid expression
  1208. * is used by the query.
  1209. * @throws BadAttributeValueExpException if an invalid attribute
  1210. * is used by the query.
  1211. * @throws InvalidApplicationException if the query is applied
  1212. * to the wrong type of bean.
  1213. */
  1214. public boolean apply(ObjectName name)
  1215. throws BadStringOperationException, BadBinaryOpValueExpException,
  1216. BadAttributeValueExpException, InvalidApplicationException
  1217. {
  1218. String v = val.apply(name).toString();
  1219. for (ValueExp vl : valueList)
  1220. if (v.equals(vl.apply(name).toString()))
  1221. return true;
  1222. return false;
  1223. }
  1224. }
  1225. /**
  1226. * Representation of the inheritance check on a
  1227. * bean for {@link #isInstanceOf(StringValueExp)}.
  1228. *
  1229. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  1230. * @since 1.6
  1231. */
  1232. private static final class InstanceOfQueryExp
  1233. extends QueryEval
  1234. implements QueryExp
  1235. {
  1236. /**
  1237. * Compatible with JDK 1.6
  1238. */
  1239. private static final long serialVersionUID = -1081892073854801359L;
  1240. /**
  1241. * The name of the class from which the attribute is taken.
  1242. */
  1243. private StringValueExp classNameValue;
  1244. /**
  1245. * Constructs a new {@link InstanceOfQueryExp} using
  1246. * the specified class name.
  1247. *
  1248. * @param classNameValue the class name.
  1249. */
  1250. public InstanceOfQueryExp(StringValueExp classNameValue)
  1251. {
  1252. this.classNameValue = classNameValue;
  1253. }
  1254. /**
  1255. * Checks that the bean specified by the supplied
  1256. * {@link ObjectName} is of the correct class
  1257. * using {@link MBeanServer#isInstanceOf(ObjectName,String)}.
  1258. * where the string is obtained by evaluating
  1259. * <code>classNameValue</code>.
  1260. *
  1261. * @param name the {@link ObjectName} of the bean to obtain
  1262. * the value from.
  1263. * @return true if the bean is an instance of the class.
  1264. * @throws BadStringOperationException if an invalid string
  1265. * operation is used by
  1266. * the value expression.
  1267. * @throws BadBinaryOpValueExpException if an invalid expression
  1268. * is used by the value expression.
  1269. * @throws BadAttributeValueExpException if an invalid attribute
  1270. * is used by the value expression.
  1271. * @throws InvalidApplicationException if the value expression is applied
  1272. * to the wrong type of bean.
  1273. */
  1274. public boolean apply(ObjectName name)
  1275. throws BadStringOperationException, BadBinaryOpValueExpException,
  1276. BadAttributeValueExpException, InvalidApplicationException
  1277. {
  1278. try
  1279. {
  1280. String className = ((StringValueExp)
  1281. classNameValue.apply(name)).getValue();
  1282. return QueryEval.getMBeanServer().isInstanceOf(name, className);
  1283. }
  1284. catch (InstanceNotFoundException e)
  1285. {
  1286. throw (BadAttributeValueExpException)
  1287. new BadAttributeValueExpException("The named bean is not registered.").initCause(e);
  1288. }
  1289. }
  1290. }
  1291. /**
  1292. * Representation of the negation of a query formed using
  1293. * {@link #not(QueryExp).
  1294. *
  1295. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  1296. * @since 1.5
  1297. */
  1298. private static final class NotQueryExp
  1299. extends QueryEval
  1300. implements QueryExp
  1301. {
  1302. /**
  1303. * Compatible with JDK 1.6
  1304. */
  1305. private static final long serialVersionUID = 5269643775896723397L;
  1306. /**
  1307. * The expression to negate.
  1308. */
  1309. private QueryExp exp;
  1310. /**
  1311. * Constructs a new {@link NotQueryExp} using
  1312. * the specified query expression.
  1313. *
  1314. * @param exp the expression to negate.
  1315. */
  1316. public NotQueryExp(QueryExp exp)
  1317. {
  1318. this.exp = exp;
  1319. }
  1320. /**
  1321. * Returns the result of the negation.
  1322. *
  1323. * @param name the {@link ObjectName} to apply
  1324. * the query to.
  1325. * @return the result of the negation.
  1326. * @throws BadStringOperationException if an invalid string
  1327. * operation is used by
  1328. * the query.
  1329. * @throws BadBinaryOpValueExpException if an invalid expression
  1330. * is used by the query.
  1331. * @throws BadAttributeValueExpException if an invalid attribute
  1332. * is used by the query.
  1333. * @throws InvalidApplicationException if the query is applied
  1334. * to the wrong type of bean.
  1335. */
  1336. public boolean apply(ObjectName name)
  1337. throws BadStringOperationException, BadBinaryOpValueExpException,
  1338. BadAttributeValueExpException, InvalidApplicationException
  1339. {
  1340. return !(exp.apply(name));
  1341. }
  1342. }
  1343. /**
  1344. * Representation of the disjunction formed using
  1345. * {@link #or(QueryExp, QueryExp).
  1346. *
  1347. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  1348. * @since 1.5
  1349. */
  1350. private static final class OrQueryExp
  1351. extends QueryEval
  1352. implements QueryExp
  1353. {
  1354. /**
  1355. * Compatible with JDK 1.6
  1356. */
  1357. private static final long serialVersionUID = 2962973084421716523L;
  1358. /**
  1359. * The first operand.
  1360. */
  1361. private QueryExp exp1;
  1362. /**
  1363. * The second operand.
  1364. */
  1365. private QueryExp exp2;
  1366. /**
  1367. * Constructs a new {@link OrQueryExp} using
  1368. * the two specified operands.
  1369. *
  1370. * @param exp1 the first query expression.
  1371. * @param exp2 the second query expression.
  1372. */
  1373. public OrQueryExp(QueryExp exp1, QueryExp exp2)
  1374. {
  1375. this.exp1 = exp1;
  1376. this.exp2 = exp2;
  1377. }
  1378. /**
  1379. * Returns the disjunction of the two query
  1380. * expressions.
  1381. *
  1382. * @param name the {@link ObjectName} to apply
  1383. * the query to.
  1384. * @return the disjunction of applying the name
  1385. * to both operands.
  1386. * @throws BadStringOperationException if an invalid string
  1387. * operation is used by
  1388. * the query.
  1389. * @throws BadBinaryOpValueExpException if an invalid expression
  1390. * is used by the query.
  1391. * @throws BadAttributeValueExpException if an invalid attribute
  1392. * is used by the query.
  1393. * @throws InvalidApplicationException if the query is applied
  1394. * to the wrong type of bean.
  1395. */
  1396. public boolean apply(ObjectName name)
  1397. throws BadStringOperationException, BadBinaryOpValueExpException,
  1398. BadAttributeValueExpException, InvalidApplicationException
  1399. {
  1400. return exp1.apply(name) || exp2.apply(name);
  1401. }
  1402. }
  1403. /**
  1404. * Representation of a boolean being used as an argument
  1405. * to a relational constraint, formed using
  1406. * {@link #value(boolean)}.
  1407. *
  1408. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  1409. * @since 1.5
  1410. */
  1411. private static final class BooleanValueExp
  1412. extends QueryEval
  1413. implements ValueExp
  1414. {
  1415. /**
  1416. * Compatible with JDK 1.6
  1417. */
  1418. private static final long serialVersionUID = 7754922052666594581L;
  1419. /**
  1420. * The boolean value.
  1421. */
  1422. private boolean val;
  1423. /**
  1424. * Constructs a new {@link BooleanValueExp} using the
  1425. * specified value.
  1426. *
  1427. * @param val the boolean value used for this expression.
  1428. */
  1429. public BooleanValueExp(boolean val)
  1430. {
  1431. this.val = val;
  1432. }
  1433. /**
  1434. * Applies the {@link BooleanValueExp} to the specified
  1435. * management bean by simply returning the value.
  1436. *
  1437. * @param name the {@link ObjectName} of the bean.
  1438. * @return the {@link BooleanValueExp} itself.
  1439. * @throws BadStringOperationException if an invalid string
  1440. * operation is used by
  1441. * the value expression.
  1442. * @throws BadBinaryOpValueExpException if an invalid expression
  1443. * is used by the value expression.
  1444. * @throws BadAttributeValueExpException if an invalid attribute
  1445. * is used by the value expression.
  1446. * @throws InvalidApplicationException if the value expression is applied
  1447. * to the wrong type of bean.
  1448. */
  1449. public ValueExp apply(ObjectName name)
  1450. throws BadStringOperationException, BadBinaryOpValueExpException,
  1451. BadAttributeValueExpException, InvalidApplicationException
  1452. {
  1453. return this;
  1454. }
  1455. /**
  1456. * Returns the value as a string.
  1457. *
  1458. * @return the value in textual form.
  1459. */
  1460. public String toString()
  1461. {
  1462. return Boolean.toString(val);
  1463. }
  1464. }
  1465. /**
  1466. * Representation of a number being used as an argument
  1467. * to a relational constraint, formed using
  1468. * {@link #value(double)}, {@link #value(float)},
  1469. * {@link #value(int)}, {@link #value(long)} or
  1470. * {@link #value(Number)}.
  1471. *
  1472. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  1473. * @since 1.5
  1474. */
  1475. private static final class NumericValueExp
  1476. extends QueryEval
  1477. implements ValueExp
  1478. {
  1479. /**
  1480. * Compatible with JDK 1.6
  1481. */
  1482. private static final long serialVersionUID = -4679739485102359104L;
  1483. /**
  1484. * The numeric value.
  1485. */
  1486. private Number val;
  1487. /**
  1488. * Constructs a new {@link NumericValueExp} using the
  1489. * specified …

Large files files are truncated, but you can click here to view the full file