Merge from mainline.
[official-gcc.git] / libjava / classpath / javax / naming / Binding.java
bloba34f8b3292c21486043dfa10cba80f2cdedb8ac1
1 /* Binding.java --
2 Copyright (C) 2001, 2005, 2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.naming;
41 /**
42 * <code>Binding</code> represents the name-object mapping of a
43 * binding in a context.
44 * <p>
45 * Bindings are mappings of a name to an object and this class is used to
46 * specify such mappings. The bindings of a context are retrieved by the
47 * <code>Context#listBindings()</code> methods.
48 * </p>
50 * @author Tom Tromey (tromey@redhat.com)
51 * @since 1.3
53 public class Binding extends NameClassPair
55 private static final long serialVersionUID = 8839217842691845890L;
57 /**
58 * Constructs an instance with the given name and object.
60 * @param name the name of the binding relative to the target context
61 * (may not be <code>null</code>)
62 * @param obj the bound object
64 public Binding (String name, Object obj)
66 super (name, null);
67 boundObj = obj;
70 /**
71 * Constructs an instance with the given name and object and a
72 * flag indicating if the name is relative to the target context.
74 * @param name the name of the binding relative to the target context
75 * (may not be <code>null</code>)
76 * @param obj the bound object
77 * @param isRelative flag indicating if the name is relative or not
79 public Binding (String name, Object obj, boolean isRelative)
81 super (name, null, isRelative);
82 boundObj = obj;
85 /**
86 * Constructs an instance with the given name, classname and object.
88 * @param name the name of the binding relative to the target context
89 * (may not be <code>null</code>)
90 * @param className the classname to set (maybe <code>null</code>)
91 * @param obj the bound object
93 public Binding (String name, String className, Object obj)
95 super (name, className);
96 boundObj = obj;
99 /**
100 * Constructs an instance with the given name, classname, object and a
101 * flag indicating if the name is relative to the target context.
103 * @param name the name of the binding relative to the target context
104 * (may not be <code>null</code>)
105 * @param className the classname to set (maybe <code>null</code>)
106 * @param isRelative flag indicating if the name is relative or not
107 * @param obj the bound object
109 public Binding (String name, String className, Object obj,
110 boolean isRelative)
112 super (name, className, isRelative);
113 boundObj = obj;
117 * Returns the classname of the bound object.
118 * <p>
119 * Returns the classname if set explicitly. If not and the bound object is
120 * not <code>null</code> the classname of the bound object is used.
121 * </p>
123 * @return The fully qualified classname (may be <code>null</code>).
125 public String getClassName ()
127 String r = super.getClassName ();
128 if (r != null)
129 return r;
130 return boundObj == null ? null : boundObj.getClass ().getName ();
134 * Returns the bound object of this binding.
135 * @return The bound object (maybe <code>null</code>).
137 public Object getObject ()
139 return boundObj;
143 * Sets the bound object of this binding.
144 * @param obj the bound object.
146 public void setObject (Object obj)
148 boundObj = obj;
152 * Returns the string representation.
153 * @return The string as given by the NameClassPair superclass plus
154 * the bound objects string representation seperated by a colon.
156 public String toString ()
158 // Format specified by the documentation.
159 return super.toString () + ":" + boundObj.toString ();
162 // This name is fixed by the serialization spec.
163 private Object boundObj;