ca.tnt.ldaputils.annotations.processing
Class LdapEntityBinder

Package class diagram package LdapEntityBinder
java.lang.Object
  extended by ca.tnt.ldaputils.annotations.processing.LdapEntityHandler
      extended by ca.tnt.ldaputils.annotations.processing.LdapEntityBinder
All Implemented Interfaces:
IAnnotationHandler

public class LdapEntityBinder
extends LdapEntityHandler

IAnnotationHandler implementation that processes LPA annotations for the purpose of generating JNDI Attributes for the bind call.

Created : 02/01/11 1:09 PM MST

Author:
Trenton D. Adams

Field Summary
 
Fields inherited from class ca.tnt.ldaputils.annotations.processing.LdapEntityHandler
entity, manager
 
Constructor Summary
LdapEntityBinder(Object entityInstance)
          Initializes the entity binder with the instance to be bound to ldap.
 
Method Summary
 List<Attributes> getAttributesList()
          Retrieve the processed attributes for LDAP.
 LdapName getDn()
          Returns the dn processed during processDN(Class, Field)
 List<LdapName> getDnList()
          Get the list of DNs that match the list of Attributes returned by getAttributesList()

WARNING! WARNING! WARNING! you may only call this method a SINGLE time.

protected  boolean preProcessAnnotation(LdapEntity annotation, Class annotatedClass)
          grabs the object classes from the LdapEntity.requiredObjectClasses() annotation field, and puts them in an Attribute, and stores them for return from getAttributesList()
protected  Object processAttribute(Field field, LdapAttribute attrAnnotation)
          Processes the field for binding, generates a JNDI Attribute for it, and puts it in the list of JNDI Attributes.
protected  void processDN(Class annotatedClass, Field field)
          Only calls LdapEntityHandler.validateDN(Class, Field), and then stores the dn for return through the getDn() method.
protected  Object processForeignAggregate(Field field, Class<?> aggClass, String dnReference, LdapAttribute attrAnnotation)
          Process the field as a foreign aggregate for binding, generates a JNDI Attribute for it, and stores it in the list of JNDI Attributes
protected  void processLdapAttributes(Field field)
          Processing for LdapAttribute annotation where name is '*'
protected  Object processLocalAggregate(Field field, Class<?> aggClass, LdapAttribute attrAnnotation)
          Process the field as a local aggregate for binding, generates a series of JNDI Attribute for it, and stores them in the list of JNDI Attributes.
protected  void processManager(Field field)
          Does nothing, and does not call the super, as the entity binder does not require the handling of manager instances.
 void setManager(LdapManager managerInstance)
          Sets the established ldap manager object, which should be pre-authenticated.
 void validateProcessing()
          Method for validating the processing of the annotations.
 
Methods inherited from class ca.tnt.ldaputils.annotations.processing.LdapEntityHandler
getAnnotatedClass, getAnnotationClass, getReferencedEntity, isMultiValued, noAnnotation, processAggregate, processAnnotation, processLdapAttribute, validateDN, validateObjectClasses
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LdapEntityBinder

public LdapEntityBinder(Object entityInstance)
Initializes the entity binder with the instance to be bound to ldap.

Parameters:
entityInstance - the LdapEntity annotated entityInstance instance that needs to be bound to ldap.
Method Detail

processManager

protected void processManager(Field field)
                       throws IllegalAccessException
Does nothing, and does not call the super, as the entity binder does not require the handling of manager instances.

Overrides:
processManager in class LdapEntityHandler
Parameters:
field - the field to inject the manager to
Throws:
IllegalAccessException - if java policies prevent access to fields via reflection

processLdapAttributes

protected void processLdapAttributes(Field field)
                              throws IllegalAccessException
Description copied from class: LdapEntityHandler
Processing for LdapAttribute annotation where name is '*'

Specified by:
processLdapAttributes in class LdapEntityHandler
Parameters:
field - the field the annotation is on
Throws:
IllegalAccessException - if java policies prevent access to fields via reflection

processAttribute

protected Object processAttribute(Field field,
                                  LdapAttribute attrAnnotation)
                           throws NamingException,
                                  IllegalAccessException
Processes the field for binding, generates a JNDI Attribute for it, and puts it in the list of JNDI Attributes.

Specified by:
processAttribute in class LdapEntityHandler
Parameters:
field - the field being processed
attrAnnotation - the LdapAttribute annotation instance being processed
Returns:
always null, as we are not attempting to write to the instance, we're binding to LDAP using the instance values.
Throws:
NamingException - general JNDI exception wrapper for any errors that occur in the directory
IllegalAccessException - if java policies prevent access to fields via reflection

