src/java.naming/share/classes/javax/naming/Binding.java
author eosterlund
Mon, 25 Nov 2019 15:21:44 +0000
changeset 59258 4c2557ab304e
parent 58531 9b40d05c9f66
permissions -rw-r--r--
8234531: Remove CMS code from CLDG and safepoint cleanup Reviewed-by: coleenp, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58531
9b40d05c9f66 8232076: Suppress warnings on non-serializable non-transient instance fields java.naming
darcy
parents: 47216
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.naming;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  * This class represents a name-to-object binding found in a context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  * A context consists of name-to-object bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  * The Binding class represents such a binding.  It consists
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * of a name and an object. The <code>Context.listBindings()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  * method returns an enumeration of Binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  * Use subclassing for naming systems that generate contents of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  * a binding dynamically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * A Binding instance is not synchronized against concurrent access by multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * threads. Threads that need to access a Binding concurrently should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * synchronize amongst themselves and provide the necessary locking.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class Binding extends NameClassPair {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Contains this binding's object.
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 5506
diff changeset
    51
     * It is initialized by the constructor and can be updated using
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    52
     * {@code setObject}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @see #getObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @see #setObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
58531
9b40d05c9f66 8232076: Suppress warnings on non-serializable non-transient instance fields java.naming
darcy
parents: 47216
diff changeset
    57
    @SuppressWarnings("serial") // Not statically typed as Serializable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    private Object boundObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
      * Constructs an instance of a Binding given its name and object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
      *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    63
      * {@code getClassName()} will return
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    64
      * the class name of {@code obj} (or null if {@code obj} is null)
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    65
      * unless the class name has been explicitly set using {@code setClassName()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
      * @param  name    The non-null name of the object. It is relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      *             to the <em>target context</em> (which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      * named by the first parameter of the <code>listBindings()</code> method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public Binding(String name, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        super(name, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        this.boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      * Constructs an instance of a Binding given its name, object, and whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
      * the name is relative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      *<p>
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    82
      * {@code getClassName()} will return the class name of {@code obj}
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    83
      * (or null if {@code obj} is null) unless the class name has been
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
    84
      * explicitly set using {@code setClassName()}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      * @param  name    The non-null string name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      * @param isRelative true if <code>name</code> is a name relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      *         to the target context (which is named by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      *         the first parameter of the <code>listBindings()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      *         false if <code>name</code> is a URL string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      * @see NameClassPair#isRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      * @see NameClassPair#setRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public Binding(String name, Object obj, boolean isRelative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        super(name, null, isRelative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      * Constructs an instance of a Binding given its name, class name, and object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      * @param  name    The non-null name of the object. It is relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      *             to the <em>target context</em> (which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      * named by the first parameter of the <code>listBindings()</code> method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      * @param  className       The possibly null class name of the object
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   108
      *         bound to {@code name}. If null, the class name of {@code obj} is
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   109
      *         returned by {@code getClassName()}. If {@code obj} is also
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   110
      *         null, {@code getClassName()} will return null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public Binding(String name, String className, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        super(name, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        this.boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      * Constructs an instance of a Binding given its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      * name, class name, object, and whether the name is relative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      * @param  name    The non-null string name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      * @param  className       The possibly null class name of the object
32029
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   125
      *         bound to {@code name}. If null, the class name of {@code obj} is
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   126
      *         returned by {@code getClassName()}. If {@code obj} is also
a5538163e144 8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents: 25859
diff changeset
   127
      *         null, {@code getClassName()} will return null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      * @param isRelative true if <code>name</code> is a name relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      *         to the target context (which is named by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      *         the first parameter of the <code>listBindings()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      *         false if <code>name</code> is a URL string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      * @see NameClassPair#isRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      * @see NameClassPair#setRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public Binding(String name, String className, Object obj, boolean isRelative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        super(name, className, isRelative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        this.boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      * Retrieves the class name of the object bound to the name of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      * If the class name has been set explicitly, return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      * Otherwise, if this binding contains a non-null object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      * that object's class name is used. Otherwise, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      * @return A possibly null string containing class name of object bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        String cname = super.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            return cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (boundObj != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            return boundObj.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
      * Retrieves the object bound to the name of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
      * @return The object bound; null if this binding does not contain an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      * @see #setObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public Object getObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return boundObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Sets the object associated with this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param obj The possibly null object to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @see #getObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public void setObject(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        boundObj = obj;
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
      * Generates the string representation of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      * The string representation consists of the string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      * of the name/class pair and the string representation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      * this binding's object, separated by ':'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      * The contents of this string is useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      * for debugging and is not meant to be interpreted programmatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      * @return The non-null string representation of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return super.toString() + ":" + getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    private static final long serialVersionUID = 8839217842691845890L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
};