1. /*
  2. * @(#)Name.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. import java.util.Enumeration;
  12. /**
  13. * The <tt>Name</tt> interface represents a generic name -- an ordered
  14. * sequence of components. It can be a composite name (names that
  15. * span multiple namespaces), or a compound name (names that are
  16. * used within individual hierarchical naming systems).
  17. *
  18. * <p> There can be different implementations of <tt>Name</tt> for example,
  19. * composite names, URLs, or namespace-specific compound names.
  20. *
  21. * <p> The components of a name are numbered. The indexes of a name
  22. * with N components range from 0 up to, but not including, N. This
  23. * range may be written as [0,N).
  24. * The most significant component is at index 0.
  25. * An empty name has no components.
  26. *
  27. * <p> None of the methods in this interface accept null as a valid
  28. * value for a parameter that is a name or a name component.
  29. * Likewise, methods that return a name or name component never return null.
  30. *
  31. * <p> An instance of a <tt>Name</tt> may not be synchronized against
  32. * concurrent multithreaded access if that access is not read-only.
  33. *
  34. * @author Rosanna Lee
  35. * @author Scott Seligman
  36. * @author R. Vasudevan
  37. * @version 1.5 00/02/02
  38. * @since 1.3
  39. */
  40. public interface Name extends Cloneable, java.io.Serializable {
  41. /**
  42. * Generates a new copy of this name.
  43. * Subsequent changes to the components of this name will not
  44. * affect the new copy, and vice versa.
  45. *
  46. * @return a copy of this name
  47. *
  48. * @see Object#clone()
  49. */
  50. public Object clone();
  51. /**
  52. * Compares this name with another name for order.
  53. * Returns a negative integer, zero, or a positive integer as this
  54. * name is less than, equal to, or greater than the given name.
  55. *
  56. * <p> As with <tt>Object.equals()</tt>, the notion of ordering for names
  57. * depends on the class that implements this interface.
  58. * For example, the ordering may be
  59. * based on lexicographical ordering of the name components.
  60. * Specific attributes of the name, such as how it treats case,
  61. * may affect the ordering. In general, two names of different
  62. * classes may not be compared.
  63. *
  64. * @param obj the non-null object to compare against.
  65. * @return a negative integer, zero, or a positive integer as this name
  66. * is less than, equal to, or greater than the given name
  67. * @throws ClassCastException if obj is not a <tt>Name</tt> of a
  68. * type that may be compared with this name
  69. *
  70. * @see Comparable#compareTo(Object)
  71. */
  72. public int compareTo(Object obj);
  73. /**
  74. * Returns the number of components in this name.
  75. *
  76. * @return the number of components in this name
  77. */
  78. public int size();
  79. /**
  80. * Determines whether this name is empty.
  81. * An empty name is one with zero components.
  82. *
  83. * @return true if this name is empty, false otherwise
  84. */
  85. public boolean isEmpty();
  86. /**
  87. * Retrieves the components of this name as an enumeration
  88. * of strings. The effect on the enumeration of updates to
  89. * this name is undefined. If the name has zero components,
  90. * an empty (non-null) enumeration is returned.
  91. *
  92. * @return an enumeration of the components of this name, each a string
  93. */
  94. public Enumeration getAll();
  95. /**
  96. * Retrieves a component of this name.
  97. *
  98. * @param posn
  99. * the 0-based index of the component to retrieve.
  100. * Must be in the range [0,size()).
  101. * @return the component at index posn
  102. * @throws ArrayIndexOutOfBoundsException
  103. * if posn is outside the specified range
  104. */
  105. public String get(int posn);
  106. /**
  107. * Creates a name whose components consist of a prefix of the
  108. * components of this name. Subsequent changes to
  109. * this name will not affect the name that is returned and vice versa.
  110. *
  111. * @param posn
  112. * the 0-based index of the component at which to stop.
  113. * Must be in the range [0,size()].
  114. * @return a name consisting of the components at indexes in
  115. * the range [0,posn).
  116. * @throws ArrayIndexOutOfBoundsException
  117. * if posn is outside the specified range
  118. */
  119. public Name getPrefix(int posn);
  120. /**
  121. * Creates a name whose components consist of a suffix of the
  122. * components in this name. Subsequent changes to
  123. * this name do not affect the name that is returned and vice versa.
  124. *
  125. * @param posn
  126. * the 0-based index of the component at which to start.
  127. * Must be in the range [0,size()].
  128. * @return a name consisting of the components at indexes in
  129. * the range [posn,size()). If posn is equal to
  130. * size(), an empty name is returned.
  131. * @throws ArrayIndexOutOfBoundsException
  132. * if posn is outside the specified range
  133. */
  134. public Name getSuffix(int posn);
  135. /**
  136. * Determines whether this name starts with a specified prefix.
  137. * A name <tt>n</tt> is a prefix if it is equal to
  138. * <tt>getPrefix(n.size())</tt>.
  139. *
  140. * @param n
  141. * the name to check
  142. * @return true if <tt>n</tt> is a prefix of this name, false otherwise
  143. */
  144. public boolean startsWith(Name n);
  145. /**
  146. * Determines whether this name ends with a specified suffix.
  147. * A name <tt>n</tt> is a suffix if it is equal to
  148. * <tt>getSuffix(size()-n.size())</tt>.
  149. *
  150. * @param n
  151. * the name to check
  152. * @return true if <tt>n</tt> is a suffix of this name, false otherwise
  153. */
  154. public boolean endsWith(Name n);
  155. /**
  156. * Adds the components of a name -- in order -- to the end of this name.
  157. *
  158. * @param suffix
  159. * the components to add
  160. * @return the updated name (not a new one)
  161. *
  162. * @throws InvalidNameException if <tt>suffix</tt> is not a valid name,
  163. * or if the addition of the components would violate the syntax
  164. * rules of this name
  165. */
  166. public Name addAll(Name suffix) throws InvalidNameException;
  167. /**
  168. * Adds the components of a name -- in order -- at a specified position
  169. * within this name.
  170. * Components of this name at or after the index of the first new
  171. * component are shifted up (away from 0) to accommodate the new
  172. * components.
  173. *
  174. * @param n
  175. * the components to add
  176. * @param posn
  177. * the index in this name at which to add the new
  178. * components. Must be in the range [0,size()].
  179. * @return the updated name (not a new one)
  180. *
  181. * @throws ArrayIndexOutOfBoundsException
  182. * if posn is outside the specified range
  183. * @throws InvalidNameException if <tt>n</tt> is not a valid name,
  184. * or if the addition of the components would violate the syntax
  185. * rules of this name
  186. */
  187. public Name addAll(int posn, Name n) throws InvalidNameException;
  188. /**
  189. * Adds a single component to the end of this name.
  190. *
  191. * @param comp
  192. * the component to add
  193. * @return the updated name (not a new one)
  194. *
  195. * @throws InvalidNameException if adding <tt>comp</tt> would violate
  196. * the syntax rules of this name
  197. */
  198. public Name add(String comp) throws InvalidNameException;
  199. /**
  200. * Adds a single component at a specified position within this name.
  201. * Components of this name at or after the index of the new component
  202. * are shifted up by one (away from index 0) to accommodate the new
  203. * component.
  204. *
  205. * @param comp
  206. * the component to add
  207. * @param posn
  208. * the index at which to add the new component.
  209. * Must be in the range [0,size()].
  210. * @return the updated name (not a new one)
  211. *
  212. * @throws ArrayIndexOutOfBoundsException
  213. * if posn is outside the specified range
  214. * @throws InvalidNameException if adding <tt>comp</tt> would violate
  215. * the syntax rules of this name
  216. */
  217. public Name add(int posn, String comp) throws InvalidNameException;
  218. /**
  219. * Removes a component from this name.
  220. * The component of this name at the specified position is removed.
  221. * Components with indexes greater than this position
  222. * are shifted down (toward index 0) by one.
  223. *
  224. * @param posn
  225. * the index of the component to remove.
  226. * Must be in the range [0,size()).
  227. * @return the component removed (a String)
  228. *
  229. * @throws ArrayIndexOutOfBoundsException
  230. * if posn is outside the specified range
  231. * @throws InvalidNameException if deleting the component
  232. * would violate the syntax rules of the name
  233. */
  234. public Object remove(int posn) throws InvalidNameException;
  235. }