org.apache.directory.shared.ldap.util
Class NamespaceTools

java.lang.Object
  extended byorg.apache.directory.shared.ldap.util.NamespaceTools

public class NamespaceTools
extends java.lang.Object

Tools dealing with common Naming operations.

Version:
$Revision: 379008 $
Author:
Alex Karasulu, $Author: akarasulu $

Constructor Summary
NamespaceTools()
           
 
Method Summary
static java.lang.String[] getCompositeComponents(java.lang.String compositeNameComponent)
          Gets the '+' appended components of a composite name component.
static java.lang.String getLastComponent(java.lang.String a_name)
          Fast and efficiently get last index of a comma from a_name and return substring from comma to end of the string.
static java.lang.String getNamespaceString(javax.naming.Name a_name)
          Generates the string representation of a name.
static java.lang.String getNamespaceString(java.lang.String a_base, javax.naming.Name a_name)
          Generates the string representation of a name off of a base prefix.
static java.lang.String getParent(java.lang.String a_childDN)
          Given a child distinguished name this method gets the distinguished name of the parent.
static java.lang.String getRdn(java.lang.String a_name)
          Quickly splits off the relative distinguished name component.
static java.lang.String getRdnAttribute(java.lang.String a_rdn)
          Gets the attribute of a single attribute rdn or name component.
static java.lang.String getRdnValue(java.lang.String a_rdn)
          Gets the value of a single name component of a distinguished name.
static javax.naming.Name getRelativeName(javax.naming.Name ancestor, javax.naming.Name descendant)
          Gets the relative name between an ancestor and a potential descendant.
static boolean hasCompositeComponents(java.lang.String name)
          Checks to see if a name has name complex name components in it.
static java.lang.String inferLdapName(java.lang.String realm)
          Uses the algorithm in RFC 2247 to infer an LDAP name from a Kerberos realm name or a DNS domain name.
static boolean isDescendant(javax.naming.Name a_ancestor, javax.naming.Name a_descendant)
          Tests to see if a candidate entry is a descendant of a base.
static boolean isRoot(java.lang.String a_dn)
          Checks to see if a distinguished name is a root.
static boolean isSibling(javax.naming.Name a_name1, javax.naming.Name a_name2)
          Checks to see if two names are siblings.
static java.lang.String setRdn(java.lang.String a_name, java.lang.String a_rdn)
          Sets the rdn of a distinguished name string.
 java.lang.String toLowerAttributeType(java.lang.String nameComponent)
          Lowercases the attribute of a complex name component or a simple one with a single attribute value pair.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NamespaceTools

public NamespaceTools()
Method Detail

isRoot

public static boolean isRoot(java.lang.String a_dn)
                      throws javax.naming.InvalidNameException
Checks to see if a distinguished name is a root.

Parameters:
a_dn - distinguished name to test.
Returns:
true if it has only one component, false otherwise.
Throws:
javax.naming.InvalidNameException - if a_dn is not syntactically correctly

getParent

public static java.lang.String getParent(java.lang.String a_childDN)
                                  throws javax.naming.InvalidNameException
Given a child distinguished name this method gets the distinguished name of the parent. If the child is only composed of one component then null is returned.

Parameters:
a_childDN - the distinguished name of the child.
Returns:
the parent's distinguished name, or null if the child is a root.
Throws:
javax.naming.InvalidNameException - if dn is not syntactically correctly

getNamespaceString

public static java.lang.String getNamespaceString(javax.naming.Name a_name)
                                           throws javax.naming.InvalidNameException
Generates the string representation of a name.

Parameters:
a_name - the Name object to convert to a string.
Returns:
the name as a string.
Throws:
javax.naming.InvalidNameException - if the name is a federated composite name.

getNamespaceString

public static java.lang.String getNamespaceString(java.lang.String a_base,
                                                  javax.naming.Name a_name)
                                           throws javax.naming.InvalidNameException
Generates the string representation of a name off of a base prefix.

