ca.tnt.ldaputils.impl
Class LdapEntry

Package class diagram package LdapEntry
java.lang.Object
  extended by ca.tnt.ldaputils.impl.LdapEntry
All Implemented Interfaces:
ILdapEntry, Comparable
Direct Known Subclasses:
LdapGroup, LdapOrganization

public class LdapEntry
extends Object
implements ILdapEntry, Comparable

Default implementation of an LDAP object. This handles a fair bit of LDAP update capability, by way of using the factory.

Created : 16-Aug-2010 8:05:16 PM MST

Author:
Trenton D. Adams

Field Summary
protected  Attributes attributes
          This contains all of the attributes for the object
protected  boolean isNew
           
protected  LinkedHashMap modificationItems
           
protected  boolean modified
           
protected  List<String> objectClasses
          All objectClass attributes, we know they are Strings
 
Fields inherited from interface ca.tnt.ldaputils.ILdapEntry
ADD_ATTRIBUTE, REMOVE_ATTRIBUTE, REPLACE_ATTRIBUTE
 
Constructor Summary
LdapEntry()
           
 
Method Summary
 int compareTo(Object o)
           
 ILdapEntry convertInstance(int type)
           
 boolean equals(Object o)
           
 Attributes getAttributes()
           
 List getAttributeValues(String attribute)
           
 Attributes getBindAttributes()
           
 String getCn()
           
 String getCN()
           
 String getDescription()
           
 LdapName getDn()
           
 List<String> getObjectClasses()
          Get's the types of objects this is.
 String getStringAttribute(Attributes attributes, String attribute)
           
 String getStringValue(String attribute)
           
 int hashCode()
           
 boolean isObjectClass(String objectClass)
           
 void modifyAttribute(int operation, String attribute, Object value)
          Sets the given attribute right now, and does not delay.
 void modifyBatchAttribute(int operation, String attribute, Object value)
          Please note, the preferred method is to call setXXXX() where XXXX is the attribute name, followed by save().
 void modifyBatchAttributes()
          Runs the batch modifications requested through the ILdapEntry.modifyBatchAttribute(int, String, Object)
 void save()
          Because LDAP operations are expensive, we have a save method.
 void setCn(String cn)
           
 void setDn(LdapName dn)
           
 void setObjectClasses(List<String> objectClasses)
           
 String toString()
           
protected  void updateAttribute(String attrName)
          Updates the specified attribute from LDAP.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

modified

protected boolean modified

isNew

protected boolean isNew

modificationItems

protected LinkedHashMap modificationItems

attributes

protected Attributes attributes
This contains all of the attributes for the object


objectClasses

protected List<String> objectClasses
All objectClass attributes, we know they are Strings

Constructor Detail

LdapEntry

public LdapEntry()
Method Detail

getDn

public LdapName getDn()
Specified by:
getDn in interface ILdapEntry
Returns:
the distinquished name of the object. ie, fully qualified path in LDAP tree.

getDescription

public String getDescription()
Specified by:
getDescription in interface ILdapEntry
Returns:
the description attribute.

convertInstance

public ILdapEntry convertInstance(int type)
                           throws NamingException
Specified by:
convertInstance in interface ILdapEntry
Parameters:
type - the object type to convert to
Returns:
the new converted object
Throws:
NamingException - if any conversion problems occur.

getStringAttribute

public String getStringAttribute(Attributes attributes,
                                 String attribute)
                          throws NamingException
Throws:
NamingException

getAttributeValues

public List getAttributeValues(String attribute)
Specified by:
getAttributeValues in interface ILdapEntry

getStringValue

public String getStringValue(String attribute)
Specified by:
getStringValue in interface ILdapEntry

modifyAttribute

public void modifyAttribute(int operation,
                            String attribute,
                            Object value)
Sets the given attribute right now, and does not delay. This should only be used in the case where there is only one value for the attribute. If there are multiple values, then the modifyBatchAttribute is the one that really needs to be called. If you call this with REPLACE_ATTRIBUTE for instance, and there was multiple entries in LDAP, then the existing entries will be replaced with this one value and only this one value. In addition, if you want to modify multiple attributes at a time, then you should not call this, you should use modifyBatchAttribute().

Specified by:
modifyAttribute in interface ILdapEntry
Parameters:
operation - on of ADD_ATTRIBUTE, REPLACE_ATTRIBUTE, REMOVE_ATTRIBUTE
attribute - the name of the attribute
value - the value of the attribute
See Also:
ADD_ATTRIBUTE, REPLACE_ATTRIBUTE, REMOVE_ATTRIBUTE

modifyBatchAttribute

public void modifyBatchAttribute(int operation,
                                 String attribute,
                                 Object value)
Please note, the preferred method is to call setXXXX() where XXXX is the attribute name, followed by save().

This sets a batch attribute. This means that it will be added to a queue for changing LDAP. You can modify the same attribute multiple times, assuming LDAP supports multivalued attributes for that attribute. You are then required to call modifyBatchAttributes(), which will actually do the operations requested.

You should call this one or more times per attribute, followed by modifyBatchAttributes().

Each time you call this method, for the same attribute, you should specify the same operation, otherwise you will get an IllegalArgumentException, with an appropriate error message.

Specified by:
modifyBatchAttribute in interface ILdapEntry
Parameters:
operation - one of ADD_ATTRIBUTE, REPLACE_ATTRIBUTE, REMOVE_ATTRIBUTE
attribute - the name of the attribute
value - the value of the attribute
See Also:
ADD_ATTRIBUTE, REPLACE_ATTRIBUTE, REMOVE_ATTRIBUTE

modifyBatchAttributes

public void modifyBatchAttributes()
Runs the batch modifications requested through the ILdapEntry.modifyBatchAttribute(int, String, Object)

Specified by:
modifyBatchAttributes in interface ILdapEntry

save

public void save()
Because LDAP operations are expensive, we have a save method. Saves any changes made by setXXXX() methods, where XXXX is an attribute name. Also an alias for modifyBatchAttributes(), but will do nothing unless modifyBatchAtribute() has been called

Specified by:
save in interface ILdapEntry

getBindAttributes

public Attributes getBindAttributes()
Specified by:
getBindAttributes in interface ILdapEntry

updateAttribute

protected void updateAttribute(String attrName)
                        throws NamingException
Updates the specified attribute from LDAP.

MINOR : Instead of using LDAPFactory.getAttributes, using DirContext.getAttributes(). Then we can remove the getAttributes().

Parameters:
attrName - the name of the attribute
Throws:
NamingException - if any LDAP errors occur.

getAttributes

public Attributes getAttributes()

getObjectClasses

public List<String> getObjectClasses()
Description copied from interface: ILdapEntry
Get's the types of objects this is.

Specified by:
getObjectClasses in interface ILdapEntry
Returns:
a list of Strings representing the object class names

getCN

public String getCN()
Specified by:
getCN in interface ILdapEntry
Returns:
the common name attribute.

setObjectClasses

public void setObjectClasses(List<String> objectClasses)

isObjectClass

public boolean isObjectClass(String objectClass)

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable

setDn

public void setDn(LdapName dn)
Specified by:
setDn in interface ILdapEntry

getCn

public String getCn()
Specified by:
getCn in interface ILdapEntry

setCn

public void setCn(String cn)
Specified by:
setCn in interface ILdapEntry