Source for javax.naming.Name

   1: /* Name.java -- Name build up from different components
   2:    Copyright (C) 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   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)
   9: any later version.
  10: 
  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.
  15: 
  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
  19: 02110-1301 USA.
  20: 
  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
  24: combination.
  25: 
  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. */
  37: 
  38: package javax.naming;
  39: 
  40: import java.io.Serializable;
  41: import java.util.Enumeration;
  42: 
  43: /**
  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
  50:  * <code>Name</code>.
  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.
  55:  * <p>
  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>.
  58:  *
  59:  * @since 1.3
  60:  * @author Anthony Green (green@redhat.com)
  61:  * @author Mark Wielaard (mark@klomp.org)
  62:  */
  63: public interface Name extends Cloneable, Serializable, Comparable<Object>
  64: {
  65:   // This class is implemented as gnu.javax.naming.ictxImpl.trans.GnuName
  66: 
  67:   long serialVersionUID = -3617482732056931635L;
  68: 
  69:   /**
  70:    * Returns the number of components of this <code>Name</code>.
  71:    * The returned number can be zero.
  72:    */
  73:   int size();
  74: 
  75:   /**
  76:    * Returns <code>true</code> if the number of components of this
  77:    * <code>Name</code> is zero, <code>false</code> otherwise.
  78:    */
  79:   boolean isEmpty();
  80: 
  81:   /**
  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.
  84:    */
  85:   Enumeration<String> getAll();
  86: 
  87:   /**
  88:    * Gets the component at the given index.
  89:    *
  90:    * @exception ArrayIndexOutOfBoundsException if the given index is smaller
  91:    *            then zero or greater then or equal to <code>size()</code>.
  92:    */
  93:   String get(int i);
  94: 
  95:   /**
  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
  98:    * original.
  99:    *
 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: }