1. /*
  2. * @(#)NameClassPair.java 1.5 00/02/02
  3. *
  4. * Copyright 1999, 2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.naming;
  11. /**
  12. * This class represents the object name and class name pair of a binding
  13. * found in a context.
  14. *<p>
  15. * A context consists of name-to-object bindings.
  16. * The NameClassPair class represents the name and the
  17. * class of the bound object. It consists
  18. * of a name and a string representing the
  19. * package-qualified class name.
  20. *<p>
  21. * Use subclassing for naming systems that generate contents of
  22. * a name/class pair dynamically.
  23. *<p>
  24. * A NameClassPair instance is not synchronized against concurrent
  25. * access by multiple threads. Threads that need to access a NameClassPair
  26. * concurrently should synchronize amongst themselves and provide
  27. * the necessary locking.
  28. *
  29. * @author Rosanna Lee
  30. * @author Scott Seligman
  31. * @version 1.5 00/02/02
  32. *
  33. * @see Context#list
  34. * @since 1.3
  35. */
  36. /*<p>
  37. * The serialized form of a NameClassPair object consists of the name (a
  38. * String), class name (a String), and isRelative flag (a boolean).
  39. */
  40. public class NameClassPair implements java.io.Serializable {
  41. /**
  42. * Contains the name of this NameClassPair.
  43. * It is initialized by the constructor and can be updated using
  44. * <tt>setName()</tt>.
  45. * @serial
  46. * @see #getName
  47. * @see #setName
  48. */
  49. private String name;
  50. /**
  51. *Contains the class name contained in this NameClassPair.
  52. * It is initialized by the constructor and can be updated using
  53. * <tt>setClassName()</tt>.
  54. * @serial
  55. * @see #getClassName
  56. * @see #setClassName
  57. */
  58. private String className;
  59. /**
  60. * Records whether the name of this <tt>NameClassPair</tt>
  61. * is relative to the target context.
  62. * It is initialized by the constructor and can be updated using
  63. * <tt>setRelative()</tt>.
  64. * @serial
  65. * @see #isRelative
  66. * @see #setRelative
  67. * @see #getName
  68. * @see #setName
  69. */
  70. private boolean isRel = true;
  71. /**
  72. * Constructs an instance of a NameClassPair given its
  73. * name and class name.
  74. *
  75. * @param name The non-null name of the object. It is relative
  76. * to the <em>target context</em> (which is
  77. * named by the first parameter of the <code>list()</code> method)
  78. * @param className The possibly null class name of the object
  79. * bound to name. It is null if the object bound is null.
  80. * @see #getClassName
  81. * @see #setClassName
  82. * @see #getName
  83. * @see #setName
  84. */
  85. public NameClassPair(String name, String className) {
  86. this.name = name;
  87. this.className = className;
  88. }
  89. /**
  90. * Constructs an instance of a NameClassPair given its
  91. * name, class name, and whether it is relative to the listing context.
  92. *
  93. * @param name The non-null name of the object.
  94. * @param className The possibly null class name of the object
  95. * bound to name. It is null if the object bound is null.
  96. * @param isRelative true if <code>name</code> is a name relative
  97. * to the target context (which is named by
  98. * the first parameter of the <code>list()</code> method);
  99. * false if <code>name</code> is a URL string.
  100. * @see #getClassName
  101. * @see #setClassName
  102. * @see #getName
  103. * @see #setName
  104. * @see #isRelative
  105. * @see #setRelative
  106. */
  107. public NameClassPair(String name, String className, boolean isRelative) {
  108. this.name = name;
  109. this.className = className;
  110. this.isRel = isRelative;
  111. }
  112. /**
  113. * Retrieves the class name of the object bound to the name of this binding.
  114. * If a reference or some other indirect information is bound,
  115. * retrieves the class name of the eventual object that
  116. * will be returned by <tt>Binding.getObject()</tt>.
  117. *
  118. * @return The possibly null class name of object bound.
  119. * It is null if the object bound is null.
  120. * @see Binding#getObject
  121. * @see Binding#getClassName
  122. * @see #setClassName
  123. */
  124. public String getClassName() {
  125. return className;
  126. }
  127. /**
  128. * Retrieves the name of this binding.
  129. * If <tt>isRelative()</tt> is true, this name is relative to the target context
  130. * (which is named by the first parameter of the <tt>list()</tt>).
  131. * If <tt>isRelative()</tt> is false, this name is a URL string.
  132. *
  133. * @return The non-null name of this binding.
  134. * @see #isRelative
  135. * @see #setName
  136. */
  137. public String getName() {
  138. return name;
  139. }
  140. /**
  141. * Sets the name of this binding.
  142. *
  143. * @param name the non-null string to use as the name.
  144. * @see #getName
  145. * @see #setRelative
  146. */
  147. public void setName(String name) {
  148. this.name = name;
  149. }
  150. /**
  151. * Sets the class name of this binding.
  152. *
  153. * @param name the possibly null string to use as the class name.
  154. * If null, <tt>Binding.getClassName()</tt> will return
  155. * the actual class name of the object in the binding.
  156. * The class name will be null if the object bound is null.
  157. * @see #getClassName
  158. * @see Binding#getClassName
  159. */
  160. public void setClassName(String name) {
  161. this.className = name;
  162. }
  163. /**
  164. * Determines whether the name of this binding is
  165. * relative to the target context (which is named by
  166. * the first parameter of the <code>list()</code> method).
  167. * @return true if the name of this binding is relative to the target context;
  168. * false if the name of this binding is a URL string.
  169. * @see #setRelative
  170. * @see #getName
  171. */
  172. public boolean isRelative() {
  173. return isRel;
  174. }
  175. /**
  176. * Sets whether the name of this binding is relative to the target
  177. * context (which is named by the first parameter of the <code>list()</code>
  178. * method).
  179. * @param r If true, the name of binding is relative to the target context;
  180. * if false, the name of binding is a URL string.
  181. * @see #isRelative
  182. * @see #setName
  183. */
  184. public void setRelative(boolean r) {
  185. isRel = r;
  186. }
  187. /**
  188. * Generates the string representation of this name/class pair.
  189. * The string representation consists of the name and class name separated
  190. * by a colon (':').
  191. * The contents of this string is useful
  192. * for debugging and is not meant to be interpreted programmatically.
  193. *
  194. * @return The string representation of this name/class pair.
  195. */
  196. public String toString() {
  197. return (isRelative() ? "" : "(not relative)") + getName() + ": " +
  198. getClassName();
  199. }
  200. /**
  201. * Use serialVersionUID from JNDI 1.1.1 for interoperability
  202. */
  203. private static final long serialVersionUID = 5620776610160863339L;
  204. }