001 /* Binding.java -- 002 Copyright (C) 2001, 2005, 2006 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package 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 */ 053 public 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 }