Source for javax.naming.Binding

   1: /* Binding.java --
   2:    Copyright (C) 2001, 2005, 2006  Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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.
  10: 
  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.
  15: 
  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.
  20: 
  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.
  25: 
  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. */
  37: 
  38: 
  39: package javax.naming;
  40: 
  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>
  49:  * 
  50:  * @author Tom Tromey (tromey@redhat.com)
  51:  * @since 1.3
  52:  */
  53: public class Binding extends NameClassPair
  54: {
  55:   private static final long serialVersionUID = 8839217842691845890L;
  56: 
  57:   /**
  58:    * Constructs an instance with the given name and object.
  59:    * 
  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
  63:    */
  64:   public Binding (String name, Object obj)
  65:   {
  66:     super (name, null);
  67:     boundObj = obj;
  68:   }
  69: 
  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.
  73:    * 
  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
  78:    */
  79:   public Binding (String name, Object obj, boolean isRelative)
  80:   {
  81:     super (name, null, isRelative);
  82:     boundObj = obj;
  83:   }
  84: 
  85:   /**
  86:    * Constructs an instance with the given name, classname and object.
  87:    * 
  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
  92:    */
  93:   public Binding (String name, String className, Object obj)
  94:   {
  95:     super (name, className);
  96:     boundObj = obj;
  97:   }
  98: 
  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.
 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: }