NameClassPair.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* NameClassPair.java --
  2. Copyright (C) 2001, 2005, 2006 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.naming;
  32. import java.io.Serializable;
  33. /**
  34. * <code>NameClassPair</code> represents the name-classname mapping pair
  35. * of a binding in a context.
  36. * <p>
  37. * Bindings are mappings of a name to an object and this class is used to
  38. * specify the mapping of the name to the class type of the bound object.
  39. * As classname the fully qualified classname is used.
  40. * </p>
  41. *
  42. * @author Tom Tromey (tromey@redhat.com)
  43. * @since 1.3
  44. */
  45. public class NameClassPair implements Serializable
  46. {
  47. private static final long serialVersionUID = 5620776610160863339L;
  48. /**
  49. * Constructs an instance with the given name and classname.
  50. *
  51. * @param name the name of the binding relative to the target context
  52. * (may not be <code>null</code>)
  53. * @param className the name of the class. If <code>null</code> the bound
  54. * object is also <code>null</code>
  55. */
  56. public NameClassPair (String name, String className)
  57. {
  58. this (name, className, true);
  59. }
  60. /**
  61. * Constructs an instance with the given name and classname and a
  62. * flag indicating if the name is relative to the target context.
  63. *
  64. * @param name the name of the binding (may not be <code>null</code>)
  65. * @param className the name of the class. If <code>null</code> the bound
  66. * object is also <code>null</code>
  67. * @param isRelative flag indicating if the name is relative or not
  68. */
  69. public NameClassPair (String name, String className, boolean isRelative)
  70. {
  71. this.name = name;
  72. this.className = className;
  73. this.isRel = isRelative;
  74. }
  75. /**
  76. * Returns the classname of the binding.
  77. * @return The fully qualified classname or <code>null</code> if the
  78. * bound object is null.
  79. */
  80. public String getClassName ()
  81. {
  82. return className;
  83. }
  84. /**
  85. * Returns the name of the binding.
  86. * @return The name.
  87. */
  88. public String getName ()
  89. {
  90. return name;
  91. }
  92. /**
  93. * Checks whether the name is relative to the target context or not.
  94. * @return <code>true</code> if the name is relative,
  95. * <code>false</code> otherwise.
  96. */
  97. public boolean isRelative ()
  98. {
  99. return isRel;
  100. }
  101. /**
  102. * Sets the classname of the bound object.
  103. * @param name the classname to set (maybe <code>null</code>)
  104. */
  105. public void setClassName (String name)
  106. {
  107. this.className = name;
  108. }
  109. /**
  110. * Sets the name of the binding.
  111. * @param name the name to set
  112. */
  113. public void setName (String name)
  114. {
  115. this.name = name;
  116. }
  117. /**
  118. * Sets if the name is relative to the target context.
  119. * @param r <code>true</code> to mark as relative
  120. */
  121. public void setRelative (boolean r)
  122. {
  123. this.isRel = r;
  124. }
  125. /**
  126. * Sets the full name for this binding. Setting the full name by this
  127. * method is the only way to initialize full names of bindings if
  128. * supported by a specific naming system.
  129. *
  130. * @param fullName the full name of this binding. If not set or set to
  131. * <code>null</code> the <code>getNameInNamespace()</code> method will
  132. * throw an exception
  133. *
  134. * @see #getNameInNamespace()
  135. *
  136. * @since 1.5
  137. */
  138. public void setNameInNamespace(String fullName)
  139. {
  140. this.fullName = fullName;
  141. }
  142. /**
  143. * Returns the full name for this binding. The full name of a binding is
  144. * defined as the absolute name in its own namespace and is not valid
  145. * outside.
  146. *
  147. * @return The full name in the bindings namespace.
  148. * @throws UnsupportedOperationException if no full name is applicable in
  149. * the specific naming system.
  150. *
  151. * @see Context#getNameInNamespace()
  152. *
  153. * @since 1.5
  154. */
  155. public String getNameInNamespace()
  156. {
  157. if (this.fullName == null)
  158. throw new UnsupportedOperationException();
  159. return this.fullName;
  160. }
  161. /**
  162. * Returns the string representation.
  163. * @return The string <code>getName() + ":" + getClassName()</code>.
  164. */
  165. public String toString ()
  166. {
  167. // Specified by class documentation.
  168. return name + ":" + className;
  169. }
  170. // These field names are fixed by the serialization spec.
  171. private String name;
  172. private String className;
  173. private boolean isRel;
  174. private String fullName;
  175. }