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