jdk/src/java.naming/share/classes/javax/naming/CompoundName.java
author lana
Thu, 31 Mar 2016 01:13:19 -0700
changeset 36728 9bc1d0332a48
parent 36439 e0fdb6c0bb65
child 43536 8212439a528c
permissions -rw-r--r--
Added tag jdk-9+112 for changeset 5531985950c0
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 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
 *
18580
6c4badf4ffba 8019407: Fix doclint issues in javax.naming.*
darcy
parents: 10324
diff changeset
    42
 * <h1>Compound Name Syntax</h1>
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
 *
18580
6c4badf4ffba 8019407: Fix doclint issues in javax.naming.*
darcy
parents: 10324
diff changeset
   139
 *<h1>Multithreaded Access</h1>
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      * Implementation of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      * This field is initialized by the constructors and cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
      * It should be treated as a read-only variable by subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected transient NameImpl impl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
      * Syntax properties for this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
      * This field is initialized by the constructors and cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
      * It should be treated as a read-only variable by subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      * Any necessary changes to mySyntax should be made within constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
      * and not after the compound name has been instantiated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    protected transient Properties mySyntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      * Constructs a new compound name instance using the components
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   168
      * specified in comps and syntax. This protected method is intended
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      * to be used by subclasses of CompoundName when they override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      * methods such as clone(), getPrefix(), getSuffix().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      * @param comps  A non-null enumeration of the components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      *   Each element of the enumeration is of class String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      *               The enumeration will be consumed to extract its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      *               elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
      * @param syntax   A non-null properties that specify the syntax of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
      *                 this compound name. See class description for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
      *                 contents of properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    protected CompoundName(Enumeration<String> comps, Properties syntax) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (syntax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        mySyntax = syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        impl = new NameImpl(syntax, comps);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      * Constructs a new compound name instance by parsing the string n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      * using the syntax specified by the syntax properties supplied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      * @param  n       The non-null string to parse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      * @param syntax   A non-null list of properties that specify the syntax of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      *                 this compound name.  See class description for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
      *                 contents of properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
      * @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
   197
      *                 by {@code syntax}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    public CompoundName(String n, Properties syntax) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (syntax == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        mySyntax = syntax;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        impl = new NameImpl(syntax, n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
      * Generates the string representation of this compound name, using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
      * the syntax rules of the compound name. The syntax rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      * are described in the class description.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
      * An empty component is represented by an empty string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
      * The string representation thus generated can be passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
      * the CompoundName constructor with the same syntax properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
      * to create a new equivalent compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      * @return A non-null string representation of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        return (impl.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
      * Determines whether obj is syntactically equal to this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
      * If obj is null or not a CompoundName, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
      * Two compound names are equal if each component in one is "equal"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
      * to the corresponding component in the other.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
      * Equality is also defined in terms of the syntax of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
      * The default implementation of CompoundName uses the syntax properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
      * jndi.syntax.ignorecase and jndi.syntax.trimblanks when comparing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
      * two components for equality.  If case is ignored, two strings
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
      * with the same sequence of characters but with different cases
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
      * are considered equal. If blanks are being trimmed, leading and trailing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
      * blanks are ignored for the purpose of the comparison.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      * Both compound names must have the same number of components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      * Implementation note: Currently the syntax properties of the two compound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
      * names are not compared for equality. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      * @param  obj     The possibly null object to compare against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
      * @return true if obj is equal to this compound name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
      * @see #compareTo(java.lang.Object obj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // %%% check syntax too?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        return (obj != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                obj instanceof CompoundName &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                impl.equals(((CompoundName)obj).impl));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      * Computes the hash code of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      * The hash code is the sum of the hash codes of the "canonicalized"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      * forms of individual components of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
      * Each component is "canonicalized" according to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
      * compound name's syntax before its hash code is computed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
      * For a case-insensitive name, for example, the uppercased form of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
      * a name has the same hash code as its lowercased equivalent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      * @return An int representing the hash code of this name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return impl.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
      * Creates a copy of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
      * Changes to the components of this compound name won't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      * affect the new copy and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      * The clone and this compound name share the same syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      * @return A non-null copy of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        return (new CompoundName(getAll(), mySyntax));
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
     * Compares this CompoundName with the specified Object for order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Returns a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * negative integer, zero, or a positive integer as this Name is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * than, equal to, or greater than the given Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * If obj is null or not an instance of CompoundName, ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * See equals() for what it means for two compound names to be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * If two compound names are equal, 0 is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Ordering of compound names depend on the syntax of the compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * By default, they follow lexicographical rules for string comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * with the extension that this applies to all the components in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * compound name and that comparison of individual components is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * affected by the jndi.syntax.ignorecase and jndi.syntax.trimblanks
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * properties, identical to how they affect equals().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * If this compound name is "lexicographically" lesser than obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * a negative number is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * If this compound name is "lexicographically" greater than obj,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * a positive number is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Implementation note: Currently the syntax properties of the two compound
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * names are not compared when checking order. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @param   obj     The non-null object to compare against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @return  a negative integer, zero, or a positive integer as this Name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *          is less than, equal to, or greater than the given Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @exception ClassCastException if obj is not a CompoundName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see #equals(java.lang.Object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public int compareTo(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (!(obj instanceof CompoundName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            throw new ClassCastException("Not a CompoundName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return impl.compareTo(((CompoundName)obj).impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      * Retrieves the number of components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      * @return The nonnegative number of components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        return (impl.size());
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
      * Determines whether this compound name is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
      * A compound name is empty if it has zero components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
      * @return true if this compound name is empty, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return (impl.isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
      * Retrieves the components of this compound name as an enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
      * of strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
      * The effects of updates to this compound name on this enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
      * is undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
      * @return A non-null enumeration of the components of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
      * compound name. Each element of the enumeration is of class String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public Enumeration<String> getAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return (impl.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      * Retrieves a component of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
      * @param  posn    The 0-based index of the component to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
      *                 Must be in the range [0,size()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
      * @return The component at index posn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
      * @exception ArrayIndexOutOfBoundsException if posn is outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
      *         specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public String get(int posn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        return (impl.get(posn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
      * Creates a compound name whose components consist of a prefix of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
      * components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
      * The result and this compound name share the same syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
      * Subsequent changes to
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   368
      * this compound name do not affect the name that is returned and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
      * vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
      * @param  posn    The 0-based index of the component at which to stop.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
      * @return A compound name consisting of the components at indexes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
      *         the range [0,posn).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public Name getPrefix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   379
        Enumeration<String> comps = impl.getPrefix(posn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return (new CompoundName(comps, mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
      * Creates a compound name whose components consist of a suffix of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
      * components in this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
      * The result and this compound name share the same syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
      * Subsequent changes to
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 21285
diff changeset
   388
      * this compound name do not affect the name that is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
      * @param  posn    The 0-based index of the component at which to start.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
      * @return A compound name consisting of the components at indexes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
      *         the range [posn,size()).  If posn is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
      *         size(), an empty compound name is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public Name getSuffix(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   399
        Enumeration<String> comps = impl.getSuffix(posn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return (new CompoundName(comps, mySyntax));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
      * Determines whether a compound name is a prefix of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
      * A compound name 'n' is a prefix if it is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
      * getPrefix(n.size())--in other words, this compound name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
      * starts with 'n'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
      * If n is null or not a compound name, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
      * Implementation note: Currently the syntax properties of n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
      *  are not used when doing the comparison. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
      * @param  n       The possibly null compound name to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
      * @return true if n is a CompoundName and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
      *                 is a prefix of this compound name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public boolean startsWith(Name n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        if (n instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            return (impl.startsWith(n.size(), n.getAll()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return false;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      * 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
   426
      * A compound name 'n' is a suffix if it is equal to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
      * getSuffix(size()-n.size())--in other words, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
      * compound name ends with 'n'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
      * If n is null or not a compound name, false is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
      * Implementation note: Currently the syntax properties of n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
      *  are not used when doing the comparison. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
      * @param  n       The possibly null compound name to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
      * @return true if n is a CompoundName and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
      *         is a suffix of this compound name, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public boolean endsWith(Name n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        if (n instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return (impl.endsWith(n.size(), n.getAll()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return false;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
      * Adds the components of a compound name -- in order -- to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
      * this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      * Implementation note: Currently the syntax properties of suffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
      *  is not used or checked. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
      * @param suffix   The non-null components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
      * @exception InvalidNameException If suffix is not a compound name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
      *            or if the addition of the components violates the syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
      *            of this compound name (e.g. exceeding number of components).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public Name addAll(Name suffix) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (suffix instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            impl.addAll(suffix.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            throw new InvalidNameException("Not a compound name: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                suffix.toString());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
      * Adds the components of a compound name -- in order -- at a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
      * position within this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
      * Components of this compound name at or after the index of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
      * new component are shifted up (away from index 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
      * to accommodate the new components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
      * Implementation note: Currently the syntax properties of suffix
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
      *  is not used or checked. They might be in the future.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
      * @param n        The non-null components to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
      * @param posn     The index in this name at which to add the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
      *                 components.  Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
      * @exception InvalidNameException If n is not a compound name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
      *            or if the addition of the components violates the syntax
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
      *            of this compound name (e.g. exceeding number of components).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    public Name addAll(int posn, Name n) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (n instanceof CompoundName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            impl.addAll(posn, n.getAll());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            throw new InvalidNameException("Not a compound name: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                n.toString());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
      * Adds a single component to the end of this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
      * @param comp     The non-null component to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
      * @exception InvalidNameException If adding comp at end of the name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      *                         would violate the compound name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public Name add(String comp) throws InvalidNameException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        impl.add(comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
      * Adds a single component at a specified position within this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
      * compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
      * Components of this compound name at or after the index of the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      * component are shifted up by one (away from index 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
      * to accommodate the new component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
      * @param  comp    The non-null component to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
      * @param  posn    The index at which to add the new component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
      *                 Must be in the range [0,size()].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
      *         If posn is outside the specified range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
      * @return The updated CompoundName, not a new one. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
      * @exception InvalidNameException If adding comp at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
      *                         would violate the compound name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    public Name add(int posn, String comp) throws InvalidNameException{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        impl.add(posn, comp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
      * Deletes a component from this compound name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
      * The component of this compound name at position 'posn' is removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
      * and components at indices greater than 'posn'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
      * are shifted down (towards index 0) by one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
      * @param  posn    The index of the component to delete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
      *                 Must be in the range [0,size()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
      * @return The component removed (a String).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
      * @exception ArrayIndexOutOfBoundsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
      *         If posn is outside the specified range (includes case where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
      *         compound name is empty).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
      * @exception InvalidNameException If deleting the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
      *                         would violate the compound name's syntax.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public Object remove(int posn) throws InvalidNameException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return impl.remove(posn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * Overridden to avoid implementation dependency.
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   552
     * @serialData The syntax {@code Properties}, followed by
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   553
     * 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
   554
     * components (each a {@code String}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            throws java.io.IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        s.writeObject(mySyntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        s.writeInt(size());
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   560
        Enumeration<String> comps = getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        while (comps.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            s.writeObject(comps.nextElement());
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * Overridden to avoid implementation dependency.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            throws java.io.IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        mySyntax = (Properties)s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        impl = new NameImpl(mySyntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        int n = s.readInt();    // number of components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            while (--n >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                add((String)s.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            throw (new java.io.StreamCorruptedException("Invalid name"));
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    private static final long serialVersionUID = 3513100557083972036L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
//   For testing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        Properties dotSyntax = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        dotSyntax.put("jndi.syntax.direction", "right_to_left");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        dotSyntax.put("jndi.syntax.separator", ".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        dotSyntax.put("jndi.syntax.ignorecase", "true");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        dotSyntax.put("jndi.syntax.escape", "\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
//      dotSyntax.put("jndi.syntax.beginquote", "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
//      dotSyntax.put("jndi.syntax.beginquote2", "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        Name first = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            for (int i = 0; i < args.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                Name name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                Enumeration e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                System.out.println("Given name: " + args[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                name = new CompoundName(args[i], dotSyntax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                if (first == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                    first = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                e = name.getComponents();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                while (e.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                    System.out.println("Element: " + e.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                System.out.println("Constructed name: " + name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                System.out.println("Compare " + first.toString() + " with "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    + name.toString() + " = " + first.compareTo(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        } catch (Exception ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            ne.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
}