src/java.naming/share/classes/javax/naming/CompositeName.java
author herrick
Tue, 24 Sep 2019 13:41:16 -0400
branchJDK-8200758-branch
changeset 58301 e0efb29609bd
parent 54126 478f1483c511
permissions -rw-r--r--
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code Submitted-by: asemenyuk Reviewed-by: herrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54126
478f1483c511 8220252: Fix Headings in java.naming
lancea
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2019, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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.naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * This class represents a composite name -- a sequence of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * component names spanning multiple namespaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Each component is a string name from the namespace of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * naming system. If the component comes from a hierarchical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * namespace, that component can be further parsed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * its atomic parts by using the CompoundName class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The components of a composite name are numbered.  The indexes of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * composite name with N components range from 0 up to, but not including, N.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * This range may be written as [0,N).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * The most significant component is at index 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * An empty composite name has no components.
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
    44
 *
54126
478f1483c511 8220252: Fix Headings in java.naming
lancea
parents: 47216
diff changeset
    45
 * <h2>JNDI Composite Name Syntax</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * JNDI defines a standard string representation for composite names. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * representation is the concatenation of the components of a composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * from left to right using the component separator (a forward
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * slash character (/)) to separate each component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The JNDI syntax defines the following meta characters:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <li>escape (backward slash \),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <li>quote characters  (single (') and double quotes (")), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <li>component separator (forward slash character (/)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Any occurrence of a leading quote, an escape preceding any meta character,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * an escape at the end of a component, or a component separator character
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * in an unquoted component must be preceded by an escape character when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * that component is being composed into a composite name string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * Alternatively, to avoid adding escape characters as described,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * the entire component can be quoted using matching single quotes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * or matching double quotes. A single quote occurring within a double-quoted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * component is not considered a meta character (and need not be escaped),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * When two composite names are compared, the case of the characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * is significant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * A leading component separator (the composite name string begins with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * a separator) denotes a leading empty component (a component consisting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * of an empty string).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * A trailing component separator (the composite name string ends with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * a separator) denotes a trailing empty component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * Adjacent component separators denote an empty component.
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
    75
 *
54126
478f1483c511 8220252: Fix Headings in java.naming
lancea
parents: 47216
diff changeset
    76
 *<h2>Composite Name Examples</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *This table shows examples of some composite names. Each row shows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *the string form of a composite name and its corresponding structural form
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    79
 *({@code CompositeName}).
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
    80
 *
45132
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 32029
diff changeset
    81
<table class="striped"><caption style="display:none">examples showing string
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 32029
diff changeset
    82
 form of composite name and its corresponding structural form (CompositeName)</caption>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    83
<thead>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    85
<th scope="col">String Name</th>
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    86
<th scope="col">CompositeName</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
</tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    88
</thead>
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    89
<tbody style="text-align:left">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    91
<th scope="row">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
""
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    93
</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
<td>{} (the empty name == new CompositeName("") == new CompositeName())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
    99
<th scope="row">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
"x"
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   101
</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
<td>{"x"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   107
<th scope="row">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
"x/y"
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   109
</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
<td>{"x", "y"}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   114
<th scope="row">"x/"</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
<td>{"x", ""}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   119
<th scope="row">"/x"</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
<td>{"", "x"}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   124
<th scope="row">"/"</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
<td>{""}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   129
<th scope="row">"//"</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
<td>{"", ""}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   133
<tr><th scope="row">"/x/"</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
<td>{"", "x", ""}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   137
<tr><th scope="row">"x//y"</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
<td>{"x", "", "y"}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
</tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   140
</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
</table>
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
   142
 *
54126
478f1483c511 8220252: Fix Headings in java.naming
lancea
parents: 47216
diff changeset
   143
 *<h2>Composition Examples</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * Here are some composition examples.  The right column shows composing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * string composite names while the left column shows composing the
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   146
 * corresponding {@code CompositeName}s.  Notice that composing the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * string forms of two composite names simply involves concatenating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * their string forms together.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
45132
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 32029
diff changeset
   150
<table class="striped"><caption style="display:none">composition examples
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 32029
diff changeset
   151
 showing string names and composite names</caption>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   152
<thead>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   154
<th scope="col">String Names</th>
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   155
<th scope="col">CompositeNames</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
</tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   157
</thead>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   159
<tbody style="text-align:left">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   161
<th scope="row">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
"x/y"           + "/"   = x/y/
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   163
</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
<td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
{"x", "y"}      + {""}  = {"x", "y", ""}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   170
<th scope="row">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
""              + "x"   = "x"
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   172
</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
<td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
{}              + {"x"} = {"x"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   179
<th scope="row">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
"/"             + "x"   = "/x"
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   181
</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
<td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
{""}            + {"x"} = {"", "x"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
</tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
<tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   188
<th scope="row">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
"x"   + ""      + ""    = "x"
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   190
</th>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
<td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
{"x"} + {}      + {}    = {"x"}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
</tr>
47029
7d0ceae2dec2 8186934: Fix accessibility issues in the java.naming module
jjg
parents: 45132
diff changeset
   195
</tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
</table>
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
   197
 *
54126
478f1483c511 8220252: Fix Headings in java.naming
lancea
parents: 47216
diff changeset
   198
 *<h2>Multithreaded Access</h2>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   199
 * A {@code CompositeName} instance is not synchronized against concurrent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 * multithreaded access. Multiple threads trying to access and modify a
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   201
 * {@code CompositeName} should lock the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
public class CompositeName implements Name {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    private transient NameImpl impl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      * Constructs a new composite name instance using the components
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   214
      * specified by 'comps'. This protected method is intended
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      * to be used by subclasses of CompositeName when they override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      * methods such as clone(), getPrefix(), getSuffix().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      * @param comps A non-null enumeration containing the components for the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      *              composite name. Each element is of class String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      *               The enumeration will be consumed to extract its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
      *               elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    protected CompositeName(Enumeration<String> comps) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        impl = new NameImpl(null, comps); // null means use default syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      * Constructs a new composite name instance by parsing the string n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
      * using the composite name syntax (left-to-right, slash separated).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      * The composite name syntax is described in detail in the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      * description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
      * @param  n       The non-null string to parse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      * @exception InvalidNameException If n has invalid composite name syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public CompositeName(String n) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        impl = new NameImpl(null, n);  // null means use default syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      * Constructs a new empty composite name. Such a name returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      * when <code>isEmpty()</code> is invoked on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public CompositeName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        impl = new NameImpl(null);  // null means use default syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      * Generates the string representation of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      * The string representation consists of enumerating in order
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      * each component of the composite name and separating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      * each component by a forward slash character. Quoting and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      * escape characters are applied where necessary according to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      * the JNDI syntax, which is described in the class description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      * An empty component is represented by an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      * The string representation thus generated can be passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      * the CompositeName constructor to create a new equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      * composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      * @return A non-null string representation of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return impl.toString();
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
      * Determines whether two composite names are equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      * If obj is null or not a composite name, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      * Two composite names are equal if each component in one is equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      * to the corresponding component in the other. This implies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      * both have the same number of components, and each component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      * equals() test against the corresponding component in the other name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      * returns true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
      * @param  obj     The possibly null object to compare against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
      * @return true if obj is equal to this composite name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
      * @see #hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        return (obj != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                obj instanceof CompositeName &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                impl.equals(((CompositeName)obj).impl));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      * Computes the hash code of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      * The hash code is the sum of the hash codes of individual components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
      * of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
      * @return An int representing the hash code of this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
      * @see #equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return impl.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Compares this CompositeName with the specified Object for order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * negative integer, zero, or a positive integer as this Name is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * than, equal to, or greater than the given Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * If obj is null or not an instance of CompositeName, ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * See equals() for what it means for two composite names to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * If two composite names are equal, 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * Ordering of composite names follows the lexicographical rules for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * string comparison, with the extension that this applies to all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * the components in the composite name. The effect is as if all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * components were lined up in their specified ordered and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * lexicographical rules applied over the two line-ups.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * If this composite name is "lexicographically" lesser than obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * a negative number is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * If this composite name is "lexicographically" greater than obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * a positive number is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @param obj The non-null object to compare against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @return  a negative integer, zero, or a positive integer as this Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     *          is less than, equal to, or greater than the given Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * @exception ClassCastException if obj is not a CompositeName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public int compareTo(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (!(obj instanceof CompositeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            throw new ClassCastException("Not a CompositeName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return impl.compareTo(((CompositeName)obj).impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
      * Generates a copy of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
      * Changes to the components of this composite name won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
      * affect the new copy and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      * @return A non-null copy of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return (new CompositeName(getAll()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
      * Retrieves the number of components in this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
      * @return The nonnegative number of components in this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        return (impl.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
      * Determines whether this composite name is empty. A composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
      * is empty if it has zero components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
      * @return true if this composite name is empty, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return (impl.isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
      * Retrieves the components of this composite name as an enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
      * of strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      * The effects of updates to this composite name on this enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
      * is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      * @return A non-null enumeration of the components of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      *         this composite name. Each element of the enumeration is of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
      *         class String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public Enumeration<String> getAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return (impl.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
      * Retrieves a component of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
      * @param  posn    The 0-based index of the component to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
      *                 Must be in the range [0,size()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
      * @return The non-null component at index posn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
      * @exception ArrayIndexOutOfBoundsException if posn is outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
      *         specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public String get(int posn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        return (impl.get(posn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
      * Creates a composite name whose components consist of a prefix of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      * components in this composite name. Subsequent changes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
      * this composite name does not affect the name that is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      * @param  posn    The 0-based index of the component at which to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
      * @return A composite name consisting of the components at indexes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
      *         the range [0,posn).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public Name getPrefix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   403
        Enumeration<String> comps = impl.getPrefix(posn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return (new CompositeName(comps));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
      * Creates a composite name whose components consist of a suffix of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
      * components in this composite name. Subsequent changes to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
      * this composite name does not affect the name that is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
      * @param  posn    The 0-based index of the component at which to start.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
      * @return A composite name consisting of the components at indexes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
      *         the range [posn,size()).  If posn is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
      *         size(), an empty composite name is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public Name getSuffix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   421
        Enumeration<String> comps = impl.getSuffix(posn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return (new CompositeName(comps));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      * Determines whether a composite name is a prefix of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      * A composite name 'n' is a prefix if it is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      * getPrefix(n.size())--in other words, this composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      * starts with 'n'. If 'n' is null or not a composite name, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      * @param  n       The possibly null name to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
      * @return true if n is a CompositeName and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
      *         is a prefix of this composite name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public boolean startsWith(Name n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if (n instanceof CompositeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return (impl.startsWith(n.size(), n.getAll()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
      * Determines whether a composite name is a suffix of this composite name.
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   445
      * A composite name 'n' is a suffix if it is equal to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      * getSuffix(size()-n.size())--in other words, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
      * composite name ends with 'n'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      * If n is null or not a composite name, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
      * @param  n       The possibly null name to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
      * @return true if n is a CompositeName and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
      *         is a suffix of this composite name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public boolean endsWith(Name n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (n instanceof CompositeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            return (impl.endsWith(n.size(), n.getAll()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
      * Adds the components of a composite name -- in order -- to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
      * this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
      * @param suffix   The non-null components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
      * @return The updated CompositeName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
      * @exception InvalidNameException If suffix is not a composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public Name addAll(Name suffix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        throws InvalidNameException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        if (suffix instanceof CompositeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            impl.addAll(suffix.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            throw new InvalidNameException("Not a composite name: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                suffix.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      * Adds the components of a composite name -- in order -- at a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
      * position within this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
      * Components of this composite name at or after the index of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
      * new component are shifted up (away from index 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
      * to accommodate the new components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
      * @param n        The non-null components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
      * @param posn     The index in this name at which to add the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
      *                 components.  Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
      * @return The updated CompositeName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
      * @exception InvalidNameException If n is not a composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public Name addAll(int posn, Name n)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        throws InvalidNameException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (n instanceof CompositeName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            impl.addAll(posn, n.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            throw new InvalidNameException("Not a composite name: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                n.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
      * Adds a single component to the end of this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      * @param comp     The non-null component to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      * @return The updated CompositeName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      * @exception InvalidNameException If adding comp at end of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
      *                         would violate the name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public Name add(String comp) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        impl.add(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
      * Adds a single component at a specified position within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
      * composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
      * Components of this composite name at or after the index of the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
      * component are shifted up by one (away from index 0) to accommodate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
      * the new component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
      * @param  comp    The non-null component to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
      * @param  posn    The index at which to add the new component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
      * @return The updated CompositeName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
      * @exception InvalidNameException If adding comp at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
      *                         would violate the name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public Name add(int posn, String comp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        throws InvalidNameException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        impl.add(posn, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
      * Deletes a component from this composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
      * The component of this composite name at position 'posn' is removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
      * and components at indices greater than 'posn'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
      * are shifted down (towards index 0) by one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
      * @param  posn    The index of the component to delete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
      *                 Must be in the range [0,size()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
      * @return The component removed (a String).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
      *         If posn is outside the specified range (includes case where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
      *         composite name is empty).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
      * @exception InvalidNameException If deleting the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
      *                         would violate the name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    public Object remove(int posn) throws InvalidNameException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        return impl.remove(posn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * Overridden to avoid implementation dependency.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   566
     * @serialData The number of components (an {@code int}) followed by
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   567
     * the individual components (each a {@code String}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        s.writeInt(size());
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   572
        Enumeration<String> comps = getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        while (comps.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            s.writeObject(comps.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * Overridden to avoid implementation dependency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        impl = new NameImpl(null);  // null means use default syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        int n = s.readInt();    // number of components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            while (--n >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                add((String)s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            throw (new java.io.StreamCorruptedException("Invalid name"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    private static final long serialVersionUID = 1667768148915813118L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    // %%% Test code for serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        CompositeName c = new CompositeName("aaa/bbb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        java.io.FileOutputStream f1 = new java.io.FileOutputStream("/tmp/ser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        java.io.ObjectOutputStream s1 = new java.io.ObjectOutputStream(f1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        s1.writeObject(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        s1.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        java.io.FileInputStream f2 = new java.io.FileInputStream("/tmp/ser");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        java.io.ObjectInputStream s2 = new java.io.ObjectInputStream(f2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        c = (CompositeName)s2.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        System.out.println("Size: " + c.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        System.out.println("Size: " + c.snit);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
   %%% Testing code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            for (int i = 0; i < args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                Name name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                Enumeration e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                System.out.println("Given name: " + args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                name = new CompositeName(args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                e = name.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    System.out.println("Element: " + e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                System.out.println("Constructed name: " + name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        } catch (Exception ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            ne.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
}