Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/naming/Binding.java
38829 views
/*1* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming;2627/**28* This class represents a name-to-object binding found in a context.29*<p>30* A context consists of name-to-object bindings.31* The Binding class represents such a binding. It consists32* of a name and an object. The <code>Context.listBindings()</code>33* method returns an enumeration of Binding.34*<p>35* Use subclassing for naming systems that generate contents of36* a binding dynamically.37*<p>38* A Binding instance is not synchronized against concurrent access by multiple39* threads. Threads that need to access a Binding concurrently should40* synchronize amongst themselves and provide the necessary locking.41*42* @author Rosanna Lee43* @author Scott Seligman44* @since 1.345*/4647public class Binding extends NameClassPair {48/**49* Contains this binding's object.50* It is initialized by the constructor and can be updated using51* <tt>setObject</tt>.52* @serial53* @see #getObject54* @see #setObject55*/56private Object boundObj;5758/**59* Constructs an instance of a Binding given its name and object.60*<p>61* <tt>getClassName()</tt> will return62* the class name of <tt>obj</tt> (or null if <tt>obj</tt> is null)63* unless the class name has been explicitly set using <tt>setClassName()</tt>64*65* @param name The non-null name of the object. It is relative66* to the <em>target context</em> (which is67* named by the first parameter of the <code>listBindings()</code> method)68* @param obj The possibly null object bound to name.69* @see NameClassPair#setClassName70*/71public Binding(String name, Object obj) {72super(name, null);73this.boundObj = obj;74}7576/**77* Constructs an instance of a Binding given its name, object, and whether78* the name is relative.79*<p>80* <tt>getClassName()</tt> will return the class name of <tt>obj</tt>81* (or null if <tt>obj</tt> is null) unless the class name has been82* explicitly set using <tt>setClassName()</tt>83*84* @param name The non-null string name of the object.85* @param obj The possibly null object bound to name.86* @param isRelative true if <code>name</code> is a name relative87* to the target context (which is named by88* the first parameter of the <code>listBindings()</code> method);89* false if <code>name</code> is a URL string.90* @see NameClassPair#isRelative91* @see NameClassPair#setRelative92* @see NameClassPair#setClassName93*/94public Binding(String name, Object obj, boolean isRelative) {95super(name, null, isRelative);96this.boundObj = obj;97}9899/**100* Constructs an instance of a Binding given its name, class name, and object.101*102* @param name The non-null name of the object. It is relative103* to the <em>target context</em> (which is104* named by the first parameter of the <code>listBindings()</code> method)105* @param className The possibly null class name of the object106* bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is107* returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also108* null, <tt>getClassName()</tt> will return null.109* @param obj The possibly null object bound to name.110* @see NameClassPair#setClassName111*/112public Binding(String name, String className, Object obj) {113super(name, className);114this.boundObj = obj;115}116117/**118* Constructs an instance of a Binding given its119* name, class name, object, and whether the name is relative.120*121* @param name The non-null string name of the object.122* @param className The possibly null class name of the object123* bound to <tt>name</tt>. If null, the class name of <tt>obj</tt> is124* returned by <tt>getClassName()</tt>. If <tt>obj</tt> is also125* null, <tt>getClassName()</tt> will return null.126* @param obj The possibly null object bound to name.127* @param isRelative true if <code>name</code> is a name relative128* to the target context (which is named by129* the first parameter of the <code>listBindings()</code> method);130* false if <code>name</code> is a URL string.131* @see NameClassPair#isRelative132* @see NameClassPair#setRelative133* @see NameClassPair#setClassName134*/135public Binding(String name, String className, Object obj, boolean isRelative) {136super(name, className, isRelative);137this.boundObj = obj;138}139140/**141* Retrieves the class name of the object bound to the name of this binding.142* If the class name has been set explicitly, return it.143* Otherwise, if this binding contains a non-null object,144* that object's class name is used. Otherwise, null is returned.145*146* @return A possibly null string containing class name of object bound.147*/148public String getClassName() {149String cname = super.getClassName();150if (cname != null) {151return cname;152}153if (boundObj != null)154return boundObj.getClass().getName();155else156return null;157}158159/**160* Retrieves the object bound to the name of this binding.161*162* @return The object bound; null if this binding does not contain an object.163* @see #setObject164*/165166public Object getObject() {167return boundObj;168}169170/**171* Sets the object associated with this binding.172* @param obj The possibly null object to use.173* @see #getObject174*/175public void setObject(Object obj) {176boundObj = obj;177}178179/**180* Generates the string representation of this binding.181* The string representation consists of the string representation182* of the name/class pair and the string representation of183* this binding's object, separated by ':'.184* The contents of this string is useful185* for debugging and is not meant to be interpreted programmatically.186*187* @return The non-null string representation of this binding.188*/189190public String toString() {191return super.toString() + ":" + getObject();192}193194/**195* Use serialVersionUID from JNDI 1.1.1 for interoperability196*/197private static final long serialVersionUID = 8839217842691845890L;198};199200201