jdk/src/share/classes/javax/naming/Binding.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 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
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * <tt>setObject</tt>.
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private Object boundObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
      * Constructs an instance of a Binding given its name and object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
      * <tt>getClassName()</tt> will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
      * the class name of <tt>obj</tt> (or null if <tt>obj</tt> is null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      * unless the class name has been explicitly set using <tt>setClassName()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
      * @param  name    The non-null name of the object. It is relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
      *             to the <em>target context</em> (which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      * named by the first parameter of the <code>listBindings()</code> method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public Binding(String name, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        super(name, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        this.boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      * Constructs an instance of a Binding given its name, object, and whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      * the name is relative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
      *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      * <tt>getClassName()</tt> will return the class name of <tt>obj</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      * (or null if <tt>obj</tt> is null) unless the class name has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      * explicitly set using <tt>setClassName()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      * @param  name    The non-null string name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
      * @param isRelative true if <code>name</code> is a name relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      *         to the target context (which is named by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
      *         the first parameter of the <code>listBindings()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      *         false if <code>name</code> is a URL string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      * @see NameClassPair#isRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      * @see NameClassPair#setRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public Binding(String name, Object obj, boolean isRelative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super(name, null, isRelative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        this.boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
      * Constructs an instance of a Binding given its name, class name, and object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
      * @param  name    The non-null name of the object. It is relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
      *             to the <em>target context</em> (which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
      * named by the first parameter of the <code>listBindings()</code> method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
      * @param  className       The possibly null class name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
      *         bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
      *         returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
      *         null, <tt>getClassName()</tt> will return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public Binding(String name, String className, Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        super(name, className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        this.boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
      * Constructs an instance of a Binding given its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
      * name, class name, object, and whether the name is relative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
      * @param  name    The non-null string name of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
      * @param  className       The possibly null class name of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
      *         bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      *         returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      *         null, <tt>getClassName()</tt> will return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      * @param  obj     The possibly null object bound to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      * @param isRelative true if <code>name</code> is a name relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      *         to the target context (which is named by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      *         the first parameter of the <code>listBindings()</code> method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      *         false if <code>name</code> is a URL string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      * @see NameClassPair#isRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      * @see NameClassPair#setRelative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      * @see NameClassPair#setClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public Binding(String name, String className, Object obj, boolean isRelative) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        super(name, className, isRelative);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        this.boundObj = obj;
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
      * Retrieves the class name of the object bound to the name of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
      * If the class name has been set explicitly, return it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
      * Otherwise, if this binding contains a non-null object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      * that object's class name is used. Otherwise, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      * @return A possibly null string containing class name of object bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        String cname = super.getClassName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (cname != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            return cname;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (boundObj != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            return boundObj.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            return null;
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
      * Retrieves the object bound to the name of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      * @return The object bound; null if this binding does not contain an object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
      * @see #setObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public Object getObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return boundObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * Sets the object associated with this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param obj The possibly null object to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see #getObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void setObject(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        boundObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
      * Generates the string representation of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
      * The string representation consists of the string representation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
      * of the name/class pair and the string representation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
      * this binding's object, separated by ':'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
      * The contents of this string is useful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
      * for debugging and is not meant to be interpreted programmatically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
      * @return The non-null string representation of this binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        return super.toString() + ":" + getObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Use serialVersionUID from JNDI 1.1.1 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    private static final long serialVersionUID = 8839217842691845890L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
};