processForeignAggregate

protected Object processForeignAggregate(Field field,
                                         Class<?> aggClass,
                                         String dnReference,
                                         LdapAttribute attrAnnotation)
                                  throws NamingException,
                                         IllegalAccessException
Process the field as a foreign aggregate for binding, generates a JNDI Attribute for it, and stores it in the list of JNDI Attributes

Specified by:
processForeignAggregate in class LdapEntityHandler
Parameters:
field - the field being processed
aggClass - the aggregate class as defined by LdapAttribute.aggregateClass()
dnReference - the "properly" formatted dn, with bind parameter, as returned by the LdapAttribute.referencedDNMethod() method
attrAnnotation - the LdapAttribute annotation instance being processed
Returns:
always null, as we are not attempting to write to the instance, we're binding to LDAP using the instance values.
Throws:
NamingException - general JNDI exception wrapper for any errors that occur in the directory
IllegalAccessException - if java policies prevent access to fields via reflection

processLocalAggregate

protected Object processLocalAggregate(Field field,
                                       Class<?> aggClass,
                                       LdapAttribute attrAnnotation)
                                throws IllegalAccessException,
                                       InstantiationException,
                                       NamingException
Process the field as a local aggregate for binding, generates a series of JNDI Attribute for it, and stores them in the list of JNDI Attributes.

Developer Note: Attributes of a local aggregate are to be part of the main entry. So, we simply copy them into the Attributes. Local aggregates are not allowed to have foreign aggregates inside of them.

Specified by:
processLocalAggregate in class LdapEntityHandler
Parameters:
field - the field being processed
aggClass - the aggregate class, if needed.
attrAnnotation - the LdapAttribute annotation instance being processed
Returns:
always null, as we are not attempting to write to the instance, we're binding to LDAP using the instance values.
Throws:
IllegalAccessException - if java policies prevent access to fields via reflection
InstantiationException - if an error occurs creating an aggregate instance
NamingException - general JNDI exception wrapper for any errors that occur in the directory

processDN

protected void processDN(Class annotatedClass,
                         Field field)
                  throws IllegalAccessException,
                         NoSuchMethodException
Only calls LdapEntityHandler.validateDN(Class, Field), and then stores the dn for return through the getDn() method.

Specified by:
processDN in class LdapEntityHandler
Parameters:
annotatedClass - class of the annotated object
field - the field the annotation is on
Throws:
IllegalAccessException - if java policies prevent access to fields via reflection
NoSuchMethodException - if the LdapAttribute.referencedDNMethod() is the name of a method that does not exist

preProcessAnnotation

protected boolean preProcessAnnotation(LdapEntity annotation,
                                       Class annotatedClass)
grabs the object classes from the LdapEntity.requiredObjectClasses() annotation field, and puts them in an Attribute, and stores them for return from getAttributesList()

Overrides:
preProcessAnnotation in class LdapEntityHandler
Parameters:
annotation - the annotation being processed
annotatedClass - the annotated class with the annotation
Returns:
true if nothing went wrong during processing

validateProcessing

public void validateProcessing()
Description copied from interface: IAnnotationHandler
Method for validating the processing of the annotations. This is called after all classes in the class tree have been traversed and processed. This is the final validation, and is meant for problems that could not be detected until traversing the entire class tree. For example, it may be that you require a particular annotation on at least one class in the hierarchy, but your handler doesn't know when the end of Class hierarchy traversal is complete; this method is called after traversal completion.


setManager

public void setManager(LdapManager managerInstance)
Description copied from interface: IAnnotationHandler
Sets the established ldap manager object, which should be pre-authenticated.

Parameters:
managerInstance - the already authenticated manager

getAttributesList

public List<Attributes> getAttributesList()
                                   throws UnsupportedOperationException
Retrieve the processed attributes for LDAP. Each entry in the list is for a single

WARNING! WARNING! WARNING! you may only call this method a SINGLE time. Once it has been called, the list of Attributes objects is immutable, and this method will throw an UnsupportedOperationException.

Returns:
the directory Attributes to be bound
Throws:
UnsupportedOperationException - if you call this method more than once

getDnList

public List<LdapName> getDnList()
Get the list of DNs that match the list of Attributes returned by getAttributesList()

WARNING! WARNING! WARNING! you may only call this method a SINGLE time. Once it has been called, the list of DNs is immutable, and this method will throw an UnsupportedOperationException.

Returns:
the dn list
Throws:
UnsupportedOperationException - if you call this method more than once

getDn

public LdapName getDn()
Returns the dn processed during processDN(Class, Field)

Returns:
the dn