jdk/src/share/classes/javax/management/OrQueryExp.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 471 422ff0db58d3
child 4156 acaa49a2768a
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 471
diff changeset
     2
 * Copyright 1999-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * This class is used by the query-building mechanism to represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * disjunctions of relational expressions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @serial include
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
class OrQueryExp extends QueryEval implements QueryExp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /* Serial version */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    private static final long serialVersionUID = 2962973084421716523L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * @serial The left query expression
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    private QueryExp exp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * @serial The right query expression
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private QueryExp exp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Basic Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public OrQueryExp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * Creates a new OrQueryExp with the specified ValueExps
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public OrQueryExp(QueryExp q1, QueryExp q2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        exp1 = q1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        exp2 = q2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns the left query expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public QueryExp getLeftExp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return exp1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * Returns the right query expression.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public QueryExp getRightExp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return exp2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Applies the OrQueryExp on a MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param name The name of the MBean on which the OrQueryExp will be applied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @return  True if the query was successfully applied to the MBean, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @exception BadStringOperationException The string passed to the method is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @exception BadBinaryOpValueExpException The expression passed to the method is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @exception BadAttributeValueExpException The attribute value passed to the method is invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public boolean apply(ObjectName name) throws BadStringOperationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        BadBinaryOpValueExpException, BadAttributeValueExpException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        InvalidApplicationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return exp1.apply(name) || exp2.apply(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   101
     * Returns a string representation of this OrQueryExp
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
471
422ff0db58d3 6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents: 34
diff changeset
   103
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return "(" + exp1 + ") or (" + exp2 + ")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   107
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   108
    @Override
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   109
    String toQueryString() {
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   110
        return parens(exp1) + " or " + parens(exp2);
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   111
    }
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   112
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   113
    // Add parentheses to avoid possible confusion.  If we have an expression
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   114
    // such as Query.or(Query.and(a, b), c), then we return
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   115
    // (a and b) or c
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   116
    // rather than just
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   117
    // a and b or c
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   118
    // In fact the precedence rules are such that the parentheses are not
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   119
    // strictly necessary, but omitting them would be confusing.
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   120
    private static String parens(QueryExp exp) {
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   121
        String s = Query.toString(exp);
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   122
        if (exp instanceof AndQueryExp)
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   123
            return "(" + s + ")";
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   124
        else
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   125
            return s;
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   126
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}