001 /* Name.java -- Name build up from different components 002 Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package javax.naming; 039 040 import java.io.Serializable; 041 import java.util.Enumeration; 042 043 /** 044 * Interface descriping a name build up from different components. 045 * The components are represented as <code>String</code>s which are 046 * ordered from most significant to least significant. There are methods to 047 * get the number of components. Methods to get a particular component or group 048 * of components. Components can be added as <code>String</code>s or 049 * <code>Name</code>s and a component can be removed from any position in the 050 * <code>Name</code>. 051 * A <code>Name</code> can be compared to another <code>Name</code> and it can 052 * be checked if a particular <code>Name</code> starts or ends with the same 053 * components as another <code>Name</code>. Finally <code>Name</code>s can be 054 * serialized and cloned. 055 * <p> 056 * Since <code>Name</code>s can be empty (have no components) methods that 057 * return a <code>Name</code> will never return <code>null</code>. 058 * 059 * @since 1.3 060 * @author Anthony Green (green@redhat.com) 061 * @author Mark Wielaard (mark@klomp.org) 062 */ 063 public interface Name extends Cloneable, Serializable, Comparable<Object> 064 { 065 // This class is implemented as gnu.javax.naming.ictxImpl.trans.GnuName 066 067 long serialVersionUID = -3617482732056931635L; 068 069 /** 070 * Returns the number of components of this <code>Name</code>. 071 * The returned number can be zero. 072 */ 073 int size(); 074 075 /** 076 * Returns <code>true</code> if the number of components of this 077 * <code>Name</code> is zero, <code>false</code> otherwise. 078 */ 079 boolean isEmpty(); 080 081 /** 082 * Returns a non-null (but possibly empty) <code>Enumeration</code> of the 083 * components of the <code>Name</code> as <code>String</code>s. 084 */ 085 Enumeration<String> getAll(); 086 087 /** 088 * Gets the component at the given index. 089 * 090 * @exception ArrayIndexOutOfBoundsException if the given index is smaller 091 * then zero or greater then or equal to <code>size()</code>. 092 */ 093 String get(int i); 094 095 /** 096 * Returns the components till the given index as a <code>Name</code>. 097 * The returned <code>Name</code> can be modified without changing the 098 * original. 099 * 100 * @param posn the ending position, exclusive 101 * 102 * @exception ArrayIndexOutOfBoundsException if the given index is smaller 103 * then zero or greater then or equal to <code>size()</code>. 104 */ 105 Name getPrefix(int posn); 106 107 /** 108 * Returns the components from the given index till the end as a 109 * <code>Name</code>. 110 * The returned <code>Name</code> can be modified without changing the 111 * original. 112 * 113 * @param posn the starting position, inclusive. If it is equal to the size 114 * of the name, the empty name is returned. 115 * 116 * @exception ArrayIndexOutOfBoundsException if the given index is smaller 117 * then zero or greater then or equal to <code>size()</code>. 118 */ 119 Name getSuffix(int posn); 120 121 /** 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 124 * then returns it. 125 * 126 * @exception InvalidNameException if the given <code>String</code> is not a 127 * valid component for this <code>Name</code>. 128 */ 129 Name add(String comp) throws InvalidNameException; 130 131 /** 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 134 * then returns it. 135 * 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>. 140 */ 141 Name add(int posn, String comp) throws InvalidNameException; 142 143 /** 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 146 * then returns it. 147 * 148 * @exception InvalidNameException if any of the given components is not a 149 * valid component for this <code>Name</code>. 150 */ 151 Name addAll(Name suffix) throws InvalidNameException; 152 153 /** 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. 158 * 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>. 163 */ 164 Name addAll(int posn, Name n) throws InvalidNameException; 165 166 /** 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. 169 * 170 * @exception InvalidNameException if the given <code>String</code> is not a 171 * valid component for this <code>Name</code>. 172 */ 173 Object remove(int posn) throws InvalidNameException; 174 175 /** 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. 178 */ 179 boolean startsWith(Name name); 180 181 /** 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. 184 */ 185 boolean endsWith(Name name); 186 187 /** 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. 197 */ 198 int compareTo(Object obj); 199 200 /** 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>. 204 */ 205 Object clone(); 206 }