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