1 /* Name.java -- Name build up from different components
2 Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 import java.io.Serializable;
41 import java.util.Enumeration;
44 * Interface descriping a name build up from different components.
45 * The components are represented as <code>String</code>s which are
46 * ordered from most significant to least significant. There are methods to
47 * get the number of components. Methods to get a particular component or group
48 * of components. Components can be added as <code>String</code>s or
49 * <code>Name</code>s and a component can be removed from any position in the
51 * A <code>Name</code> can be compared to another <code>Name</code> and it can
52 * be checked if a particular <code>Name</code> starts or ends with the same
53 * components as another <code>Name</code>. Finally <code>Name</code>s can be
54 * serialized and cloned.
56 * Since <code>Name</code>s can be empty (have no components) methods that
57 * return a <code>Name</code> will never return <code>null</code>.
60 * @author Anthony Green (green@redhat.com)
61 * @author Mark Wielaard (mark@klomp.org)
63 public interface Name extends Cloneable, Serializable, Comparable<Object>
65 // This class is implemented as gnu.javax.naming.ictxImpl.trans.GnuName
67 long serialVersionUID = -3617482732056931635L;
70 * Returns the number of components of this <code>Name</code>.
71 * The returned number can be zero.
76 * Returns <code>true</code> if the number of components of this
77 * <code>Name</code> is zero, <code>false</code> otherwise.
82 * Returns a non-null (but possibly empty) <code>Enumeration</code> of the
83 * components of the <code>Name</code> as <code>String</code>s.
85 Enumeration<String> getAll();
88 * Gets the component at the given index.
90 * @exception ArrayIndexOutOfBoundsException if the given index is smaller
91 * then zero or greater then or equal to <code>size()</code>.
96 * Returns the components till the given index as a <code>Name</code>.
97 * The returned <code>Name</code> can be modified without changing the
100 * @param posn the ending position, exclusive
102 * @exception ArrayIndexOutOfBoundsException if the given index is smaller
103 * then zero or greater then or equal to <code>size()</code>.
105 Name getPrefix(int posn);
108 * Returns the components from the given index till the end as a
110 * The returned <code>Name</code> can be modified without changing the
113 * @param posn the starting position, inclusive. If it is equal to the size
114 * of the name, the empty name is returned.
116 * @exception ArrayIndexOutOfBoundsException if the given index is smaller
117 * then zero or greater then or equal to <code>size()</code>.
119 Name getSuffix(int posn);
122 * Adds the given <code>String</code> component to the end of this
123 * <code>Name</code>. The method modifies the current <code>Name</code> and
126 * @exception InvalidNameException if the given <code>String</code> is not a
127 * valid component for this <code>Name</code>.
129 Name add(String comp) throws InvalidNameException;
132 * Inserts the given <code>String</code> component to this <code>Name</code>
133 * at the given index. The method modifies the current <code>Name</code> and
136 * @exception ArrayIndexOutOfBoundsException if the given index is smaller
137 * then zero or greater then or equal to <code>size()</code>.
138 * @exception InvalidNameException if the given <code>String</code> is not a
139 * valid component for this <code>Name</code>.
141 Name add(int posn, String comp) throws InvalidNameException;
144 * Adds all the components of the given <code>Name</code> to the end of this
145 * <code>Name</code>. The method modifies the current <code>Name</code> and
148 * @exception InvalidNameException if any of the given components is not a
149 * valid component for this <code>Name</code>.
151 Name addAll(Name suffix) throws InvalidNameException;
154 * Inserts all the components of the given <code>Name</code> to this
155 * <code>Name</code> at the given index. Components after this index
156 * (if any) are shifted up. The method modifies the current
157 * <code>Name</code> and then returns it.
159 * @exception ArrayIndexOutOfBoundsException if the given index is smaller
160 * then zero or greater then or equal to <code>size()</code>.
161 * @exception InvalidNameException if any of the given components is not a
162 * valid component for this <code>Name</code>.
164 Name addAll(int posn, Name n) throws InvalidNameException;
167 * Removes the component at the given index from this <code>Name</code>.
168 * The method modifies the current <code>Name</code> and then returns it.
170 * @exception InvalidNameException if the given <code>String</code> is not a
171 * valid component for this <code>Name</code>.
173 Object remove(int posn) throws InvalidNameException;
176 * Returns <code>true</code> if this <code>Name</code> starts with the
177 * components of the given <code>Name</code>, <code>false</code> otherwise.
179 boolean startsWith(Name name);
182 * Returns <code>true</code> if this <code>Name</code> ends with the
183 * components of the given <code>Name</code>, <code>false</code> otherwise.
185 boolean endsWith(Name name);
188 * Compares the given object to this <code>Name</code>.
189 * Returns a negative value if the given <code>Object</code> is smaller then
190 * this <code>Name</code>, a positive value if the <code>Object</code> is
191 * bigger, and zero if the are equal. If the <code>Object</code> is not of
192 * a class that can be compared to the class of this <code>Name</code> then
193 * a <code>ClassCastException</code> is thrown. Note that it is not
194 * guaranteed that <code>Name</code>s implemented in different classes can
195 * be compared. The definition of smaller, bigger and equal is up to the
196 * actual implementing class.
198 int compareTo(Object obj);
201 * Returns a clone of this <code>Name</code>. It will be a deep copy of
202 * all the components of the <code>Name</code> so that changes to components
203 * of the components does not change the component in this <code>Name</code>.