org.apache.directory.shared.ldap.name
Class LdapName

java.lang.Object
  extended byorg.apache.directory.shared.ldap.name.LdapName
All Implemented Interfaces:
java.lang.Cloneable, javax.naming.Name, java.io.Serializable

public class LdapName
extends java.lang.Object
implements javax.naming.Name

A distinguished name implementation for LDAPv3.

Version:
$Revision: 379008 $
Author:
Alex Karasulu, $Author: akarasulu $
See Also:
Serialized Form

Field Summary
static LdapName EMPTY_LDAP_NAME
           
 
Constructor Summary
LdapName()
          Creates the default empty name.
LdapName(java.lang.String dn)
          Creates the name by parsing a distinguished name String.
 
Method Summary
 javax.naming.Name add(int a_posn, java.lang.String a_comp)
          Adds a single component at a specified position within this name.
 javax.naming.Name add(java.lang.String a_comp)
          Adds a single component to the end of this name.
 javax.naming.Name addAll(int a_posn, javax.naming.Name a_name)
          Adds the components of a name -- in order -- at a specified position within this name.
 javax.naming.Name addAll(javax.naming.Name a_suffix)
          Adds the components of a name -- in order -- to the end of this name.
 java.lang.Object clone()
          Generates a new copy of this name.
 int compareTo(java.lang.Object an_obj)
          Compares this name with another name for order.
 boolean endsWith(javax.naming.Name a_name)
          Determines whether this name ends with a specified suffix.
 boolean equals(java.lang.Object obj)
           
 java.lang.String get(int a_posn)
          Retrieves a component of this name using 0 based indexing from the right most significant name component to the left least significant name component.
 java.util.Enumeration getAll()
          Retrieves the components of this name as an enumeration of Strings starting in order from the most significant name component on the right to the least significant name component on the left.
static DnParser getNameParser()
          Easy conventient method to get ahold of the NameParser singleton for all distinguished names within the LDAP namespace.
 javax.naming.Name getPrefix(int a_posn)
          Creates a name whose components consist of a prefix of the components in this name.
 java.lang.String getRdn()
          Gets the Rdn of this LdapName.
static java.lang.String getRdn(javax.naming.Name a_dn)
          Gets the Rdn of a distinguished name.
 javax.naming.Name getSuffix(int a_posn)
          Creates a name whose components consist of a suffix of the components of this name.
 int hashCode()
          Gets the hashcode of the string representation of this name.
 boolean isEmpty()
          Determines whether this name is empty.
 java.lang.Object remove(int a_posn)
          Removes a component from this name.
 int size()
          Returns the number of components in this name.
 boolean startsWith(javax.naming.Name a_name)
          Determines whether this name starts with a specified prefix.
 java.lang.String toString()
          Overriden to printout the entire LdapName with all name components in comma separated format.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_LDAP_NAME

public static LdapName EMPTY_LDAP_NAME
Constructor Detail

LdapName

public LdapName()
Creates the default empty name. ToString returns the empty string ""


LdapName

public LdapName(java.lang.String dn)
         throws javax.naming.NamingException
Creates the name by parsing a distinguished name String.

Parameters:
dn - the distinguished name as a String.
Throws:
javax.naming.NamingException - if a parser cannot be initialized or the name is invalid
Method Detail

clone

public java.lang.Object clone()
Generates a new copy of this name. Subsequent changes to the components of this name will not affect the new copy, and vice versa.

Specified by:
clone in interface javax.naming.Name
Returns:
a copy of this name
See Also:
Object.clone()

compareTo

public int compareTo(java.lang.Object an_obj)
Compares this name with another name for order. Returns a negative integer, zero, or a positive integer as this name is less than, equal to, or greater than the given name.

LDAP names contain the most significant component on the right and the least significant component on the left. This fact must be considered while comparing name components lexographically to determine the correct ordering of names.

Case is NOT ignored while matching names. Matching rules in an LDAP schema are needed to correctly determine whether case matters or not. Every attribute in the name is presumed to take on the IA5String syntax which does not ignore case while matching. Note that rather than ignore case here we let normalization occur before hand which will make case irrelavent to begin with before this comarison is made. So matching for case is a good idea here.

Specified by:
compareTo in interface javax.naming.Name
Parameters:
an_obj - the non-null object to compare against.
Returns:
a negative integer, zero, or a positive integer as this name is less than, equal to, or greater than the given name
Throws:
java.lang.ClassCastException - if obj is not a Name of a type that may be compared with this name
See Also:
Comparable.compareTo(Object)

size

public int size()
Returns the number of components in this name.

Specified by:
size in interface javax.naming.Name
Returns:
the number of components in this name

isEmpty

public boolean isEmpty()
Determines whether this name is empty. An empty name is one with zero components.

Specified by:
isEmpty in interface javax.naming.Name
Returns:
true if this name is empty, false otherwise

getAll

public java.util.Enumeration getAll()
Retrieves the components of this name as an enumeration of Strings starting in order from the most significant name component on the right to the least significant name component on the left. The effect on the enumeration of updates to this name is undefined. If the name has zero components, an empty (non-null) enumeration is returned.

Specified by:
getAll in interface javax.naming.Name
Returns:
an enumeration of the components of this name, each a string

get

public java.lang.String get(int a_posn)
Retrieves a component of this name using 0 based indexing from the right most significant name component to the left least significant name component. So the right most name component would be at index 0, and the left least significant name component would be at index size() - 1.

