jdk/src/java.naming/share/classes/javax/naming/Reference.java
author sundar
Mon, 31 Aug 2015 17:51:02 +0530
changeset 32434 769b3d81ae69
parent 32029 a5538163e144
permissions -rw-r--r--
8134731: Function.prototype.apply interacts incorrectly with arguments Reviewed-by: attila, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, 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.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Enumeration;
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 reference to an object that is found outside of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * the naming/directory system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  * Reference provides a way of recording address information about
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  * objects which themselves are not directly bound to the naming/directory system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * A Reference consists of an ordered list of addresses and class information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * about the object being referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * Each address in the list identifies a communications endpoint
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * for the same conceptual object.  The "communications endpoint"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * is information that indicates how to contact the object. It could
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * be, for example, a network address, a location in memory on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * local machine, another process on the same machine, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * The order of the addresses in the list may be of significance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  * to object factories that interpret the reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * Multiple addresses may arise for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  * various reasons, such as replication or the object offering interfaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  * over more than one communication mechanism.  The addresses are indexed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  * starting with zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  * A Reference also contains information to assist in creating an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * of the object to which this Reference refers.  It contains the class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  * of that object, and the class name and location of the factory to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  * to create the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
  * The class factory location is a space-separated list of URLs representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  * the class path used to load the factory.  When the factory class (or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
  * any class or resource upon which it depends) needs to be loaded,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  * each URL is used (in order) to attempt to load the class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  * A Reference instance is not synchronized against concurrent access by multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  * threads. Threads that need to access a single Reference concurrently should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  * synchronize amongst themselves and provide the necessary locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  * @see RefAddr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  * @see StringRefAddr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  * @see BinaryRefAddr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  /*<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  * The serialized form of a Reference object consists of the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  * name of the object being referenced (a String), a Vector of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  * addresses (each a RefAddr), the name of the class factory (a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  * String), and the location of the class factory (a String).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
public class Reference implements Cloneable, java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Contains the fully-qualified name of the class of the object to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * this Reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @see java.lang.Class#getName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    protected String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Contains the addresses contained in this Reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Initialized by constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    protected Vector<RefAddr> addrs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Contains the name of the factory class for creating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * an instance of the object to which this Reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Initialized to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected String classFactory = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Contains the location of the factory class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Initialized to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    protected String classFactoryLocation = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
      * Constructs a new reference for an object with class name 'className'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
      * Class factory and class factory location are set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
      * The newly created reference contains zero addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      * @param className The non-null class name of the object to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      * this reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public Reference(String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        this.className  = className;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   123
        addrs = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      * Constructs a new reference for an object with class name 'className' and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      * an address.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      * Class factory and class factory location are set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      * @param className The non-null class name of the object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      * which this reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      * @param addr The non-null address of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public Reference(String className, RefAddr addr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        this.className = className;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   137
        addrs = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        addrs.addElement(addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
      * Constructs a new reference for an object with class name 'className',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      * and the class name and location of the object's factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      * @param className The non-null class name of the object to which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      *                         this reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      * @param factory  The possibly null class name of the object's factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      * @param factoryLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      *         The possibly null location from which to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      *         the factory (e.g. URL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      * @see javax.naming.spi.ObjectFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      * @see javax.naming.spi.NamingManager#getObjectInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public Reference(String className, String factory, String factoryLocation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        this(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        classFactory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        classFactoryLocation = factoryLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
      * Constructs a new reference for an object with class name 'className',
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
      * the class name and location of the object's factory, and the address for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      * the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      * @param className The non-null class name of the object to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
      *         which this reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
      * @param factory  The possibly null class name of the object's factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      * @param factoryLocation  The possibly null location from which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
      *                         to load the factory (e.g. URL)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      * @param addr     The non-null address of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      * @see javax.naming.spi.ObjectFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      * @see javax.naming.spi.NamingManager#getObjectInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    public Reference(String className, RefAddr addr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                     String factory, String factoryLocation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        this(className, addr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        classFactory = factory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        classFactoryLocation = factoryLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      * Retrieves the class name of the object to which this reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      * @return The non-null fully-qualified class name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      *         (e.g. "java.lang.String")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      * Retrieves the class name of the factory of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      * to which this reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
      * @return The possibly null fully-qualified class name of the factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
      *         (e.g. "java.lang.String")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public String getFactoryClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return classFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
      * Retrieves the location of the factory of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
      * to which this reference refers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
      * If it is a codebase, then it is an ordered list of URLs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
      * separated by spaces, listing locations from where the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
      * class definition should be loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
      * @return The possibly null string containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
      *                 location for loading in the factory's class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public String getFactoryClassLocation() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        return classFactoryLocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
      * Retrieves the first address that has the address type 'addrType'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
      * String.compareTo() is used to test the equality of the address types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
      * @param addrType The non-null address type for which to find the address.
22974
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 10324
diff changeset
   221
      * @return The address in this reference with address type 'addrType';
4bf6c0d73bb8 4682009: Typo in javadocs in javax/naming
igerasim
parents: 10324
diff changeset
   222
      *         null if no such address exists.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public RefAddr get(String addrType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        int len = addrs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        RefAddr addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        for (int i = 0; i < len; i++) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   228
            addr = addrs.elementAt(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (addr.getType().compareTo(addrType) == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                return addr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
      * Retrieves the address at index posn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
      * @param posn The index of the address to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
      * @return The address at the 0-based index posn. It must be in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
      *         range [0,getAddressCount()).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
      * @exception ArrayIndexOutOfBoundsException If posn not in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
      *         range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public RefAddr get(int posn) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   244
        return addrs.elementAt(posn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
      * Retrieves an enumeration of the addresses in this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
      * When addresses are added, changed or removed from this reference,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
      * its effects on this enumeration are undefined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
      * @return An non-null enumeration of the addresses
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   253
      *         ({@code RefAddr}) in this reference.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
      *         If this reference has zero addresses, an enumeration with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
      *         zero elements is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public Enumeration<RefAddr> getAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        return addrs.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
      * Retrieves the number of addresses in this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
      * @return The nonnegative number of addresses in this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        return addrs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
      * Adds an address to the end of the list of addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
      * @param addr The non-null address to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public void add(RefAddr addr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        addrs.addElement(addr);
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
      * Adds an address to the list of addresses at index posn.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
      * All addresses at index posn or greater are shifted up
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
      * the list by one (away from index 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
      * @param posn The 0-based index of the list to insert addr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
      * @param addr The non-null address to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
      * @exception ArrayIndexOutOfBoundsException If posn not in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
      *         range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    public void add(int posn, RefAddr addr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        addrs.insertElementAt(addr, posn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
      * Deletes the address at index posn from the list of addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
      * All addresses at index greater than posn are shifted down
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
      * the list by one (towards index 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
      * @param posn The 0-based index of in address to delete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
      * @return The address removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
      * @exception ArrayIndexOutOfBoundsException If posn not in the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
      *         range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public Object remove(int posn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        Object r = addrs.elementAt(posn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        addrs.removeElementAt(posn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
      * Deletes all addresses from this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        addrs.setSize(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
      * Determines whether obj is a reference with the same addresses
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
      * (in same order) as this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
      * The addresses are checked using RefAddr.equals().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
      * In addition to having the same addresses, the Reference also needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
      * have the same class name as this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
      * The class factory and class factory location are not checked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
      * If obj is null or not an instance of Reference, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
      * @param obj The possibly null object to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      * @return true if obj is equal to this reference; false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if ((obj != null) && (obj instanceof Reference)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            Reference target = (Reference)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // ignore factory information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            if (target.className.equals(this.className) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                target.size() ==  this.size()) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   334
                Enumeration<RefAddr> mycomps = getAll();
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   335
                Enumeration<RefAddr> comps = target.getAll();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                while (mycomps.hasMoreElements())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    if (!(mycomps.nextElement().equals(comps.nextElement())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
      * Computes the hash code of this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
      * The hash code is the sum of the hash code of its addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
      * @return A hash code of this reference as an int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        int hash = className.hashCode();
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   353
        for (Enumeration<RefAddr> e = getAll(); e.hasMoreElements();)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            hash += e.nextElement().hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
      * Generates the string representation of this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
      * The string consists of the class name to which this reference refers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
      * and the string representation of each of its addresses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
      * This representation is intended for display only and not to be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
      * @return The non-null string representation of this reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public String toString() {
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 22974
diff changeset
   367
        StringBuilder sb = new StringBuilder("Reference Class Name: " +
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 22974
diff changeset
   368
                                             className + "\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        int len = addrs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        for (int i = 0; i < len; i++)
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 22974
diff changeset
   371
            sb.append(get(i).toString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
24969
afa6934dd8e8 8041679: Replace uses of StringBuffer with StringBuilder within core library classes
psandoz
parents: 22974
diff changeset
   373
        return sb.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * Makes a copy of this reference using its class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * list of addresses, class factory name and class factory location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Changes to the newly created copy does not affect this Reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * and vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        Reference r = new Reference(className, classFactory, classFactoryLocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        Enumeration<RefAddr> a = getAll();
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   385
        r.addrs = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        while (a.hasMoreElements())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            r.addrs.addElement(a.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    private static final long serialVersionUID = -1673475790065791735L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
};