com.infoengine.util
Class LdapEntry

java.lang.Object
  extended bycom.infoengine.util.LdapEntry
Direct Known Subclasses:
CommandDelegate, Package, PropertyEntry, Repository, RepositoryType, TypeId

public class LdapEntry
extends Object

Represents an entry within an LDAP directory.

Instances of this class can only be instantiated through their corresponding LdapDirectory implementation.

See Also:
LdapDirectory

Field Summary
private  Vector createdDns
           
private  Vector deletedAttrs
           
private  LdapDirectory directory
           
private  String dn
           
private  Group entry
           
private static Hashtable namingAttributes
           
private static Hashtable objectClasses
           
 
Constructor Summary
protected LdapEntry()
          Constructs an empty LdapEntry object.
(package private) LdapEntry(LdapDirectory d)
          Constructs an empty LdapEntry object tied an LdapDirectory implementation.
protected LdapEntry(LdapDirectory d, Group g)
          Constructs an LdapEntry object associated with an LdapDirectory and containing the information with Group.
 
Method Summary
 void addAttributeValue(String name, String value)
          Adds an attribute value to a multi-valued attribute.
 void addObjectClass(String oc)
          Adds an objectClass to this entry.
 void create()
          Creates this entry.
 void createDn()
          Creates this entry and all missing parents.
 void delete()
          Deletes this entry.
 boolean differs()
          Checks to see if this object is different from the LDAP entry it represents.
static Element dn2element(String dn)
           
static Element dn2element(String dn, Hashtable objClasses, Hashtable nmgAttributes)
           
 boolean exists()
          Checks to see if the underlying LDAP directory contains the entry for this entry's DN.
protected static Group find(LdapDirectory directory, String scope, String filter)
          Finds an entry using an LdapDirectory from the root with a scope and filter.
protected static Group find(LdapDirectory directory, String base, String scope, String filter)
          Finds an entry using an LdapDirectory from a search base with a scope and filter.
protected static Group find(Url u)
          Performs a search using a Url.
 String[] getAttributeNames()
          Gets a list of this object's current attribute names.
 String getAttributeValue(String attrName)
          Gets the value for an attribute name.
 String[] getAttributeValues(String attrName)
          Gets a list of attribute values for an attribute name.
 String[] getCreatedDns()
          Gets parent DNs created as a result of createDn().
 String getDn()
          Gets the DN of this entry.
protected  Element getElement()
          Gets the underlying I*E element that contains this entry's LDAP data.
(package private) static LdapEntry getEntry(LdapDirectory directory, String dn)
          Gets an LdapEntry by DN.
 LdapDirectory getLdapDirectory()
          Gets the LdapDirectory this LdapEntry belongs to.
 String[] getObjectClasses()
          Gets the current list of objectClasses for this entry.
 boolean hasChildren()
          Checks to see if this entry contains other entries.
protected  Group lookup()
          Looks up this entry by DN.
protected static Group lookup(LdapDirectory directory, String dn)
          Looks up a single entry by DN.
 boolean refresh()
          Reloads this entry from the underlying LDAP directory.
 void setAttributeValue(String name, String value)
          Sets an attribute value.
 void setDn(String dn)
          Sets the DN of this entry
protected  void setElement(Element e)
          Sets the underlying I*E element that contains this entry's LDAP data.
protected  void setLdapDirectory(LdapDirectory d)
          Sets this object's LdapDirectory object.
 String toString()
          Returns a String representation of this entry.
 void update()
          Updates this entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

directory

private LdapDirectory directory

dn

private String dn

entry

private Group entry

createdDns

private Vector createdDns

deletedAttrs

private Vector deletedAttrs

objectClasses

private static Hashtable objectClasses

namingAttributes

private static Hashtable namingAttributes
Constructor Detail

LdapEntry

protected LdapEntry()
Constructs an empty LdapEntry object.


LdapEntry

LdapEntry(LdapDirectory d)
Constructs an empty LdapEntry object tied an LdapDirectory implementation.

Parameters:
d - The LdapDirectory.

LdapEntry

protected LdapEntry(LdapDirectory d,
                    Group g)
Constructs an LdapEntry object associated with an LdapDirectory and containing the information with Group.

Parameters:
d - The LdapDirectory.
g - The I*E Group containing the entry's information.
Method Detail

getLdapDirectory

public LdapDirectory getLdapDirectory()
Gets the LdapDirectory this LdapEntry belongs to.

Returns:
This entry's LdapDirectory object.
See Also:
LdapDirectory

setLdapDirectory

protected void setLdapDirectory(LdapDirectory d)
Sets this object's LdapDirectory object.

Parameters:
d - The LdapDirectory.
See Also:
LdapDirectory

getDn

public String getDn()
Gets the DN of this entry.

Returns:
The DN or null if not set.

setDn

public void setDn(String dn)
Sets the DN of this entry

Parameters:
dn - The DN.

getElement

protected Element getElement()
Gets the underlying I*E element that contains this entry's LDAP data.

Returns:
The I*E Element.

