Path: blob/master/src/java.naming/share/classes/javax/naming/Name.java
41152 views
/*1* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming;2627import java.util.Enumeration;2829/**30* The {@code Name} interface represents a generic name -- an ordered31* sequence of components. It can be a composite name (names that32* span multiple namespaces), or a compound name (names that are33* used within individual hierarchical naming systems).34*35* <p> There can be different implementations of {@code Name}; for example,36* composite names, URLs, or namespace-specific compound names.37*38* <p> The components of a name are numbered. The indexes of a name39* with N components range from 0 up to, but not including, N. This40* range may be written as [0,N).41* The most significant component is at index 0.42* An empty name has no components.43*44* <p> None of the methods in this interface accept null as a valid45* value for a parameter that is a name or a name component.46* Likewise, methods that return a name or name component never return null.47*48* <p> An instance of a {@code Name} may not be synchronized against49* concurrent multithreaded access if that access is not read-only.50*51* @author Rosanna Lee52* @author Scott Seligman53* @author R. Vasudevan54* @since 1.355*/5657public interface Name58extends Cloneable, java.io.Serializable, Comparable<Object>59{6061/**62* The class fingerprint that is set to indicate63* serialization compatibility with a previous64* version of the class.65*66* @deprecated A {@code serialVersionUID} field in an interface is67* ineffectual. Do not use; no replacement.68*/69@Deprecated70@SuppressWarnings("serial")71static final long serialVersionUID = -3617482732056931635L;7273/**74* Generates a new copy of this name.75* Subsequent changes to the components of this name will not76* affect the new copy, and vice versa.77*78* @return a copy of this name79*80* @see Object#clone()81*/82public Object clone();8384/**85* Compares this name with another name for order.86* Returns a negative integer, zero, or a positive integer as this87* name is less than, equal to, or greater than the given name.88*89* <p> As with {@code Object.equals()}, the notion of ordering for names90* depends on the class that implements this interface.91* For example, the ordering may be92* based on lexicographical ordering of the name components.93* Specific attributes of the name, such as how it treats case,94* may affect the ordering. In general, two names of different95* classes may not be compared.96*97* @param obj the non-null object to compare against.98* @return a negative integer, zero, or a positive integer as this name99* is less than, equal to, or greater than the given name100* @throws ClassCastException if obj is not a {@code Name} of a101* type that may be compared with this name102*103* @see Comparable#compareTo(Object)104*/105public int compareTo(Object obj);106107/**108* Returns the number of components in this name.109*110* @return the number of components in this name111*/112public int size();113114/**115* Determines whether this name is empty.116* An empty name is one with zero components.117*118* @return true if this name is empty, false otherwise119*/120public boolean isEmpty();121122/**123* Retrieves the components of this name as an enumeration124* of strings. The effect on the enumeration of updates to125* this name is undefined. If the name has zero components,126* an empty (non-null) enumeration is returned.127*128* @return an enumeration of the components of this name, each a string129*/130public Enumeration<String> getAll();131132/**133* Retrieves a component of this name.134*135* @param posn136* the 0-based index of the component to retrieve.137* Must be in the range [0,size()).138* @return the component at index posn139* @throws ArrayIndexOutOfBoundsException140* if posn is outside the specified range141*/142public String get(int posn);143144/**145* Creates a name whose components consist of a prefix of the146* components of this name. Subsequent changes to147* this name will not affect the name that is returned and vice versa.148*149* @param posn150* the 0-based index of the component at which to stop.151* Must be in the range [0,size()].152* @return a name consisting of the components at indexes in153* the range [0,posn).154* @throws ArrayIndexOutOfBoundsException155* if posn is outside the specified range156*/157public Name getPrefix(int posn);158159/**160* Creates a name whose components consist of a suffix of the161* components in this name. Subsequent changes to162* this name do not affect the name that is returned and vice versa.163*164* @param posn165* the 0-based index of the component at which to start.166* Must be in the range [0,size()].167* @return a name consisting of the components at indexes in168* the range [posn,size()). If posn is equal to169* size(), an empty name is returned.170* @throws ArrayIndexOutOfBoundsException171* if posn is outside the specified range172*/173public Name getSuffix(int posn);174175/**176* Determines whether this name starts with a specified prefix.177* A name {@code n} is a prefix if it is equal to178* {@code getPrefix(n.size())}.179*180* @param n181* the name to check182* @return true if {@code n} is a prefix of this name, false otherwise183*/184public boolean startsWith(Name n);185186/**187* Determines whether this name ends with a specified suffix.188* A name {@code n} is a suffix if it is equal to189* {@code getSuffix(size()-n.size())}.190*191* @param n192* the name to check193* @return true if {@code n} is a suffix of this name, false otherwise194*/195public boolean endsWith(Name n);196197/**198* Adds the components of a name -- in order -- to the end of this name.199*200* @param suffix201* the components to add202* @return the updated name (not a new one)203*204* @throws InvalidNameException if {@code suffix} is not a valid name,205* or if the addition of the components would violate the syntax206* rules of this name207*/208public Name addAll(Name suffix) throws InvalidNameException;209210/**211* Adds the components of a name -- in order -- at a specified position212* within this name.213* Components of this name at or after the index of the first new214* component are shifted up (away from 0) to accommodate the new215* components.216*217* @param n218* the components to add219* @param posn220* the index in this name at which to add the new221* components. Must be in the range [0,size()].222* @return the updated name (not a new one)223*224* @throws ArrayIndexOutOfBoundsException225* if posn is outside the specified range226* @throws InvalidNameException if {@code n} is not a valid name,227* or if the addition of the components would violate the syntax228* rules of this name229*/230public Name addAll(int posn, Name n) throws InvalidNameException;231232/**233* Adds a single component to the end of this name.234*235* @param comp236* the component to add237* @return the updated name (not a new one)238*239* @throws InvalidNameException if adding {@code comp} would violate240* the syntax rules of this name241*/242public Name add(String comp) throws InvalidNameException;243244/**245* Adds a single component at a specified position within this name.246* Components of this name at or after the index of the new component247* are shifted up by one (away from index 0) to accommodate the new248* component.249*250* @param comp251* the component to add252* @param posn253* the index at which to add the new component.254* Must be in the range [0,size()].255* @return the updated name (not a new one)256*257* @throws ArrayIndexOutOfBoundsException258* if posn is outside the specified range259* @throws InvalidNameException if adding {@code comp} would violate260* the syntax rules of this name261*/262public Name add(int posn, String comp) throws InvalidNameException;263264/**265* Removes a component from this name.266* The component of this name at the specified position is removed.267* Components with indexes greater than this position268* are shifted down (toward index 0) by one.269*270* @param posn271* the index of the component to remove.272* Must be in the range [0,size()).273* @return the component removed (a String)274*275* @throws ArrayIndexOutOfBoundsException276* if posn is outside the specified range277* @throws InvalidNameException if deleting the component278* would violate the syntax rules of the name279*/280public Object remove(int posn) throws InvalidNameException;281}282283284