src/java.naming/share/classes/javax/naming/CompoundName.java
author lancea
Thu, 14 Mar 2019 10:50:35 -0400
changeset 54126 478f1483c511
parent 47216 71c04702a3d5
permissions -rw-r--r--
8220252: Fix Headings in java.naming Reviewed-by: dfuchs
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 compound name -- a name from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * a hierarchical name space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Each component in a compound name is an atomic name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The components of a compound name are numbered.  The indexes of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * compound name with N components range from 0 up to, but not including, N.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This range may be written as [0,N).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The most significant component is at index 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * An empty compound name has no components.
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
    41
 *
54126
478f1483c511 8220252: Fix Headings in java.naming
lancea
parents: 47216
diff changeset
    42
 * <h2>Compound Name Syntax</h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The syntax of a compound name is specified using a set of properties:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *<dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  <dt>jndi.syntax.direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *  <dd>Direction for parsing ("right_to_left", "left_to_right", "flat").
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *      If unspecified, defaults to "flat", which means the namespace is flat
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *      with no hierarchical structure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *  <dt>jndi.syntax.separator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *  <dd>Separator between atomic name components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      Required unless direction is "flat".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *  <dt>jndi.syntax.ignorecase
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *  <dd>If present, "true" means ignore the case when comparing name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *      components. If its value is not "true", or if the property is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *      present, case is considered when comparing name components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *  <dt>jndi.syntax.escape
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *  <dd>If present, specifies the escape string for overriding separator,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *      escapes and quotes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *  <dt>jndi.syntax.beginquote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *  <dd>If present, specifies the string delimiting start of a quoted string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *  <dt>jndi.syntax.endquote
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *  <dd>String delimiting end of quoted string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *      If present, specifies the string delimiting the end of a quoted string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *      If not present, use syntax.beginquote as end quote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *  <dt>jndi.syntax.beginquote2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *  <dd>Alternative set of begin/end quotes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *  <dt>jndi.syntax.endquote2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *  <dd>Alternative set of begin/end quotes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *  <dt>jndi.syntax.trimblanks
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *  <dd>If present, "true" means trim any leading and trailing whitespaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      in a name component for comparison purposes. If its value is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *      "true", or if the property is not present, blanks are significant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *  <dt>jndi.syntax.separator.ava
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *  <dd>If present, specifies the string that separates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *      attribute-value-assertions when specifying multiple attribute/value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *      pairs. (e.g. ","  in age=65,gender=male).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *  <dt>jndi.syntax.separator.typeval
36439
e0fdb6c0bb65 8151065: Typo in javax.naming.CompoundName
prappo
parents: 32029
diff changeset
    85
 *  <dd>If present, specifies the string that separates attribute
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *              from value (e.g. "=" in "age=65")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *</dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * These properties are interpreted according to the following rules:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *<ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * In a string without quotes or escapes, any instance of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * separator delimits two atomic names. Each atomic name is referred
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * to as a <em>component</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * A separator, quote or escape is escaped if preceded immediately
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * (on the left) by the escape.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * If there are two sets of quotes, a specific begin-quote must be matched
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * by its corresponding end-quote.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * A non-escaped begin-quote which precedes a component must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * matched by a non-escaped end-quote at the end of the component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * A component thus quoted is referred to as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <em>quoted component</em>. It is parsed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * removing the being- and end- quotes, and by treating the intervening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * characters as ordinary characters unless one of the rules involving
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * quoted components listed below applies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * Quotes embedded in non-quoted components are treated as ordinary strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * and need not be matched.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * A separator that is escaped or appears between non-escaped
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * quotes is treated as an ordinary string and not a separator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * An escape string within a quoted component acts as an escape only when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * followed by the corresponding end-quote string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * This can be used to embed an escaped quote within a quoted component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * An escaped escape string is not treated as an escape string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * An escape string that does not precede a meta string (quotes or separator)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * and is not at the end of a component is treated as an ordinary string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 *<li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * A leading separator (the compound name string begins with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * a separator) denotes a leading empty atomic component (consisting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * of an empty string).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * A trailing separator (the compound name string ends with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * a separator) denotes a trailing empty atomic component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * Adjacent separators denote an empty atomic component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *</ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * The string form of the compound name follows the syntax described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * When the components of the compound name are turned into their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * string representation, the reserved syntax rules described above are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * applied (e.g. embedded separators are escaped or quoted)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * so that when the same string is parsed, it will yield the same components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * of the original compound name.
21285
e740104a04f1 8026840: Fix new doclint issues in javax.naming
darcy
parents: 18580
diff changeset
   138
 *