Parameters:
a_base - the prefix of the name.
a_name - the name to add to the prefix.
Returns:
the name as a string off of a base.
Throws:
javax.naming.InvalidNameException - if the name is a federated composite name or if a_base is an invalid DN.

getLastComponent

public static java.lang.String getLastComponent(java.lang.String a_name)
Fast and efficiently get last index of a comma from a_name and return substring from comma to end of the string.

Parameters:
a_name - the name from which the last component is to be extracted.
Returns:
the last component in a_name.

getRdn

public static java.lang.String getRdn(java.lang.String a_name)
Quickly splits off the relative distinguished name component.

Parameters:
a_name - the distinguished name or a name fragment
Returns:
the rdn TODO the name rdn is misused rename refactor this method

setRdn

public static java.lang.String setRdn(java.lang.String a_name,
                                      java.lang.String a_rdn)
Sets the rdn of a distinguished name string.

Parameters:
a_name - the distinguished name to append the rdn to
a_rdn - the relative distinguished name to append
Returns:
the appended dn with the extra rdn added TODO the name rdn is misused rename refactor this method

getRdnAttribute

public static java.lang.String getRdnAttribute(java.lang.String a_rdn)
Gets the attribute of a single attribute rdn or name component.

Parameters:
a_rdn - the name component
Returns:
the attribute name TODO the name rdn is misused rename refactor this method

getRdnValue

public static java.lang.String getRdnValue(java.lang.String a_rdn)
Gets the value of a single name component of a distinguished name.

Parameters:
a_rdn - the name component to get the value from
Returns:
the value of the single name component TODO the name rdn is misused rename refactor this method

isSibling

public static boolean isSibling(javax.naming.Name a_name1,
                                javax.naming.Name a_name2)
Checks to see if two names are siblings.

Parameters:
a_name1 - the first name
a_name2 - the second name
Returns:
true if the names are siblings, false otherwise.

isDescendant

public static boolean isDescendant(javax.naming.Name a_ancestor,
                                   javax.naming.Name a_descendant)
Tests to see if a candidate entry is a descendant of a base.

Parameters:
a_ancestor - the base ancestor
a_descendant - the candidate to test for descendancy
Returns:
true if the candidate is a descendant

getRelativeName

public static javax.naming.Name getRelativeName(javax.naming.Name ancestor,
                                                javax.naming.Name descendant)
                                         throws javax.naming.NamingException
Gets the relative name between an ancestor and a potential descendant. Both name arguments must be normalized. The returned name is also normalized.

Parameters:
ancestor - the normalized distinguished name of the ancestor context
descendant - the normalized distinguished name of the descendant context
Returns:
the relatve normalized name between the ancestor and the descendant contexts
Throws:
javax.naming.NamingException - if the contexts are not related in the ancestual sense

inferLdapName

public static java.lang.String inferLdapName(java.lang.String realm)
Uses the algorithm in RFC 2247 to infer an LDAP name from a Kerberos realm name or a DNS domain name.

Parameters:
realm - the realm or domain name
Returns:
the LDAP name for the realm or domain

getCompositeComponents

public static java.lang.String[] getCompositeComponents(java.lang.String compositeNameComponent)
                                                 throws javax.naming.NamingException
Gets the '+' appended components of a composite name component.

Parameters:
compositeNameComponent - a single name component not a whole name
Returns:
the components of the complex name component in order
Throws:
javax.naming.NamingException - if nameComponent is invalid (starts with a +)

hasCompositeComponents

public static boolean hasCompositeComponents(java.lang.String name)
                                      throws javax.naming.NamingException
Checks to see if a name has name complex name components in it.

Parameters:
name -
Returns:
Throws:
javax.naming.NamingException

toLowerAttributeType

public java.lang.String toLowerAttributeType(java.lang.String nameComponent)
                                      throws javax.naming.NamingException
Lowercases the attribute of a complex name component or a simple one with a single attribute value pair.

Parameters:
nameComponent - the name component to lower the case of attribute types
Returns:
the name component with all attribute types lowercased
Throws:
javax.naming.NamingException - if the component is malformed


Copyright © 2003-2006 . All Rights Reserved.