jdk/src/share/classes/javax/management/ObjectName.java
author rriggs
Tue, 12 Nov 2013 14:03:28 -0500
changeset 21656 d4c777ccb1db
parent 7038 fd9c0e3b34eb
child 23010 6dadb192ad81
permissions -rw-r--r--
8028014: Doclint warning/error cleanup in javax.management Summary: Improve generated html by fixing doclint warnings Reviewed-by: sla, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     2
 * Copyright (c) 1999, 2008, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
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
import com.sun.jmx.mbeanserver.GetPropertyAction;
287
bff5501b2a02 6610917: Define a generic NotificationFilter
emcmanus
parents: 34
diff changeset
    29
import com.sun.jmx.mbeanserver.Util;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <p>Represents the object name of an MBean, or a pattern that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * match the names of several MBeans.  Instances of this class are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * immutable.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>An instance of this class can be used to represent:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <li>An object name</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <li>An object name pattern, within the context of a query</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>An object name consists of two parts, the domain and the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * properties.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <p>The <em>domain</em> is a string of characters not including
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
    57
 * the character colon (<code>:</code>).  It is recommended that the domain
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
    58
 * should not contain the string "{@code //}", which is reserved for future use.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>If the domain includes at least one occurrence of the wildcard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * characters asterisk (<code>*</code>) or question mark
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * (<code>?</code>), then the object name is a pattern.  The asterisk
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * matches any sequence of zero or more characters, while the question
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
    64
 * mark matches any single character.</p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>If the domain is empty, it will be replaced in certain contexts
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * by the <em>default domain</em> of the MBean server in which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * ObjectName is used.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>The <em>key properties</em> are an unordered set of keys and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * associated values.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <p>Each <em>key</em> is a nonempty string of characters which may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * not contain any of the characters comma (<code>,</code>), equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * (<code>=</code>), colon, asterisk, or question mark.  The same key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * may not occur twice in a given ObjectName.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * <p>Each <em>value</em> associated with a key is a string of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * characters that is either unquoted or quoted.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>An <em>unquoted value</em> is a possibly empty string of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * characters which may not contain any of the characters comma,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * equals, colon, or quote.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <p>If the <em>unquoted value</em> contains at least one occurrence
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * of the wildcard characters asterisk or question mark, then the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * name is a <em>property value pattern</em>. The asterisk matches any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * sequence of zero or more characters, while the question mark matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * any single character.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>A <em>quoted value</em> consists of a quote (<code>"</code>),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * followed by a possibly empty string of characters, followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * another quote.  Within the string of characters, the backslash
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * (<code>\</code>) has a special meaning.  It must be followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * one of the following characters:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <li>Another backslash.  The second backslash has no special
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * meaning and the two characters represent a single backslash.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <li>The character 'n'.  The two characters represent a newline
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * ('\n' in Java).</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <li>A quote.  The two characters represent a quote, and that quote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * is not considered to terminate the quoted value. An ending closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * quote must be present for the quoted value to be valid.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * <li>A question mark (?) or asterisk (*).  The two characters represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * a question mark or asterisk respectively.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <p>A quote may not appear inside a quoted value except immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * after an odd number of consecutive backslashes.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <p>The quotes surrounding a quoted value, and any backslashes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * within that value, are considered to be part of the value.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * <p>If the <em>quoted value</em> contains at least one occurrence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * the characters asterisk or question mark and they are not preceded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * by a backslash, then they are considered as wildcard characters and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * the object name is a <em>property value pattern</em>. The asterisk
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * matches any sequence of zero or more characters, while the question
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * mark matches any single character.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * <p>An ObjectName may be a <em>property list pattern</em>. In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * case it may have zero or more keys and associated values. It matches
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * a nonpattern ObjectName whose domain matches and that contains the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * same keys and associated values, as well as possibly other keys and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * values.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>An ObjectName is a <em>property value pattern</em> when at least
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * one of its <em>quoted</em> or <em>unquoted</em> key property values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * contains the wildcard characters asterisk or question mark as described
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * above. In this case it has one or more keys and associated values, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * at least one of the values containing wildcard characters. It matches a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * nonpattern ObjectName whose domain matches and that contains the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * keys whose values match; if the property value pattern is also a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * property list pattern then the nonpattern ObjectName can contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * other keys and values.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * <p>An ObjectName is a <em>property pattern</em> if it is either a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <em>property list pattern</em> or a <em>property value pattern</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * or both.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * <p>An ObjectName is a pattern if its domain contains a wildcard or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * if the ObjectName is a property pattern.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <p>If an ObjectName is not a pattern, it must contain at least one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * key with its associated value.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <p>Examples of ObjectName patterns are:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * <li>{@code *:type=Foo,name=Bar} to match names in any domain whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *     exact set of keys is {@code type=Foo,name=Bar}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <li>{@code d:type=Foo,name=Bar,*} to match names in the domain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *     {@code d} that have the keys {@code type=Foo,name=Bar} plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *     zero or more other keys.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * <li>{@code *:type=Foo,name=Bar,*} to match names in any domain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *     that has the keys {@code type=Foo,name=Bar} plus zero or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *     more other keys.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * <li>{@code d:type=F?o,name=Bar} will match e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *     {@code d:type=Foo,name=Bar} and {@code d:type=Fro,name=Bar}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * <li>{@code d:type=F*o,name=Bar} will match e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *     {@code d:type=Fo,name=Bar} and {@code d:type=Frodo,name=Bar}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * <li>{@code d:type=Foo,name="B*"} will match e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *     {@code d:type=Foo,name="Bling"}. Wildcards are recognized even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *     inside quotes, and like other special characters can be escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *     with {@code \}.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * <p>An ObjectName can be written as a String with the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * elements in order:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * <li>The domain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * <li>A colon (<code>:</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * <li>A key property list as defined below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * <p>A key property list written as a String is a comma-separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * list of elements.  Each element is either an asterisk or a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * property.  A key property consists of a key, an equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * (<code>=</code>), and the associated value.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * <p>At most one element of a key property list may be an asterisk.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * If the key property list contains an asterisk element, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * ObjectName is a property list pattern.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * <p>Spaces have no special significance in a String representing an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * ObjectName.  For example, the String:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * domain: key1 = value1 , key2 = value2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * represents an ObjectName with two keys.  The name of each key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * contains six characters, of which the first and last are spaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * The value associated with the key <code>"&nbsp;key1&nbsp;"</code>
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 7038
diff changeset
   198
 * also begins and ends with a space.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * <p>In addition to the restrictions on characters spelt out above,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
 * no part of an ObjectName may contain a newline character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * (<code>'\n'</code>), whether the domain, a key, or a value, whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * quoted or unquoted.  The newline character can be represented in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * quoted value with the sequence <code>\n</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 * <p>The rules on special characters and quoting apply regardless of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * which constructor is used to make an ObjectName.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
 * <p>To avoid collisions between MBeans supplied by different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 * vendors, a useful convention is to begin the domain name with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
 * reverse DNS name of the organization that specifies the MBeans,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
 * followed by a period and a string whose interpretation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
 * determined by that organization.  For example, MBeans specified by
7038
fd9c0e3b34eb 6984037: jmx/management rebranding vendor changes needed
emcmanus
parents: 5506
diff changeset
   214
 * <code>example.com</code>  would have
fd9c0e3b34eb 6984037: jmx/management rebranding vendor changes needed
emcmanus
parents: 5506
diff changeset
   215
 * domains such as <code>com.example.MyDomain</code>.  This is essentially
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
 * the same convention as for Java-language package names.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
 * <p>The <b>serialVersionUID</b> of this class is <code>1081892073854801359L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
@SuppressWarnings("serial") // don't complain serialVersionUID not constant
471
422ff0db58d3 6692027: Custom subclasses of QueryEval don't serialize
emcmanus
parents: 287
diff changeset
   223
public class ObjectName implements Comparable<ObjectName>, QueryExp {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * A structure recording property structure and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * proposing minimal services
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    private static class Property {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        int _key_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        int _key_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        int _value_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        Property(int key_index, int key_length, int value_length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            _key_index = key_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            _key_length = key_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            _value_length = value_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
         * Assigns the key index of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        void setKeyIndex(int key_index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            _key_index = key_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         * Returns a key string for receiver key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
         */
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   254
        String getKeyString(String name) {
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   255
            return name.substring(_key_index, _key_index + _key_length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * Returns a value string for receiver key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         */
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   261
        String getValueString(String name) {
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   262
            int in_begin = _key_index + _key_length + 1;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   263
            int out_end = in_begin + _value_length;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            return name.substring(in_begin, out_end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Marker class for value pattern property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    private static class PatternProperty extends Property {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        PatternProperty(int key_index, int key_length, int value_length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            super(key_index, key_length, value_length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    // Inner classes <========================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    // Private fields ---------------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // Serialization compatibility stuff -------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    private static final long oldSerialVersionUID = -5467795090068647408L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private static final long newSerialVersionUID = 1081892073854801359L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        new ObjectStreamField("domain", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        new ObjectStreamField("propertyList", Hashtable.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        new ObjectStreamField("propertyListString", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        new ObjectStreamField("canonicalName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        new ObjectStreamField("pattern", Boolean.TYPE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        new ObjectStreamField("propertyPattern", Boolean.TYPE)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private static final ObjectStreamField[] newSerialPersistentFields = { };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            // OK: exception means no compat with 1.0, too bad
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            serialVersionUID = newSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    // Serialization compatibility stuff <==============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    // Class private fields ----------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * a shared empty array for empty property lists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    static final private Property[] _Empty_property_array = new Property[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    // Class private fields <==============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    // Instance private fields ----------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * a String containing the canonical name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    private transient String _canonicalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * An array of properties in the same seq order as time creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private transient Property[] _kp_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * An array of properties in the same seq order as canonical order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    private transient Property[] _ca_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * The length of the domain part of built objectname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    private transient int _domain_length = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * The propertyList of built object name. Initialized lazily.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Table that contains all the pairs (key,value) for this ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    private transient Map<String,String> _propertyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * boolean that declares if this ObjectName domain part is a pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private transient boolean _domain_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * boolean that declares if this ObjectName contains a pattern on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * key property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    private transient boolean _property_list_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * boolean that declares if this ObjectName contains a pattern on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * value of at least one key property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private transient boolean _property_value_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    // Instance private fields <=======================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    // Private fields <========================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    //  Private methods ---------------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    // Category : Instance construction ------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Initializes this {@link ObjectName} from the given string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * representation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param name A string representation of the {@link ObjectName}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @exception MalformedObjectNameException The string passed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * parameter does not have the right format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @exception NullPointerException The <code>name</code> parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    private void construct(String name)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
   417
        throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        // The name cannot be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (name == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            throw new NullPointerException("name cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // Test if the name is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (name.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            // this is equivalent to the whole word query object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            _canonicalName = "*:*";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            _kp_array = _Empty_property_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            _ca_array = _Empty_property_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            _domain_length = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            _propertyList = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            _domain_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            _property_list_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            _property_value_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        // initialize parsing of the string
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
   438
        final char[] name_chars = name.toCharArray();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
   439
        final int len = name_chars.length;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
   440
        final char[] canonical_chars = new char[len]; // canonical form will
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
   441
                                                      // be same length at most
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        int cname_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        char c, c1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        // parses domain part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    domain_parsing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        while (index < len) {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 471
diff changeset
   449
            switch (name_chars[index]) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                case ':' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                    _domain_length = index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    break domain_parsing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                case '=' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    // ":" omission check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    // Although "=" is a valid character in the domain part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    // it is true that it is rarely used in the real world.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    // So check straight away if the ":" has been omitted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    // from the ObjectName. This allows us to provide a more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    // accurate exception message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    int i = ++index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    while ((i < len) && (name_chars[i++] != ':'))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                        if (i == len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                            throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                                "Domain part must be specified");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                case '\n' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                    throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                              "Invalid character '\\n' in domain name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    _domain_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                default :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // check for non-empty properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (index == len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                                         "Key properties cannot be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // we have got the domain part, begins building of _canonicalName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        System.arraycopy(name_chars, 0, canonical_chars, 0, _domain_length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        canonical_chars[_domain_length] = ':';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        cname_index = _domain_length + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // parses property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        Property prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        Map<String,Property> keys_map = new HashMap<String,Property>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        String[] keys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        String key_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        boolean quoted_value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        int property_index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        int in_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        int key_index, key_length, value_index, value_length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        keys = new String[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        _kp_array = new Property[10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        _property_list_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        _property_value_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        while (index < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            c = name_chars[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            // case of pattern properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            if (c == '*') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                if (_property_list_pattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                              "Cannot have several '*' characters in pattern " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                              "property list");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    _property_list_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    if ((++index < len ) && (name_chars[index] != ','))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                        throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                  "Invalid character found after '*': end of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                  "name or ',' expected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                    else if (index == len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                        if (property_index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                            // empty properties case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                            _kp_array = _Empty_property_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                            _ca_array = _Empty_property_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                            _propertyList = Collections.emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                        // correct pattern spec in props, continue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            // standard property case, key part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            in_index = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            key_index = in_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            if (name_chars[in_index] == '=')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                throw new MalformedObjectNameException("Invalid key (empty)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            while ((in_index < len) && ((c1 = name_chars[in_index++]) != '='))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                switch (c1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    // '=' considered to introduce value part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    case  '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    case  '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    case  ',' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    case  ':' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    case  '\n' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        final String ichar = ((c1=='\n')?"\\n":""+c1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                                  "Invalid character '" + ichar +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                  "' in key part of property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            if (name_chars[in_index - 1] != '=')
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                                             "Unterminated key property part");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            value_index = in_index; // in_index pointing after '=' char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            key_length = value_index - key_index - 1; // found end of key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            // standard property case, value part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            boolean value_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            if (in_index < len && name_chars[in_index] == '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                quoted_value = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                // the case of quoted value part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            quoted_value_parsing:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                while ((++in_index < len) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                       ((c1 = name_chars[in_index]) != '\"')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    // the case of an escaped character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    if (c1 == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                        if (++in_index == len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                            throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                                               "Unterminated quoted value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                        switch (c1 = name_chars[in_index]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                            case '\\' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                            case '\"' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                            case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                            case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                            case 'n' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                break; // valid character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                            default :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                          "Invalid escape sequence '\\" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                          c1 + "' in quoted value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    } else if (c1 == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                                     "Newline in quoted value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        switch (c1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                            case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                            case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                value_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                if (in_index == len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                    throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                                 "Unterminated quoted value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                else value_length = ++in_index - value_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                // the case of standard value part
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                quoted_value = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                while ((in_index < len) && ((c1 = name_chars[in_index]) != ','))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                switch (c1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    // ',' considered to be the value separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                        value_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                        in_index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                    case '=' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    case ':' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                    case '"' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    case '\n' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                        final String ichar = ((c1=='\n')?"\\n":""+c1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                        throw new MalformedObjectNameException(
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 471
diff changeset
   619
                                                 "Invalid character '" + ichar +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                                                 "' in value part of property");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                    default :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                        in_index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                value_length = in_index - value_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            // Parsed property, checks the end of name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            if (in_index == len - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                if (quoted_value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                                             "Invalid ending character `" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                             name_chars[in_index] + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                else throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                                  "Invalid ending comma");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            } else in_index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            // we got the key and value part, prepare a property for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            if (!value_pattern) {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   640
                prop = new Property(key_index, key_length, value_length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                _property_value_pattern = true;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   643
                prop = new PatternProperty(key_index, key_length, value_length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            key_name = name.substring(key_index, key_index + key_length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            if (property_index == keys.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                String[] tmp_string_array = new String[property_index + 10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                System.arraycopy(keys, 0, tmp_string_array, 0, property_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                keys = tmp_string_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            keys[property_index] = key_name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            addProperty(prop, property_index, keys_map, key_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            property_index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            index = in_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        // computes and set canonical name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        setCanonicalName(name_chars, canonical_chars, keys,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                         keys_map, cname_index, property_index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Construct an ObjectName from a domain and a Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * @param domain Domain of the ObjectName.
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 7038
diff changeset
   668
     * @param props  Map containing couples <i>key</i> {@literal ->} <i>value</i>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @exception MalformedObjectNameException The <code>domain</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * contains an illegal character, or one of the keys or values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * <code>table</code> contains an illegal character, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * values in <code>table</code> does not follow the rules for quoting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @exception NullPointerException One of the parameters is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    private void construct(String domain, Map<String,String> props)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
   677
        throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        // The domain cannot be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        if (domain == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            throw new NullPointerException("domain cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        // The key property list cannot be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (props == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            throw new NullPointerException("key property list cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        // The key property list cannot be empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        if (props.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                                         "key property list cannot be empty");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        // checks domain validity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        if (!isDomain(domain))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            throw new MalformedObjectNameException("Invalid domain: " + domain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        // init canonicalname
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        final StringBuilder sb = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        sb.append(domain).append(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        _domain_length = domain.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        // allocates the property array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        int nb_props = props.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        _kp_array = new Property[nb_props];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        String[] keys = new String[nb_props];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        final Map<String,Property> keys_map = new HashMap<String,Property>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        Property prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        int key_index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        for (Map.Entry<String,String> entry : props.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (sb.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            String key = entry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            String value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                value = entry.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                throw new MalformedObjectNameException(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            key_index = sb.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            checkKey(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            sb.append(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            keys[i] = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            sb.append("=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            boolean value_pattern = checkValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            sb.append(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            if (!value_pattern) {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   728
                prop = new Property(key_index,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                                    key.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                                    value.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                _property_value_pattern = true;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   733
                prop = new PatternProperty(key_index,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                                           key.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                                           value.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            addProperty(prop, i, keys_map, key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        // initialize canonical name and data structure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        int len = sb.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        char[] initial_chars = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        sb.getChars(0, len, initial_chars, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        char[] canonical_chars = new char[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        System.arraycopy(initial_chars, 0, canonical_chars, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                         _domain_length + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        setCanonicalName(initial_chars, canonical_chars, keys, keys_map,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                         _domain_length + 1, _kp_array.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    // Category : Instance construction <==============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    // Category : Internal utilities ------------------------------>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Add passed property to the list at the given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * for the passed key name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    private void addProperty(Property prop, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                             Map<String,Property> keys_map, String key_name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        throws MalformedObjectNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if (keys_map.containsKey(key_name)) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                MalformedObjectNameException("key `" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                         key_name +"' already defined");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        // if no more space for property arrays, have to increase it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        if (index == _kp_array.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            Property[] tmp_prop_array = new Property[index + 10];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            System.arraycopy(_kp_array, 0, tmp_prop_array, 0, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            _kp_array = tmp_prop_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        _kp_array[index] = prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        keys_map.put(key_name, prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * Sets the canonical name of receiver from input 'specified_chars'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * array, by filling 'canonical_chars' array with found 'nb-props'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * properties starting at position 'prop_index'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    private void setCanonicalName(char[] specified_chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                                  char[] canonical_chars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                                  String[] keys, Map<String,Property> keys_map,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                                  int prop_index, int nb_props) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        // Sort the list of found properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (_kp_array != _Empty_property_array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            String[] tmp_keys = new String[nb_props];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            Property[] tmp_props = new Property[nb_props];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            System.arraycopy(keys, 0, tmp_keys, 0, nb_props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            Arrays.sort(tmp_keys);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            keys = tmp_keys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            System.arraycopy(_kp_array, 0, tmp_props, 0 , nb_props);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
            _kp_array = tmp_props;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            _ca_array = new Property[nb_props];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            // now assigns _ca_array to the sorted list of keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
            // (there cannot be two identical keys in an objectname.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            for (int i = 0; i < nb_props; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                _ca_array[i] = keys_map.get(keys[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
            // now we build the canonical name and set begin indexes of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            // properties to reflect canonical form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            int last_index = nb_props - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            int prop_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            Property prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            for (int i = 0; i <= last_index; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                prop = _ca_array[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                // length of prop including '=' char
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                prop_len = prop._key_length + prop._value_length + 1;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   813
                System.arraycopy(specified_chars, prop._key_index,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                                 canonical_chars, prop_index, prop_len);
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
   815
                prop.setKeyIndex(prop_index);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                prop_index += prop_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                if (i != last_index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    canonical_chars[prop_index] = ',';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                    prop_index++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        // terminate canonicalname with '*' in case of pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        if (_property_list_pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            if (_kp_array != _Empty_property_array)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                canonical_chars[prop_index++] = ',';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            canonical_chars[prop_index++] = '*';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        // we now build the canonicalname string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        _canonicalName = (new String(canonical_chars, 0, prop_index)).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * Parse a key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * <pre>final int endKey=parseKey(s,startKey);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * <p>key starts at startKey (included), and ends at endKey (excluded).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * If (startKey == endKey), then the key is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @param s The char array of the original string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * @param startKey index at which to begin parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * @return The index following the last character of the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    private static int parseKey(final char[] s, final int startKey)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        throws MalformedObjectNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        int next   = startKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        int endKey = startKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        final int len = s.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        while (next < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            final char k = s[next++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            switch (k) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
            case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            case ',':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            case ':':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                final String ichar = ((k=='\n')?"\\n":""+k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                    MalformedObjectNameException("Invalid character in key: `"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                                                 + ichar + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                // we got the key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                endKey = next-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                if (next < len) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                else endKey=next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        return endKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * Parse a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * <pre>final int endVal=parseValue(s,startVal);</pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * <p>value starts at startVal (included), and ends at endVal (excluded).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * If (startVal == endVal), then the key is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * @param s The char array of the original string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @param startValue index at which to begin parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @return The first element of the int array indicates the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     *         following the last character of the value. The second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     *         element of the int array indicates that the value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     *         a pattern when its value equals 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    private static int[] parseValue(final char[] s, final int startValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        throws MalformedObjectNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        boolean value_pattern = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        int next   = startValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        int endValue = startValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        final int len = s.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        final char q=s[startValue];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        if (q == '"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            // quoted value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            if (++next == len) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                MalformedObjectNameException("Invalid quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            while (next < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
                char last = s[next];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
                if (last == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                    if (++next == len) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                        MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                           "Invalid unterminated quoted character sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                    last = s[next];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                    switch (last) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                        case '\\' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                        case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                        case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
                        case 'n' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                        case '\"' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                            // We have an escaped quote. If this escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                            // quote is the last character, it does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                            // qualify as a valid termination quote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                            if (next+1 == len) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                                MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                                                 "Missing termination quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                            throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                                MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                                "Invalid quoted character sequence '\\" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                last + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                } else if (last == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                    throw new MalformedObjectNameException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                                                 "Newline in quoted value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                } else if (last == '\"') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                    next++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    switch (last) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                        case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                        case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                            value_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                next++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                // Check that last character is a termination quote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                // We have already handled the case were the last
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                // character is an escaped quote earlier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                if ((next >= len) && (last != '\"')) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                    MalformedObjectNameException("Missing termination quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            endValue = next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            if (next < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                if (s[next++] != ',') throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    MalformedObjectNameException("Invalid quote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            // Non quoted value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            while (next < len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                final char v=s[next++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                switch(v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                    case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                    case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                        value_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                        if (next < len) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                        else endValue=next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    case '=':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                    case ':':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                    case '\n' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                        final String ichar = ((v=='\n')?"\\n":""+v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                        throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                            MalformedObjectNameException("Invalid character `" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
                                                         ichar + "' in value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                    case ',':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                        endValue = next-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                        if (next < len) continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                        else endValue=next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        return new int[] { endValue, value_pattern ? 1 : 0 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * Check if the supplied value is a valid value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * @return true if the value is a pattern, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    private static boolean checkValue(String val)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        throws MalformedObjectNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        if (val == null) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            NullPointerException("Invalid value (null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        final int len = val.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        if (len == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        final char[] s = val.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        final int[] result = parseValue(s,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        final int endValue = result[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        final boolean value_pattern = result[1] == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        if (endValue < len) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            MalformedObjectNameException("Invalid character in value: `" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                                         s[endValue] + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        return value_pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * Check if the supplied key is a valid key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    private static void checkKey(String key)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1019
        throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        if (key == null) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            NullPointerException("Invalid key (null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        final int len = key.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        if (len == 0) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            MalformedObjectNameException("Invalid key (empty)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        final char[] k=key.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        final int endKey = parseKey(k,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        if (endKey < len) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            MalformedObjectNameException("Invalid character in value: `" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                                         k[endKey] + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
    // Category : Internal utilities <==============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
    // Category : Internal accessors ------------------------------>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * Check if domain is a valid domain.  Set _domain_pattern if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
    private boolean isDomain(String domain) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        if (domain == null) return true;
1709
392dd6db361a 6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents: 1225
diff changeset
  1044
        final int len = domain.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        int next = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        while (next < len) {
1709
392dd6db361a 6768935: Clarify the behaviour of ObjectName pattern matching with regards to namespaces
dfuchs
parents: 1225
diff changeset
  1047
            final char c = domain.charAt(next++);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                case ':' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                case '\n' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                    _domain_pattern = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    // Category : Internal accessors <==============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    // Category : Serialization ----------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * Deserializes an {@link ObjectName} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @serialData <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     *               <li>In the current serial form (value of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     *                   <code>jmx.serial.form</code> differs from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     *                   <code>1.0</code>): the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *                   &quot;&lt;domain&gt;:&lt;properties&gt;&lt;wild&gt;&quot;,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *                   where: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     *                            <li>&lt;domain&gt; represents the domain part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     *                                of the {@link ObjectName}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *                            <li>&lt;properties&gt; represents the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     *                                properties, as returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     *                                {@link #getKeyPropertyListString}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     *                            <li>&lt;wild&gt; is empty if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     *                                <code>isPropertyPattern</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     *                                is the character "<code>*</code>" if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     *                                <code>isPropertyPattern</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *                                and &lt;properties&gt; is empty, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     *                                is "<code>,*</code>" if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     *                                <code>isPropertyPattern</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     *                                &lt;properties&gt; is not empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     *                            </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     *                          </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     *                   The intent is that this string could be supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *                   to the {@link #ObjectName(String)} constructor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     *                   produce an equivalent {@link ObjectName}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     *               </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *               <li>In the old serial form (value of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *                   <code>jmx.serial.form</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *                   <code>1.0</code>): &lt;domain&gt; &lt;propertyList&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *                   &lt;propertyListString&gt; &lt;canonicalName&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *                   &lt;pattern&gt; &lt;propertyPattern&gt;,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     *                   where: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     *                            <li>&lt;domain&gt; represents the domain part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     *                                of the {@link ObjectName}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     *                            <li>&lt;propertyList&gt; is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     *                                {@link Hashtable} that contains all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     *                                pairs (key,value) for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *                                {@link ObjectName}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     *                            <li>&lt;propertyListString&gt; is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     *                                {@link String} representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     *                                list of properties in any order (not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     *                                mandatorily a canonical representation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     *                                </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     *                            <li>&lt;canonicalName&gt; is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     *                                {@link String} containing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     *                                {@link ObjectName}'s canonical name</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     *                            <li>&lt;pattern&gt; is a boolean which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     *                                <code>true</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     *                                {@link ObjectName} contains a pattern</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *                            <li>&lt;propertyPattern&gt; is a boolean which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     *                                is <code>true</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     *                                {@link ObjectName} contains a pattern in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     *                                the list of properties</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *                          </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     *               </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     *             </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        String cn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            // Read an object serialized in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            //in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            final ObjectInputStream.GetField fields = in.readFields();
1005
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1132
            String propListString =
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1133
                    (String)fields.get("propertyListString", "");
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1134
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1135
            // 6616825: take care of property patterns
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1136
            final boolean propPattern =
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1137
                    fields.get("propertyPattern" , false);
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1138
            if (propPattern) {
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1139
                propListString =
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1140
                        (propListString.length()==0?"*":(propListString+",*"));
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1141
            }
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1142
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            cn = (String)fields.get("domain", "default")+
1005
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1144
                ":"+ propListString;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            // Read an object serialized in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            cn = (String)in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        try {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1153
            construct(cn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        } catch (NullPointerException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            throw new InvalidObjectException(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        } catch (MalformedObjectNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            throw new InvalidObjectException(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     * Serializes an {@link ObjectName} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @serialData <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     *               <li>In the current serial form (value of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     *                   <code>jmx.serial.form</code> differs from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     *                   <code>1.0</code>): the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     *                   &quot;&lt;domain&gt;:&lt;properties&gt;&lt;wild&gt;&quot;,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *                   where: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     *                            <li>&lt;domain&gt; represents the domain part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *                                of the {@link ObjectName}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     *                            <li>&lt;properties&gt; represents the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *                                properties, as returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     *                                {@link #getKeyPropertyListString}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     *                            <li>&lt;wild&gt; is empty if not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *                                <code>isPropertyPattern</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     *                                is the character "<code>*</code>" if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     *                                this <code>isPropertyPattern</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *                                and &lt;properties&gt; is empty, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     *                                is "<code>,*</code>" if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     *                                <code>isPropertyPattern</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     *                                &lt;properties&gt; is not empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     *                            </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *                          </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     *                   The intent is that this string could be supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     *                   to the {@link #ObjectName(String)} constructor to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     *                   produce an equivalent {@link ObjectName}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     *               </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     *               <li>In the old serial form (value of property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     *                   <code>jmx.serial.form</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     *                   <code>1.0</code>): &lt;domain&gt; &lt;propertyList&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *                   &lt;propertyListString&gt; &lt;canonicalName&gt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     *                   &lt;pattern&gt; &lt;propertyPattern&gt;,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     *                   where: <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     *                            <li>&lt;domain&gt; represents the domain part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *                                of the {@link ObjectName}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     *                            <li>&lt;propertyList&gt; is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     *                                {@link Hashtable} that contains all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     *                                pairs (key,value) for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     *                                {@link ObjectName}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     *                            <li>&lt;propertyListString&gt; is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *                                {@link String} representation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     *                                list of properties in any order (not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     *                                mandatorily a canonical representation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *                                </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *                            <li>&lt;canonicalName&gt; is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     *                                {@link String} containing this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     *                                {@link ObjectName}'s canonical name</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     *                            <li>&lt;pattern&gt; is a boolean which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *                                <code>true</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     *                                {@link ObjectName} contains a pattern</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     *                            <li>&lt;propertyPattern&gt; is a boolean which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     *                                is <code>true</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     *                                {@link ObjectName} contains a pattern in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     *                                the list of properties</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     *                          </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     *               </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     *             </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        // Read CR 6441274 before making any changes to this code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        ObjectOutputStream.PutField fields = out.putFields();
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1228
        fields.put("domain", _canonicalName.substring(0, _domain_length));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        fields.put("propertyList", getKeyPropertyList());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        fields.put("propertyListString", getKeyPropertyListString());
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1231
        fields.put("canonicalName", _canonicalName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        fields.put("pattern", (_domain_pattern || _property_list_pattern));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        fields.put("propertyPattern", _property_list_pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
        out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        out.defaultWriteObject();
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1241
        out.writeObject(getSerializedNameString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    //  Category : Serialization <===================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
    // Private methods <========================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    // Public methods ---------------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    // Category : ObjectName Construction ------------------------------>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * <p>Return an instance of ObjectName that can be used anywhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * an object obtained with {@link #ObjectName(String) new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * ObjectName(name)} can be used.  The returned object may be of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * a subclass of ObjectName.  Calling this method twice with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * same parameters may return the same object or two equal but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * not identical objects.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * @param name  A string representation of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * @return an ObjectName corresponding to the given String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * @exception MalformedObjectNameException The string passed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * parameter does not have the right format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * @exception NullPointerException The <code>name</code> parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    public static ObjectName getInstance(String name)
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1272
            throws MalformedObjectNameException, NullPointerException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        return new ObjectName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
     * <p>Return an instance of ObjectName that can be used anywhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * an object obtained with {@link #ObjectName(String, String,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * String) new ObjectName(domain, key, value)} can be used.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * returned object may be of a subclass of ObjectName.  Calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * this method twice with the same parameters may return the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * object or two equal but not identical objects.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * @param domain  The domain part of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * @param key  The attribute in the key property of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * @param value The value in the key property of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * @return an ObjectName corresponding to the given domain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * key, and value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * @exception MalformedObjectNameException The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * <code>domain</code>, <code>key</code>, or <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * contains an illegal character, or <code>value</code> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * follow the rules for quoting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * @exception NullPointerException One of the parameters is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    public static ObjectName getInstance(String domain, String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                                         String value)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1300
            throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        return new ObjectName(domain, key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * <p>Return an instance of ObjectName that can be used anywhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * an object obtained with {@link #ObjectName(String, Hashtable)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * new ObjectName(domain, table)} can be used.  The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * object may be of a subclass of ObjectName.  Calling this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * twice with the same parameters may return the same object or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * two equal but not identical objects.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     * @param domain  The domain part of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * @param table A hash table containing one or more key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * properties.  The key of each entry in the table is the key of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * key property in the object name.  The associated value in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * table is the associated value in the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * @return an ObjectName corresponding to the given domain and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * key mappings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * @exception MalformedObjectNameException The <code>domain</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * contains an illegal character, or one of the keys or values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * <code>table</code> contains an illegal character, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * values in <code>table</code> does not follow the rules for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * quoting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * @exception NullPointerException One of the parameters is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    public static ObjectName getInstance(String domain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                                         Hashtable<String,String> table)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1331
        throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        return new ObjectName(domain, table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * <p>Return an instance of ObjectName that can be used anywhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * the given object can be used.  The returned object may be of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     * subclass of ObjectName.  If <code>name</code> is of a subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * of ObjectName, it is not guaranteed that the returned object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * will be of the same class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * <p>The returned value may or may not be identical to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * <code>name</code>.  Calling this method twice with the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * parameters may return the same object or two equal but not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * identical objects.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * <p>Since ObjectName is immutable, it is not usually useful to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * make a copy of an ObjectName.  The principal use of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * is to guard against a malicious caller who might pass an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * instance of a subclass with surprising behavior to sensitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * code.  Such code can call this method to obtain an ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * that is known not to have surprising behavior.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * @param name an instance of the ObjectName class or of a subclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * @return an instance of ObjectName or a subclass that is known to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * have the same semantics.  If <code>name</code> respects the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * semantics of ObjectName, then the returned object is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * (though not necessarily identical) to <code>name</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @exception NullPointerException The <code>name</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     */
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1364
    public static ObjectName getInstance(ObjectName name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
        if (name.getClass().equals(ObjectName.class))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
            return name;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1367
        return Util.newObjectName(name.getSerializedNameString());
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  1368
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  1369
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  1370
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * Construct an object name from the given string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * @param name  A string representation of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * @exception MalformedObjectNameException The string passed as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     * parameter does not have the right format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * @exception NullPointerException The <code>name</code> parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    public ObjectName(String name)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1381
        throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        construct(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * Construct an object name with exactly one key property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * @param domain  The domain part of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * @param key  The attribute in the key property of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * @param value The value in the key property of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * @exception MalformedObjectNameException The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * <code>domain</code>, <code>key</code>, or <code>value</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * contains an illegal character, or <code>value</code> does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     * follow the rules for quoting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * @exception NullPointerException One of the parameters is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    public ObjectName(String domain, String key, String value)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1399
        throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        // If key or value are null a NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        // will be thrown by the put method in Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        Map<String,String> table = Collections.singletonMap(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        construct(domain, table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * Construct an object name with several key properties from a Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * @param domain  The domain part of the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * @param table A hash table containing one or more key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * properties.  The key of each entry in the table is the key of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * key property in the object name.  The associated value in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * table is the associated value in the object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * @exception MalformedObjectNameException The <code>domain</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * contains an illegal character, or one of the keys or values in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * <code>table</code> contains an illegal character, or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * values in <code>table</code> does not follow the rules for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * quoting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @exception NullPointerException One of the parameters is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    public ObjectName(String domain, Hashtable<String,String> table)
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1424
            throws MalformedObjectNameException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        construct(domain, table);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        /* The exception for when a key or value in the table is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
           String is now ClassCastException rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
           MalformedObjectNameException.  This was not previously
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
           specified.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
    // Category : ObjectName Construction <==============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    // Category : Getter methods ------------------------------>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * Checks whether the object name is a pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * An object name is a pattern if its domain contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * wildcard or if the object name is a property pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * @return  True if the name is a pattern, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
    public boolean isPattern() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        return (_domain_pattern ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                _property_list_pattern ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                _property_value_pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * Checks whether the object name is a pattern on the domain part.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     * @return  True if the name is a domain pattern, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    public boolean isDomainPattern() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        return _domain_pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * Checks whether the object name is a pattern on the key properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     * An object name is a pattern on the key properties if it is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * pattern on the key property list (e.g. "d:k=v,*") or on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * property values (e.g. "d:k=*") or on both (e.g. "d:k=*,*").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * @return  True if the name is a property pattern, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
    public boolean isPropertyPattern() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        return _property_list_pattern || _property_value_pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * Checks whether the object name is a pattern on the key property list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * For example, "d:k=v,*" and "d:k=*,*" are key property list patterns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * whereas "d:k=*" is not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * @return  True if the name is a property list pattern, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
    public boolean isPropertyListPattern() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
        return _property_list_pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
     * Checks whether the object name is a pattern on the value part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
     * of at least one of the key properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
     * For example, "d:k=*" and "d:k=*,*" are property value patterns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
     * whereas "d:k=v,*" is not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
     * @return  True if the name is a property value pattern, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
    public boolean isPropertyValuePattern() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        return _property_value_pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     * Checks whether the value associated with a key in a key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * property is a pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * @param property The property whose value is to be checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * @return True if the value associated with the given key property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * is a pattern, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * @exception NullPointerException If <code>property</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * @exception IllegalArgumentException If <code>property</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * a valid key property for this ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     */
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1518
    public boolean isPropertyValuePattern(String property) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        if (property == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            throw new NullPointerException("key property can't be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        for (int i = 0; i < _ca_array.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            Property prop = _ca_array[i];
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1523
            String key = prop.getKeyString(_canonicalName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
            if (key.equals(property))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                return (prop instanceof PatternProperty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        throw new IllegalArgumentException("key property not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
     * <p>Returns the canonical form of the name; that is, a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
     * representation where the properties are sorted in lexical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
     * order.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
     * <p>More precisely, the canonical form of the name is a String
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
     * consisting of the <em>domain part</em>, a colon
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
     * (<code>:</code>), the <em>canonical key property list</em>, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
     * a <em>pattern indication</em>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
     * <p>The <em>canonical key property list</em> is the same string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
     * as described for {@link #getCanonicalKeyPropertyListString()}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
     * <p>The <em>pattern indication</em> is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
     * <li>empty for an ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
     * that is not a property list pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
     * <li>an asterisk for an ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
     * that is a property list pattern with no keys; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
     * <li>a comma and an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
     * asterisk (<code>,*</code>) for an ObjectName that is a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
     * list pattern with at least one key.
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 7038
diff changeset
  1552
     * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
     * @return The canonical form of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    public String getCanonicalName()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
        return _canonicalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
     * Returns the domain part.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
     * @return The domain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    public String getDomain()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        return _canonicalName.substring(0, _domain_length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
     * Obtains the value associated with a key in a key property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * @param property The property whose value is to be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * @return The value of the property, or null if there is no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * property in this ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * @exception NullPointerException If <code>property</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     */
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1579
    public String getKeyProperty(String property) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
        return _getKeyPropertyList().get(property);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * <p>Returns the key properties as a Map.  The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * value is a Map in which each key is a key in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * ObjectName's key property list and each value is the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * value.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * <p>The returned value must not be modified.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * @return The table of key properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
    private Map<String,String> _getKeyPropertyList()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
            if (_propertyList == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                // build (lazy eval) the property list from the canonical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                // properties array
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                _propertyList = new HashMap<String,String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                int len = _ca_array.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                Property prop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                for (int i = len - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                    prop = _ca_array[i];
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1603
                    _propertyList.put(prop.getKeyString(_canonicalName),
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1604
                                      prop.getValueString(_canonicalName));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        return _propertyList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * <p>Returns the key properties as a Hashtable.  The returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * value is a Hashtable in which each key is a key in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * ObjectName's key property list and each value is the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * value.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     * <p>The returned value may be unmodifiable.  If it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
     * modifiable, changing it has no effect on this ObjectName.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
     * @return The table of key properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    // CR 6441274 depends on the modification property defined above
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
    public Hashtable<String,String> getKeyPropertyList()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        return new Hashtable<String,String>(_getKeyPropertyList());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     * <p>Returns a string representation of the list of key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     * properties specified at creation time.  If this ObjectName was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * constructed with the constructor {@link #ObjectName(String)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * the key properties in the returned String will be in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * order as in the argument to the constructor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     * @return The key property list string.  This string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
     * independent of whether the ObjectName is a pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    public String getKeyPropertyListString()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        // BEWARE : we rebuild the propertyliststring at each call !!
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        if (_kp_array.length == 0) return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        // the size of the string is the canonical one minus domain
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        // part and pattern part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        final int total_size = _canonicalName.length() - _domain_length - 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            - (_property_list_pattern?2:0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        final char[] dest_chars = new char[total_size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        final char[] value = _canonicalName.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
        writeKeyPropertyListString(value,dest_chars,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        return new String(dest_chars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
     * <p>Returns the serialized string of the ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
     * properties specified at creation time.  If this ObjectName was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
     * constructed with the constructor {@link #ObjectName(String)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
     * the key properties in the returned String will be in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
     * order as in the argument to the constructor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * @return The key property list string.  This string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * independent of whether the ObjectName is a pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
    private String getSerializedNameString()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        // the size of the string is the canonical one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        final int total_size = _canonicalName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        final char[] dest_chars = new char[total_size];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        final char[] value = _canonicalName.toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        final int offset = _domain_length+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        // copy "domain:" into dest_chars
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        System.arraycopy(value, 0, dest_chars, 0, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
        // Add property list string
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        final int end = writeKeyPropertyListString(value,dest_chars,offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        // Add ",*" if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
        if (_property_list_pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            if (end == offset)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                // Property list string is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                dest_chars[end] = '*';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                // Property list string is not empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                dest_chars[end]   = ',';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                dest_chars[end+1] = '*';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1689
        return new String(dest_chars);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     * <p>Write a string representation of the list of key
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
     * properties specified at creation time in the given array, starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
     * at the specified offset.  If this ObjectName was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
     * constructed with the constructor {@link #ObjectName(String)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * the key properties in the returned String will be in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * order as in the argument to the constructor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     * @return offset + #of chars written
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    private int writeKeyPropertyListString(char[] canonicalChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                                           char[] data, int offset)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        if (_kp_array.length == 0) return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        final char[] dest_chars = data;
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  1707
        final char[] value = canonicalChars;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
        int index = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        final int len = _kp_array.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
        final int last = len - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
            final Property prop = _kp_array[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
            final int prop_len = prop._key_length + prop._value_length + 1;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1715
            System.arraycopy(value, prop._key_index, dest_chars, index,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                             prop_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
            index += prop_len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
            if (i < last ) dest_chars[index++] = ',';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
        return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * Returns a string representation of the list of key properties,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * in which the key properties are sorted in lexical order. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * is used in lexicographic comparisons performed in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * select MBeans based on their key property list.  Lexical order
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * is the order implied by {@link String#compareTo(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * String.compareTo(String)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * @return The canonical key property list string.  This string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * independent of whether the ObjectName is a pattern.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
    public String getCanonicalKeyPropertyListString()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        if (_ca_array.length == 0) return "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        int len = _canonicalName.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        if (_property_list_pattern) len -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        return _canonicalName.substring(_domain_length +1, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    // Category : Getter methods <===================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    // Category : Utilities ---------------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * <p>Returns a string representation of the object name.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * format of this string is not specified, but users can expect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * that two ObjectNames return the same string if and only if they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * are equal.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * @return a string representation of this object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     */
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
  1755
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    public String toString()  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        return getSerializedNameString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * Compares the current object name with another object name.  Two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * ObjectName instances are equal if and only if their canonical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * forms are equal.  The canonical form is the string described
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * for {@link #getCanonicalName()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * @param object  The object name that the current object name is to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     *        compared with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * @return True if <code>object</code> is an ObjectName whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     * canonical form is equal to that of this ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     */
1005
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1772
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
    public boolean equals(Object object)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        // same object case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        if (this == object) return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        // object is not an object name case
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
        if (!(object instanceof ObjectName)) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
        // equality when canonical names are the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        // (because usage of intern())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
        ObjectName on = (ObjectName) object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        String on_string = on._canonicalName;
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  1785
        if (_canonicalName == on_string) return true;  // ES: OK
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
        // Because we are sharing canonical form between object names,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
        // we have finished the comparison at this stage ==> unequal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * Returns a hash code for this object name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     */
1005
1a39b4e3f2fc 6616825: JMX query returns no value in 1.0 compatibility mode - deserialization bug in readObject()
dfuchs
parents: 715
diff changeset
  1796
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
        return _canonicalName.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * <p>Returns a quoted form of the given String, suitable for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * inclusion in an ObjectName.  The returned value can be used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * the value associated with a key in an ObjectName.  The String
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * <code>s</code> may contain any character.  Appropriate quoting
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * ensures that the returned value is legal in an ObjectName.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * <p>The returned value consists of a quote ('"'), a sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * characters corresponding to the characters of <code>s</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * and another quote.  Characters in <code>s</code> appear
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * unchanged within the returned value except:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * <li>A quote ('"') is replaced by a backslash (\) followed by a quote.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * <li>An asterisk ('*') is replaced by a backslash (\) followed by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * asterisk.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * <li>A question mark ('?') is replaced by a backslash (\) followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * a question mark.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * <li>A backslash ('\') is replaced by two backslashes.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * <li>A newline character (the character '\n' in Java) is replaced
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * by a backslash followed by the character '\n'.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * @param s the String to be quoted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * @return the quoted String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * @exception NullPointerException if <code>s</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     */
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1831
    public static String quote(String s) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
        final StringBuilder buf = new StringBuilder("\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
        final int len = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
        for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
            char c = s.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
            switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                c = 'n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                buf.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
            case '\\':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            case '\"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                buf.append('\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
            buf.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        buf.append('"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     * <p>Returns an unquoted form of the given String.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * <code>q</code> is a String returned by {@link #quote quote(s)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * then <code>unquote(q).equals(s)</code>.  If there is no String
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * <code>s</code> for which <code>quote(s).equals(q)</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * unquote(q) throws an IllegalArgumentException.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * <p>These rules imply that there is a one-to-one mapping between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * quoted and unquoted forms.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     * @param q the String to be unquoted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     * @return the unquoted String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     * @exception IllegalArgumentException if <code>q</code> could not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * have been returned by the {@link #quote} method, for instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     * if it does not begin and end with a quote (").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     * @exception NullPointerException if <code>q</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     */
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1875
    public static String unquote(String q) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
        final StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
        final int len = q.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
        if (len < 2 || q.charAt(0) != '"' || q.charAt(len - 1) != '"')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
            throw new IllegalArgumentException("Argument not quoted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
        for (int i = 1; i < len - 1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
            char c = q.charAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
            if (c == '\\') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                if (i == len - 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                    throw new IllegalArgumentException("Trailing backslash");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                c = q.charAt(++i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                case 'n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                    c = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                case '\\':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                case '\"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                case '*':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                case '?':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                  throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                                   "Bad character '" + c + "' after backslash");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                switch (c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                    case '*' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                    case '?' :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                    case '\"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                    case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                         throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                                          "Invalid unescaped character '" + c +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                                          "' in the string to unquote");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
            buf.append(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     * Defines the wildcard "*:*" ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     */
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1920
    public static final ObjectName WILDCARD = Util.newObjectName("*:*");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
    // Category : Utilities <===================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
    // Category : QueryExp Interface ---------------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * <p>Test whether this ObjectName, which may be a pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * matches another ObjectName.  If <code>name</code> is a pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * the result is false.  If this ObjectName is a pattern, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * result is true if and only if <code>name</code> matches the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     * pattern.  If neither this ObjectName nor <code>name</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * a pattern, the result is true if and only if the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     * ObjectNames are equal as described for the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * #equals(Object)} method.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * @param name The name of the MBean to compare to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * @return True if <code>name</code> matches this ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     * @exception NullPointerException if <code>name</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     */
1225
6ef6227d36eb 6734813: Provide a way to construct an ObjectName without checked exceptions
emcmanus
parents: 1156
diff changeset
  1943
    public boolean apply(ObjectName name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        if (name == null) throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
        if (name._domain_pattern ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            name._property_list_pattern ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            name._property_value_pattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
        // No pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        if (!_domain_pattern &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            !_property_list_pattern &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
            !_property_value_pattern)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            return _canonicalName.equals(name._canonicalName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        return matchDomains(name) && matchKeys(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
    private final boolean matchDomains(ObjectName name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        if (_domain_pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
            // wildmatch domains
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  1964
            // This ObjectName is the pattern
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  1965
            // The other ObjectName is the string.
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1966
            return Util.wildmatch(name.getDomain(),getDomain());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        return getDomain().equals(name.getDomain());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    private final boolean matchKeys(ObjectName name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        // If key property value pattern but not key property list
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        // pattern, then the number of key properties must be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
        if (_property_value_pattern &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            !_property_list_pattern &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            (name._ca_array.length != _ca_array.length))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        // If key property value pattern or key property list pattern,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
        // then every property inside pattern should exist in name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
        if (_property_value_pattern || _property_list_pattern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
            final Map<String,String> nameProps = name._getKeyPropertyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            final Property[] props = _ca_array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            final String cn = _canonicalName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            for (int i = props.length - 1; i >= 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                // Find value in given object name for key at current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                // index in receiver
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                final Property p = props[i];
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  1992
                final String   k = p.getKeyString(cn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                final String   v = nameProps.get(k);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
                // Did we find a value for this key ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                if (v == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                // If this property is ok (same key, same value), go to next
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                if (_property_value_pattern && (p instanceof PatternProperty)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                    // wildmatch key property values
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  2001
                    // p is the property pattern, v is the string
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  2002
                    if (Util.wildmatch(v,p.getValueString(cn)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                }
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1709
diff changeset
  2007
                if (v.equals(p.getValueString(cn))) continue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
        // If no pattern, then canonical names must be equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        final String p1 = name.getCanonicalKeyPropertyListString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
        final String p2 = getCanonicalKeyPropertyListString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        return (p1.equals(p2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
    /* Method inherited from QueryExp, no implementation needed here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
       because ObjectName is not relative to an MBeanServer and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
       not contain a subquery.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
    public void setMBeanServer(MBeanServer mbs) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
    // Category : QueryExp Interface <=========================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
    // Category : Comparable Interface ---------------------------------------->
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * <p>Compares two ObjectName instances. The ordering relation between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     * ObjectNames is not completely specified but is intended to be such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * that a sorted list of ObjectNames will appear in an order that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     * convenient for a person to read.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     * <p>In particular, if the two ObjectName instances have different
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * domains then their order is the lexicographical order of the domains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * The ordering of the key property list remains unspecified.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * <p>For example, the ObjectName instances below:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * <li>Shapes:type=Square,name=3</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * <li>Colors:type=Red,name=2</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * <li>Shapes:type=Triangle,side=isosceles,name=2</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * <li>Colors:type=Red,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * <li>Shapes:type=Square,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * <li>Colors:type=Blue,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * <li>Shapes:type=Square,name=2</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * <li>JMImplementation:type=MBeanServerDelegate</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * <li>Shapes:type=Triangle,side=scalene,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     * <p>could be ordered as follows:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * <li>Colors:type=Blue,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * <li>Colors:type=Red,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * <li>Colors:type=Red,name=2</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * <li>JMImplementation:type=MBeanServerDelegate</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     * <li>Shapes:type=Square,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     * <li>Shapes:type=Square,name=2</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * <li>Shapes:type=Square,name=3</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * <li>Shapes:type=Triangle,side=scalene,name=1</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     * <li>Shapes:type=Triangle,side=isosceles,name=2</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * @param name the ObjectName to be compared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     * @return a negative integer, zero, or a positive integer as this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     *         ObjectName is less than, equal to, or greater than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     *         specified ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    public int compareTo(ObjectName name) {
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  2074
        // Quick optimization:
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  2075
        //
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  2076
        if (name == this) return 0;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents: 1005
diff changeset
  2077
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
        // (1) Compare domains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
        int domainValue = this.getDomain().compareTo(name.getDomain());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        if (domainValue != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            return domainValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        // (2) Compare "type=" keys
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        // Within a given domain, all names with missing or empty "type="
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        // come before all names with non-empty type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        // When both types are missing or empty, canonical-name ordering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
        // applies which is a total order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
        String thisTypeKey = this.getKeyProperty("type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
        String anotherTypeKey = name.getKeyProperty("type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
        if (thisTypeKey == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            thisTypeKey = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
        if (anotherTypeKey == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            anotherTypeKey = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        int typeKeyValue = thisTypeKey.compareTo(anotherTypeKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
        if (typeKeyValue != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
            return typeKeyValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
        // (3) Compare canonical names
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
        return this.getCanonicalName().compareTo(name.getCanonicalName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
    // Category : Comparable Interface <=========================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
    // Public methods <========================================
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
}