Name.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* Name.java -- Name build up from different components
  2. Copyright (C) 2000, 2001, 2004, 2005 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. import java.util.Enumeration;
  34. /**
  35. * Interface descriping a name build up from different components.
  36. * The components are represented as <code>String</code>s which are
  37. * ordered from most significant to least significant. There are methods to
  38. * get the number of components. Methods to get a particular component or group
  39. * of components. Components can be added as <code>String</code>s or
  40. * <code>Name</code>s and a component can be removed from any position in the
  41. * <code>Name</code>.
  42. * A <code>Name</code> can be compared to another <code>Name</code> and it can
  43. * be checked if a particular <code>Name</code> starts or ends with the same
  44. * components as another <code>Name</code>. Finally <code>Name</code>s can be
  45. * serialized and cloned.
  46. * <p>
  47. * Since <code>Name</code>s can be empty (have no components) methods that
  48. * return a <code>Name</code> will never return <code>null</code>.
  49. *
  50. * @since 1.3
  51. * @author Anthony Green (green@redhat.com)
  52. * @author Mark Wielaard (mark@klomp.org)
  53. */
  54. public interface Name extends Cloneable, Serializable, Comparable<Object>
  55. {
  56. // This class is implemented as gnu.javax.naming.ictxImpl.trans.GnuName
  57. long serialVersionUID = -3617482732056931635L;
  58. /**
  59. * Returns the number of components of this <code>Name</code>.
  60. * The returned number can be zero.
  61. */
  62. int size();
  63. /**
  64. * Returns <code>true</code> if the number of components of this
  65. * <code>Name</code> is zero, <code>false</code> otherwise.
  66. */
  67. boolean isEmpty();
  68. /**
  69. * Returns a non-null (but possibly empty) <code>Enumeration</code> of the
  70. * components of the <code>Name</code> as <code>String</code>s.
  71. */
  72. Enumeration<String> getAll();
  73. /**
  74. * Gets the component at the given index.
  75. *
  76. * @exception ArrayIndexOutOfBoundsException if the given index is smaller
  77. * then zero or greater then or equal to <code>size()</code>.
  78. */
  79. String get(int i);
  80. /**
  81. * Returns the components till the given index as a <code>Name</code>.
  82. * The returned <code>Name</code> can be modified without changing the
  83. * original.
  84. *
  85. * @param posn the ending position, exclusive
  86. *
  87. * @exception ArrayIndexOutOfBoundsException if the given index is smaller
  88. * then zero or greater then or equal to <code>size()</code>.
  89. */
  90. Name getPrefix(int posn);
  91. /**
  92. * Returns the components from the given index till the end as a
  93. * <code>Name</code>.
  94. * The returned <code>Name</code> can be modified without changing the
  95. * original.
  96. *
  97. * @param posn the starting position, inclusive. If it is equal to the size
  98. * of the name, the empty name is returned.
  99. *
  100. * @exception ArrayIndexOutOfBoundsException if the given index is smaller
  101. * then zero or greater then or equal to <code>size()</code>.
  102. */
  103. Name getSuffix(int posn);
  104. /**
  105. * Adds the given <code>String</code> component to the end of this
  106. * <code>Name</code>. The method modifies the current <code>Name</code> and
  107. * then returns it.
  108. *
  109. * @exception InvalidNameException if the given <code>String</code> is not a
  110. * valid component for this <code>Name</code>.
  111. */
  112. Name add(String comp) throws InvalidNameException;
  113. /**
  114. * Inserts the given <code>String</code> component to this <code>Name</code>
  115. * at the given index. The method modifies the current <code>Name</code> and
  116. * then returns it.
  117. *
  118. * @exception ArrayIndexOutOfBoundsException if the given index is smaller
  119. * then zero or greater then or equal to <code>size()</code>.
  120. * @exception InvalidNameException if the given <code>String</code> is not a
  121. * valid component for this <code>Name</code>.
  122. */
  123. Name add(int posn, String comp) throws InvalidNameException;
  124. /**
  125. * Adds all the components of the given <code>Name</code> to the end of this
  126. * <code>Name</code>. The method modifies the current <code>Name</code> and
  127. * then returns it.
  128. *
  129. * @exception InvalidNameException if any of the given components is not a
  130. * valid component for this <code>Name</code>.
  131. */
  132. Name addAll(Name suffix) throws InvalidNameException;
  133. /**
  134. * Inserts all the components of the given <code>Name</code> to this
  135. * <code>Name</code> at the given index. Components after this index
  136. * (if any) are shifted up. The method modifies the current
  137. * <code>Name</code> and then returns it.
  138. *
  139. * @exception ArrayIndexOutOfBoundsException if the given index is smaller
  140. * then zero or greater then or equal to <code>size()</code>.
  141. * @exception InvalidNameException if any of the given components is not a
  142. * valid component for this <code>Name</code>.
  143. */
  144. Name addAll(int posn, Name n) throws InvalidNameException;
  145. /**
  146. * Removes the component at the given index from this <code>Name</code>.
  147. * The method modifies the current <code>Name</code> and then returns it.
  148. *
  149. * @exception InvalidNameException if the given <code>String</code> is not a
  150. * valid component for this <code>Name</code>.
  151. */
  152. Object remove(int posn) throws InvalidNameException;
  153. /**
  154. * Returns <code>true</code> if this <code>Name</code> starts with the
  155. * components of the given <code>Name</code>, <code>false</code> otherwise.
  156. */
  157. boolean startsWith(Name name);
  158. /**
  159. * Returns <code>true</code> if this <code>Name</code> ends with the
  160. * components of the given <code>Name</code>, <code>false</code> otherwise.
  161. */
  162. boolean endsWith(Name name);
  163. /**
  164. * Compares the given object to this <code>Name</code>.
  165. * Returns a negative value if the given <code>Object</code> is smaller then
  166. * this <code>Name</code>, a positive value if the <code>Object</code> is
  167. * bigger, and zero if the are equal. If the <code>Object</code> is not of
  168. * a class that can be compared to the class of this <code>Name</code> then
  169. * a <code>ClassCastException</code> is thrown. Note that it is not
  170. * guaranteed that <code>Name</code>s implemented in different classes can
  171. * be compared. The definition of smaller, bigger and equal is up to the
  172. * actual implementing class.
  173. */
  174. int compareTo(Object obj);
  175. /**
  176. * Returns a clone of this <code>Name</code>. It will be a deep copy of
  177. * all the components of the <code>Name</code> so that changes to components
  178. * of the components does not change the component in this <code>Name</code>.
  179. */
  180. Object clone();
  181. }