setElement

protected void setElement(Element e)
Sets the underlying I*E element that contains this entry's LDAP data.

Parameters:
e - The I*E Element.

setAttributeValue

public void setAttributeValue(String name,
                              String value)
Sets an attribute value.

For example setAttributeValue ( "sn", "Johnson" );

To remove an attribute value pass null for the value. To actually apply changes the update() method must be called.

Parameters:
name - The attribute name.
value - The attribute value.
See Also:
update()

addAttributeValue

public void addAttributeValue(String name,
                              String value)
Adds an attribute value to a multi-valued attribute.

For example addAttributeValue ( "ptcProperty", "name=value" );

If the attribute has not been set yet then the attribute will be added. To actually apply changes the update() method must be called.

Parameters:
name - The attribute name.
value - The attribute value.
See Also:
update()

getAttributeNames

public String[] getAttributeNames()
Gets a list of this object's current attribute names.

Returns:
The attribute names.

getAttributeValues

public String[] getAttributeValues(String attrName)
Gets a list of attribute values for an attribute name.

Parameters:
attrName - The attribute name.
Returns:
The list of attribute value or null if none.
See Also:
getAttributeNames()

getAttributeValue

public String getAttributeValue(String attrName)
Gets the value for an attribute name. If the attribute named is multi-valued this method will return the first value.

Parameters:
attrName - The attribute name.
Returns:
The first value or null if none.

getObjectClasses

public String[] getObjectClasses()
Gets the current list of objectClasses for this entry.

Returns:
The object class list.

addObjectClass

public void addObjectClass(String oc)
Adds an objectClass to this entry. Thus expanding the number of acceptable attributes.

Parameters:
oc - The objectClass to add.

refresh

public boolean refresh()
Reloads this entry from the underlying LDAP directory. Any changes made wihtout a call to update() will be lost.

Returns:
true if refresh was successful.

exists

public boolean exists()
Checks to see if the underlying LDAP directory contains the entry for this entry's DN.

Returns:
true if the directory contains this entry.

hasChildren

public boolean hasChildren()
Checks to see if this entry contains other entries.

Returns:
true if children are found.

differs

public boolean differs()
Checks to see if this object is different from the LDAP entry it represents.

This method will return true if:

Returns:
true if this object and the LDAP entry it represents differ.

create

public void create()
            throws IEException
Creates this entry.

Throws:
IEException

createDn

public void createDn()
              throws IEException
Creates this entry and all missing parents.

Missing parent entries can only be one of:

Throws:
IEException
See Also:
getCreatedDns()

getCreatedDns

public String[] getCreatedDns()
Gets parent DNs created as a result of createDn().

Returns:
The list of DNs created or a zero length array.
See Also:
createDn()

delete

public void delete()
            throws IEException
Deletes this entry.

Throws:
IEException

update

public void update()
            throws IEException
Updates this entry.

Throws:
IEException

find

protected static Group find(LdapDirectory directory,
                            String scope,
                            String filter)
Finds an entry using an LdapDirectory from the root with a scope and filter.

Parameters:
directory - The LdapDirectory.
scope - The search scope.
filter - The search filter.
Returns:
The Group representing the search results or null if not found or error.

find

protected static Group find(LdapDirectory directory,
                            String base,
                            String scope,
                            String filter)
Finds an entry using an LdapDirectory from a search base with a scope and filter.

Parameters:
directory - The LdapDirectory.
base - The search base.
scope - The search scope.
filter - The search filter.
Returns:
The Group representing the search results or null if not found or error.

find

protected static Group find(Url u)
Performs a search using a Url.

Parameters:
u - The Url.
Returns:
The Group representing the search results or null if not found or error.

lookup

protected static Group lookup(LdapDirectory directory,
                              String dn)
Looks up a single entry by DN.

Parameters:
directory - The directory.
dn - The DN to lookup.
Returns:
The Group representing the search results or null if not found.

lookup

protected Group lookup()
Looks up this entry by DN.

Returns:
The Group representing this entry.

getEntry

static LdapEntry getEntry(LdapDirectory directory,
                          String dn)
Gets an LdapEntry by DN.

Parameters:
directory - The LdapDirectory
dn - The entry to lookup
Returns:
The LdapEntry or null if not found.

toString

public String toString()
Returns a String representation of this entry.

Form is LDIF without support for binary or UTF-8.

Returns:
LDIF

dn2element

public static Element dn2element(String dn)
                          throws IEException
Parameters:
dn - The dn
Returns:
An I*E Element that could be used to construct the entry at dn.
Throws:
IEException

dn2element

public static Element dn2element(String dn,
                                 Hashtable objClasses,
                                 Hashtable nmgAttributes)
                          throws IEException
Parameters:
dn - The dn
objClasses - Hashtable of naming attribute to objectClass. e.g. cn -> top, ptcSubtree
nmgAttributes - Hashtable of naming attribute to naming attribute(s). e.g. cn -> cn,sn
Returns:
An I*E Element that could be used to construct the entry at dn.
Throws:
IEException