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