54126
478f1483c511 8220252: Fix Headings in java.naming
lancea
parents: 47216
diff changeset
   139
 *<h2>Multithreaded Access</h2>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   140
 * A {@code CompoundName} instance is not synchronized against concurrent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * 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
   142
 * {@code CompoundName} should lock the object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
public class CompoundName implements Name {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
43536
8212439a528c 8167178: Exported elements referring to inaccessible types in java.naming
vtewari
parents: 36439
diff changeset
   152
     * Implementation of this compound name. This field is initialized by the
8212439a528c 8167178: Exported elements referring to inaccessible types in java.naming
vtewari
parents: 36439
diff changeset
   153
     * constructors and cannot be null.
8212439a528c 8167178: Exported elements referring to inaccessible types in java.naming
vtewari
parents: 36439
diff changeset
   154
     */
8212439a528c 8167178: Exported elements referring to inaccessible types in java.naming
vtewari
parents: 36439
diff changeset
   155
    private transient NameImpl impl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
      * Syntax properties for this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      * This field is initialized by the constructors and cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      * It should be treated as a read-only variable by subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      * Any necessary changes to mySyntax should be made within constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      * and not after the compound name has been instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    protected transient Properties mySyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
      * Constructs a new compound name instance using the components
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   167
      * specified in comps and syntax. This protected method is intended
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      * to be used by subclasses of CompoundName when they override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      * methods such as clone(), getPrefix(), getSuffix().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      * @param comps  A non-null enumeration of the components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      *   Each element of the enumeration is of class String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      *               The enumeration will be consumed to extract its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      *               elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      * @param syntax   A non-null properties that specify the syntax of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      *                 this compound name. See class description for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      *                 contents of properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    protected CompoundName(Enumeration<String> comps, Properties syntax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (syntax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        mySyntax = syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        impl = new NameImpl(syntax, comps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      * Constructs a new compound name instance by parsing the string n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      * using the syntax specified by the syntax properties supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      * @param  n       The non-null string to parse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      * @param syntax   A non-null list of properties that specify the syntax of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      *                 this compound name.  See class description for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      *                 contents of properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
      * @exception      InvalidNameException If 'n' violates the syntax specified
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   196
      *                 by {@code syntax}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public CompoundName(String n, Properties syntax) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (syntax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        mySyntax = syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        impl = new NameImpl(syntax, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      * Generates the string representation of this compound name, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
      * the syntax rules of the compound name. The syntax rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
      * are described in the class description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      * An empty component is represented by an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      * The string representation thus generated can be passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      * the CompoundName constructor with the same syntax properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      * to create a new equivalent compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      * @return A non-null string representation of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return (impl.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      * Determines whether obj is syntactically equal to this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
      * If obj is null or not a CompoundName, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
      * Two compound names are equal if each component in one is "equal"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      * to the corresponding component in the other.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      * Equality is also defined in terms of the syntax of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
      * The default implementation of CompoundName uses the syntax properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      * jndi.syntax.ignorecase and jndi.syntax.trimblanks when comparing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      * two components for equality.  If case is ignored, two strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
      * with the same sequence of characters but with different cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
      * are considered equal. If blanks are being trimmed, leading and trailing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      * blanks are ignored for the purpose of the comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      * Both compound names must have the same number of components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
      * Implementation note: Currently the syntax properties of the two compound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      * names are not compared for equality. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      * @param  obj     The possibly null object to compare against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      * @return true if obj is equal to this compound name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      * @see #compareTo(java.lang.Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        // %%% check syntax too?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return (obj != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                obj instanceof CompoundName &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                impl.equals(((CompoundName)obj).impl));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
      * Computes the hash code of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      * The hash code is the sum of the hash codes of the "canonicalized"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      * forms of individual components of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      * Each component is "canonicalized" according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      * compound name's syntax before its hash code is computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      * For a case-insensitive name, for example, the uppercased form of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      * a name has the same hash code as its lowercased equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      * @return An int representing the hash code of this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        return impl.hashCode();
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
      * Creates a copy of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      * Changes to the components of this compound name won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      * affect the new copy and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      * The clone and this compound name share the same syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      * @return A non-null copy of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return (new CompoundName(getAll(), mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Compares this CompoundName with the specified Object for order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * negative integer, zero, or a positive integer as this Name is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * than, equal to, or greater than the given Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * If obj is null or not an instance of CompoundName, ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * See equals() for what it means for two compound names to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * If two compound names are equal, 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Ordering of compound names depend on the syntax of the compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * By default, they follow lexicographical rules for string comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * with the extension that this applies to all the components in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * compound name and that comparison of individual components is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * affected by the jndi.syntax.ignorecase and jndi.syntax.trimblanks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * properties, identical to how they affect equals().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * If this compound name is "lexicographically" lesser than obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * a negative number is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * If this compound name is "lexicographically" greater than obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * a positive number is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Implementation note: Currently the syntax properties of the two compound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * names are not compared when checking order. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param   obj     The non-null object to compare against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return  a negative integer, zero, or a positive integer as this Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *          is less than, equal to, or greater than the given Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @exception ClassCastException if obj is not a CompoundName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see #equals(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    public int compareTo(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (!(obj instanceof CompoundName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            throw new ClassCastException("Not a CompoundName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return impl.compareTo(((CompoundName)obj).impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      * Retrieves the number of components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      * @return The nonnegative number of components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        return (impl.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
      * Determines whether this compound name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
      * A compound name is empty if it has zero components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
      * @return true if this compound name is empty, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        return (impl.isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
      * Retrieves the components of this compound name as an enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      * of strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      * The effects of updates to this compound name on this enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      * is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      * @return A non-null enumeration of the components of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
      * compound name. Each element of the enumeration is of class String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public Enumeration<String> getAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return (impl.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      * Retrieves a component of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      * @param  posn    The 0-based index of the component to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
      *                 Must be in the range [0,size()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
      * @return The component at index posn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
      * @exception ArrayIndexOutOfBoundsException if posn is outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
      *         specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public String get(int posn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return (impl.get(posn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
      * Creates a compound name whose components consist of a prefix of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
      * components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
      * The result and this compound name share the same syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      * Subsequent changes to
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   367
      * this compound name do not affect the name that is returned and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
      * vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      * @param  posn    The 0-based index of the component at which to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      * @return A compound name consisting of the components at indexes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
      *         the range [0,posn).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public Name getPrefix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   378
        Enumeration<String> comps = impl.getPrefix(posn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return (new CompoundName(comps, mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
      * Creates a compound name whose components consist of a suffix of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
      * components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
      * The result and this compound name share the same syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
      * Subsequent changes to
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   387
      * this compound name do not affect the name that is returned.
2
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 start.
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 compound name consisting of the components at indexes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      *         the range [posn,size()).  If posn is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
      *         size(), an empty compound name is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public Name getSuffix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   398
        Enumeration<String> comps = impl.getSuffix(posn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return (new CompoundName(comps, mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
      * Determines whether a compound name is a prefix of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
      * A compound name 'n' is a prefix if it is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
      * getPrefix(n.size())--in other words, this compound name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
      * starts with 'n'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
      * If n is null or not a compound name, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
      * Implementation note: Currently the syntax properties of n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
      *  are not used when doing the comparison. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
      * @param  n       The possibly null compound name to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
      * @return true if n is a CompoundName and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
      *                 is a prefix of this compound name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public boolean startsWith(Name n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if (n instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            return (impl.startsWith(n.size(), n.getAll()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
      * Determines whether a compound name is a suffix of this compound name.
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   425
      * A compound name 'n' is a suffix if it is equal to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      * getSuffix(size()-n.size())--in other words, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      * compound name ends with 'n'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      * If n is null or not a compound name, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      * Implementation note: Currently the syntax properties of n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      *  are not used when doing the comparison. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
      * @param  n       The possibly null compound name to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
      * @return true if n is a CompoundName and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
      *         is a suffix of this compound name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public boolean endsWith(Name n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (n instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            return (impl.endsWith(n.size(), n.getAll()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return false;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
      * Adds the components of a compound name -- in order -- to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      * this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      * Implementation note: Currently the syntax properties of suffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      *  is not used or checked. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
      * @param suffix   The non-null components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
      * @exception InvalidNameException If suffix is not a compound name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
      *            or if the addition of the components violates the syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
      *            of this compound name (e.g. exceeding number of components).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public Name addAll(Name suffix) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (suffix instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            impl.addAll(suffix.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            throw new InvalidNameException("Not a compound name: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                suffix.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
      * Adds the components of a compound name -- in order -- at a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
      * position within this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      * Components of this compound name at or after the index of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      * new component are shifted up (away from index 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      * to accommodate the new components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
      * Implementation note: Currently the syntax properties of suffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      *  is not used or checked. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
      * @param n        The non-null components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      * @param posn     The index in this name at which to add the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      *                 components.  Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
      * @exception InvalidNameException If n is not a compound name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      *            or if the addition of the components violates the syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
      *            of this compound name (e.g. exceeding number of components).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    public Name addAll(int posn, Name n) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        if (n instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            impl.addAll(posn, n.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            throw new InvalidNameException("Not a compound name: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                n.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
      * Adds a single component to the end of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
      * @param comp     The non-null component to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
      * @exception InvalidNameException If adding comp at end of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
      *                         would violate the compound name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public Name add(String comp) throws InvalidNameException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        impl.add(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return this;
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 at a specified position within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      * compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      * Components of this compound name at or after the index of the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      * component are shifted up by one (away from index 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      * to accommodate the new component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
      * @param  comp    The non-null component to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      * @param  posn    The index at which to add the new component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
      * @exception InvalidNameException If adding comp at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
      *                         would violate the compound name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    public Name add(int posn, String comp) throws InvalidNameException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        impl.add(posn, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
      * Deletes a component from this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
      * The component of this compound name at position 'posn' is removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
      * and components at indices greater than 'posn'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
      * are shifted down (towards index 0) by one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
      * @param  posn    The index of the component to delete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
      *                 Must be in the range [0,size()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
      * @return The component removed (a String).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
      *         If posn is outside the specified range (includes case where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
      *         compound name is empty).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
      * @exception InvalidNameException If deleting the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
      *                         would violate the compound name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public Object remove(int posn) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        return impl.remove(posn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * Overridden to avoid implementation dependency.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   551
     * @serialData The syntax {@code Properties}, followed by
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   552
     * the number of components (an {@code int}), and the individual
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   553
     * components (each a {@code String}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        s.writeObject(mySyntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        s.writeInt(size());
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   559
        Enumeration<String> comps = getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        while (comps.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            s.writeObject(comps.nextElement());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * Overridden to avoid implementation dependency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        mySyntax = (Properties)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        impl = new NameImpl(mySyntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        int n = s.readInt();    // number of components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            while (--n >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                add((String)s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            throw (new java.io.StreamCorruptedException("Invalid name"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    private static final long serialVersionUID = 3513100557083972036L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
//   For testing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        Properties dotSyntax = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        dotSyntax.put("jndi.syntax.direction", "right_to_left");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        dotSyntax.put("jndi.syntax.separator", ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        dotSyntax.put("jndi.syntax.ignorecase", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        dotSyntax.put("jndi.syntax.escape", "\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
//      dotSyntax.put("jndi.syntax.beginquote", "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
//      dotSyntax.put("jndi.syntax.beginquote2", "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        Name first = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            for (int i = 0; i < args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                Name name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                Enumeration e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                System.out.println("Given name: " + args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                name = new CompoundName(args[i], dotSyntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                if (first == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    first = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                e = name.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    System.out.println("Element: " + e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                System.out.println("Constructed name: " + name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                System.out.println("Compare " + first.toString() + " with "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    + name.toString() + " = " + first.compareTo(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        } catch (Exception ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            ne.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
}