001/* Binding.java -- 002 Copyright (C) 2001, 2005, 2006 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package javax.naming; 040 041/** 042 * <code>Binding</code> represents the name-object mapping of a 043 * binding in a context. 044 * <p> 045 * Bindings are mappings of a name to an object and this class is used to 046 * specify such mappings. The bindings of a context are retrieved by the 047 * <code>Context#listBindings()</code> methods. 048 * </p> 049 * 050 * @author Tom Tromey (tromey@redhat.com) 051 * @since 1.3 052 */ 053public class Binding extends NameClassPair 054{ 055 private static final long serialVersionUID = 8839217842691845890L; 056 057 /** 058 * Constructs an instance with the given name and object. 059 * 060 * @param name the name of the binding relative to the target context 061 * (may not be <code>null</code>) 062 * @param obj the bound object 063 */ 064 public Binding (String name, Object obj) 065 { 066 super (name, null); 067 boundObj = obj; 068 } 069 070 /** 071 * Constructs an instance with the given name and object and a 072 * flag indicating if the name is relative to the target context. 073 * 074 * @param name the name of the binding relative to the target context 075 * (may not be <code>null</code>) 076 * @param obj the bound object 077 * @param isRelative flag indicating if the name is relative or not 078 */ 079 public Binding (String name, Object obj, boolean isRelative) 080 { 081 super (name, null, isRelative); 082 boundObj = obj; 083 } 084 085 /** 086 * Constructs an instance with the given name, classname and object. 087 * 088 * @param name the name of the binding relative to the target context 089 * (may not be <code>null</code>) 090 * @param className the classname to set (maybe <code>null</code>) 091 * @param obj the bound object 092 */ 093 public Binding (String name, String className, Object obj) 094 { 095 super (name, className); 096 boundObj = obj; 097 } 098 099 /** 100 * Constructs an instance with the given name, classname, object and a 101 * flag indicating if the name is relative to the target context. 102 * 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 108 */ 109 public Binding (String name, String className, Object obj, 110 boolean isRelative) 111 { 112 super (name, className, isRelative); 113 boundObj = obj; 114 } 115 116 /** 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> 122 * 123 * @return The fully qualified classname (may be <code>null</code>). 124 */ 125 public String getClassName () 126 { 127 String r = super.getClassName (); 128 if (r != null) 129 return r; 130 return boundObj == null ? null : boundObj.getClass ().getName (); 131 } 132 133 /** 134 * Returns the bound object of this binding. 135 * @return The bound object (maybe <code>null</code>). 136 */ 137 public Object getObject () 138 { 139 return boundObj; 140 } 141 142 /** 143 * Sets the bound object of this binding. 144 * @param obj the bound object. 145 */ 146 public void setObject (Object obj) 147 { 148 boundObj = obj; 149 } 150 151 /** 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. 155 */ 156 public String toString () 157 { 158 // Format specified by the documentation. 159 return super.toString () + ":" + boundObj.toString (); 160 } 161 162 // This name is fixed by the serialization spec. 163 private Object boundObj; 164}