ca.tnt.ldaputils.impl
Class LDAPEntryImpl

Package class diagram package LDAPEntryImpl
java.lang.Object
  extended by ca.tnt.ldaputils.impl.LDAPEntryImpl
All Implemented Interfaces:
ILdapEntry, Serializable

public class LDAPEntryImpl
extends Object
implements ILdapEntry, Serializable

LDAPObject implementing class. All inheriting classes should implement a getAttributeXAsString() type method, such as getMail(). But they may also need to implement a getAttributeXValues(), such as getMails(). So, it should simply be a plural of the attribute. If an object had getBusinessCategory() it could also have a getBusinessCategories(). The plural versions should ALWAYS return a "List" for consistancy.

Created : 14-Apr-2006 6:29:39 PM MST

TODO : print out all attributes

Author:
Trenton D. Adams
See Also:
Serialized Form

Field Summary
protected  Attributes attributes
          This contains all of the attributes for the object
protected  LdapName dn
           
protected  boolean isNew
           
protected  LinkedHashMap modificationItems
           
protected  boolean modified
           
protected  List objectClasses
           
 
Fields inherited from interface ca.tnt.ldaputils.ILdapEntry
ADD_ATTRIBUTE, REMOVE_ATTRIBUTE, REPLACE_ATTRIBUTE
 
Constructor Summary
LDAPEntryImpl()
          Calling this constructor implies that the object is brand new, and the save() method should act accordingly.
LDAPEntryImpl(Attributes attributes, LdapName dn)
          Creates an LDAPObject that has all of the attributes and their values in the order in which they were found in LDAP.
 
Method Summary
 ILdapEntry convertInstance(int type)
          Converts this object to the given instance.
 boolean equals(Object obj)
           
 List getAttributeValues(String attribute)
           
 Attributes getBindAttributes()
           
 String getCn()
           
 String getCN()
           
 String getDescription()
           
 LdapName getDn()
           
 List getObjectClasses()
          Get's the types of objects this is.
 String getStringAttribute(Attributes attributes, String attribute)
           
 String getStringValue(String attribute)
           
protected  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)
           
 String toString()
           
protected  void updateAttribute(String attrName)
          Updates the specified attribute from LDAP.
protected  void updateObject()
          Updates the attributes from LDAP.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

modified

protected boolean modified

isNew

protected boolean isNew

dn

protected LdapName dn

objectClasses

protected List objectClasses

modificationItems

protected LinkedHashMap modificationItems

attributes

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

Constructor Detail

LDAPEntryImpl

public LDAPEntryImpl(Attributes attributes,
                     LdapName dn)
              throws NamingException
Creates an LDAPObject that has all of the attributes and their values in the order in which they were found in LDAP. If you want a sorted version, just convert them to another utility class, such as TreeSet, or TreeMap.

Parameters:
attributes - the LDAP attributes object as returned by the JNDI APIs.
dn - distinguished name of the object.
Throws:
NamingException - when any errors occur

LDAPEntryImpl

public LDAPEntryImpl()
Calling this constructor implies that the object is brand new, and the save() method should act accordingly.

Method Detail

equals

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

convertInstance

public ILdapEntry convertInstance(int type)
                           throws NamingException
Converts this object to the given instance.

Specified by:
convertInstance in interface ILdapEntry
Parameters:
type - the object type to convert to
Returns:
the new object.
Throws:
NamingException - if conversion fails due to the proper objectClass not being setup.

getObjectClasses

public List 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.

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.

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)
Description copied from interface: ILdapEntry
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)
Description copied from interface: ILdapEntry
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()
Description copied from interface: ILdapEntry
Runs the batch modifications requested through the ILdapEntry.modifyBatchAttribute(int, String, Object)

Specified by:
modifyBatchAttributes in interface ILdapEntry

save

public void save()
Description copied from interface: ILdapEntry
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

updateAttribute

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

TODO : 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.

updateObject

protected void updateObject()
                     throws NamingException
Updates the attributes from LDAP.

TODO : in order for this to work properly, we MUST have all possible attribute names stored in this object as statics so that we will know what to lookup in LDAP. Either that, or we need to just load all attributes.

Throws:
NamingException - - should be replaced with LdapNamingException?

isObjectClass

protected boolean isObjectClass(String objectClass)

getBindAttributes

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

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

toString

public String toString()
Overrides:
toString in class Object