ca.tnt.ldaputils.annotations.processing
Class LdapEntityLoader

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

public class LdapEntityLoader
extends LdapEntityHandler

IAnnotationHandler implementation that processes LPA annotations for the purpose of loading the LdapEntity annotated instance from the ldap query results.

FEATURE MINOR native support for Map (issue-13) Created : 22-Aug-2010 12:44:56 AM MST

Author:
Trenton D. Adams

Field Summary
 
Fields inherited from class ca.tnt.ldaputils.annotations.processing.LdapEntityHandler
entity, manager
 
Constructor Summary
LdapEntityLoader()
          does nothing
LdapEntityLoader(Object newObject, Attributes attributes, LdapName dn)
          creates a new LdapEntityHandler with given parameters.
 
Method Summary
protected  boolean isDnSet()
          Checks if the distinguished name was set
protected  boolean preProcessAnnotation(LdapEntity annotation, Class annotatedClass)
          Does annotation pre-processing, in case the subclass wants to do something special before anything is processed.
protected  Object processAttribute(Field field, LdapAttribute attrAnnotation)
          Simple attribute processing.
protected  void processDN(Class annotatedClass, Field field)
          Processing for DN annotation
protected  Object processForeignAggregate(Field field, Class<?> aggClass, String dnReference, LdapAttribute attrAnnotation)
          Called to process a foreign aggregate.
protected  void processLdapAttributes(Field field)
          Processing for LdapAttribute annotation where name is '*'
protected  Object processLocalAggregate(Field field, Class<?> aggClass, LdapAttribute attrAnnotation)
          Do what you need to for the local aggregate.
 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, processManager, validateDN, validateObjectClasses
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LdapEntityLoader

public LdapEntityLoader()
does nothing


LdapEntityLoader

public LdapEntityLoader(Object newObject,
                        Attributes attributes,
                        LdapName dn)
creates a new LdapEntityHandler with given parameters.

Parameters:
newObject - the new object to process
attributes - the attributes from ldap
dn - the ldap distinguished name
Method Detail

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

preProcessAnnotation

protected boolean preProcessAnnotation(LdapEntity annotation,
                                       Class annotatedClass)
Description copied from class: LdapEntityHandler
Does annotation pre-processing, in case the subclass wants to do something special before anything is processed. We implement the default here, which is to return true.

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

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

processDN

protected void processDN(Class annotatedClass,
                         Field field)
                  throws IllegalAccessException,
                         NoSuchMethodException
Description copied from class: LdapEntityHandler
Processing for DN annotation

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

processAttribute

protected Object processAttribute(Field field,
                                  LdapAttribute attrAnnotation)
                           throws NamingException,
                                  IllegalAccessException
Description copied from class: LdapEntityHandler
Simple attribute processing. Called when we're doing with attributes only, and not aggregates.

Note, the object returned should be null if you are not attempting to inject anything into this field. That may be the case if you are implementing a handler to "read" from the instance, rather than write to it.

Specified by:
processAttribute in class LdapEntityHandler
Parameters:
field - the field being processed
attrAnnotation - the LdapAttribute annotation instance being processed
Returns:
the value for the field
Throws:
ClassCastException - if we attempt to store an attribute value in an unsupported field Class type. Your problem, not ours, until we support TypeHandler for non aggregates
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
Description copied from class: LdapEntityHandler
Called to process a foreign aggregate. It's up to the subclass to do what it likes. Returning null indicates the subclass does not want anything stored in the LdapEntity annotated instance, but is instead reading from the instance.

Tip on implementing: aggregates are stored in one of two ways.

  1. directly into an aggregate object, if you know that it's a single valued attribute, or your business practise makes it always single valued.
  2. in a collection of aggregate objects, of some sort. e.g. SortedSet<MyAggregateClass> myAggregates
Therefore, the easiest way to determine if it's a single aggregate, is to check the field type, against the LdapAttribute.aggregateClass() by asking if they are equal. See the LdapEntityLoader source for an example.

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:
the new aggregate instance, or collection of aggregate instances; subclasses may also return null
Throws:
NamingException - general JNDI exception wrapper for any errors that occur in the directory
IllegalAccessException - if java policies prevent access to fields via reflection

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.


isDnSet

protected boolean isDnSet()
Checks if the distinguished name was set

Returns:
true if the distinguished name was processed and set, false otherwise.

processLocalAggregate

protected Object processLocalAggregate(Field field,
                                       Class<?> aggClass,
                                       LdapAttribute attrAnnotation)
                                throws IllegalAccessException,
                                       InstantiationException,
                                       NamingException
Description copied from class: LdapEntityHandler
Do what you need to for the local aggregate. Returning null indicates the subclass does not want anything stored in the LdapEntity annotated instance, but is instead reading from the instance.

A local aggregate is an aggregate object which will be injected into the object field, which has requested it via LdapAttribute.aggregateClass(), and is also using the existing LDAP entry's attributes as a basis for the object. See the documentation on LdapAttribute.aggregateClass() for more information.

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:
the new fieldValue if one is needed; subclasses may also return null
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