Specified by:
get in interface javax.naming.Name
Parameters:
a_posn - the 0-based index of the component to retrieve. Must be in the range [0,size()).
Returns:
the component at index posn
Throws:
java.lang.ArrayIndexOutOfBoundsException - if posn is outside the specified range

getSuffix

public javax.naming.Name getSuffix(int a_posn)
Creates a name whose components consist of a suffix of the components of this name. Subsequent changes to this name will not affect the name that is returned and vice versa.

Specified by:
getSuffix in interface javax.naming.Name
Parameters:
a_posn - the 0-based index of the component at which to stop. Must be in the range [0,size()].
Returns:
a name consisting of the components at indexes in the range [0,posn).
Throws:
java.lang.ArrayIndexOutOfBoundsException - if posn is outside the specified range

getPrefix

public javax.naming.Name getPrefix(int a_posn)
Creates a name whose components consist of a prefix of the components in this name. Subsequent changes to this name do not affect the name that is returned and vice versa.

Specified by:
getPrefix in interface javax.naming.Name
Parameters:
a_posn - the 0-based index of the component at which to start. Must be in the range [0,size()].
Returns:
a name consisting of the components at indexes in the range [posn,size()). If posn is equal to size(), an empty name is returned.
Throws:
java.lang.IndexOutOfBoundsException - if posn is outside the specified range

startsWith

public boolean startsWith(javax.naming.Name a_name)
Determines whether this name starts with a specified prefix. A name n is a prefix if it is equal to getPrefix(n.size()).

Specified by:
startsWith in interface javax.naming.Name
Parameters:
a_name - the name to check
Returns:
true if n is a prefix of this name, false otherwise

endsWith

public boolean endsWith(javax.naming.Name a_name)
Determines whether this name ends with a specified suffix. A name n is a suffix if it is equal to getSuffix(size()-n.size()).

Specified by:
endsWith in interface javax.naming.Name
Parameters:
a_name - the name to check
Returns:
true if n is a suffix of this name, false otherwise

addAll

public javax.naming.Name addAll(javax.naming.Name a_suffix)
                         throws javax.naming.InvalidNameException
Adds the components of a name -- in order -- to the end of this name.

Specified by:
addAll in interface javax.naming.Name
Parameters:
a_suffix - the components to add
Returns:
the updated name (not a new one)
Throws:
javax.naming.InvalidNameException - if suffix is not a valid name, or if the addition of the components would violate the syntax rules of this name

addAll

public javax.naming.Name addAll(int a_posn,
                                javax.naming.Name a_name)
                         throws javax.naming.InvalidNameException
Adds the components of a name -- in order -- at a specified position within this name. Components of this name at or after the index of the first new component are shifted up (away from 0) to accommodate the new components.

Specified by:
addAll in interface javax.naming.Name
Parameters:
a_name - the components to add
a_posn - the index in this name at which to add the new components. Must be in the range [0,size()].
Returns:
the updated name (not a new one)
Throws:
java.lang.ArrayIndexOutOfBoundsException - if posn is outside the specified range
javax.naming.InvalidNameException - if n is not a valid name, or if the addition of the components would violate the syntax rules of this name

add

public javax.naming.Name add(java.lang.String a_comp)
                      throws javax.naming.InvalidNameException
Adds a single component to the end of this name.

Specified by:
add in interface javax.naming.Name
Parameters:
a_comp - the component to add
Returns:
the updated name (not a new one)
Throws:
javax.naming.InvalidNameException - if adding comp would violate the syntax rules of this name

add

public javax.naming.Name add(int a_posn,
                             java.lang.String a_comp)
                      throws javax.naming.InvalidNameException
Adds a single component at a specified position within this name. Components of this name at or after the index of the new component are shifted up by one (away from index 0) to accommodate the new component.

Specified by:
add in interface javax.naming.Name
Parameters:
a_comp - the component to add
a_posn - the index at which to add the new component. Must be in the range [0,size()].
Returns:
the updated name (not a new one)
Throws:
java.lang.ArrayIndexOutOfBoundsException - if posn is outside the specified range
javax.naming.InvalidNameException - if adding comp would violate the syntax rules of this name

remove

public java.lang.Object remove(int a_posn)
                        throws javax.naming.InvalidNameException
Removes a component from this name. The component of this name at the specified position is removed. Components with indexes greater than this position are shifted down (toward index 0) by one.

Specified by:
remove in interface javax.naming.Name
Parameters:
a_posn - the index of the component to remove. Must be in the range [0,size()).
Returns:
the component removed (a String)
Throws:
java.lang.IndexOutOfBoundsException - if posn is outside the specified range
javax.naming.InvalidNameException - if deleting the component would violate the syntax rules of the name

toString

public java.lang.String toString()
Overriden to printout the entire LdapName with all name components in comma separated format.

Returns:
the string representation of this LdapName.

equals

public boolean equals(java.lang.Object obj)
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Gets the hashcode of the string representation of this name.

See Also:
Object.hashCode()

getNameParser

public static DnParser getNameParser()
                              throws javax.naming.NamingException
Easy conventient method to get ahold of the NameParser singleton for all distinguished names within the LDAP namespace.

Returns:
the DN name parser for the LDAP namespace
Throws:
javax.naming.NamingException - if the parser could not be initialized.

getRdn

public java.lang.String getRdn()
Gets the Rdn of this LdapName.

Returns:
the rdn

getRdn

public static java.lang.String getRdn(javax.naming.Name a_dn)
Gets the Rdn of a distinguished name.

Parameters:
a_dn - the LDAP based Name to get the Rdn of
Returns:
the rdn


Copyright © 2003-2006 . All Rights Reserved.