Package com.unboundid.ldap.sdk.persist
Class LDAPObjectHandler<T>
- java.lang.Object
-
- com.unboundid.ldap.sdk.persist.LDAPObjectHandler<T>
-
- Type Parameters:
T- The type of object handled by this class.
- All Implemented Interfaces:
java.io.Serializable
@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class LDAPObjectHandler<T> extends java.lang.Object implements java.io.Serializable
This class provides a mechanism for validating, encoding, and decoding objects marked with theLDAPObjectannotation type.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringconstructDN(T o, java.lang.String parentDN)Determines the DN that should be used for the entry associated with the given object.FiltercreateBaseFilter()Retrieves a filter that will match any entry containing the structural and auxiliary classes for this object type.FiltercreateFilter(T o)Retrieves a filter that can be used to search for entries matching the provided object.java.lang.String[]getAttributesToRequest()Retrieves the names of the attributes that should be requested when performing a search.java.lang.String[]getAuxiliaryClasses()Retrieves the names of the auxiliary object classes for objects of the associated type.java.lang.reflect.Constructor<T>getConstructor()Retrieves the constructor used to create a new instance of the appropriate type.DNgetDefaultParentDN()Retrieves the default parent DN for objects of the associated type.java.lang.reflect.FieldgetDNField()Retrieves the field that will be used to hold the DN of the associated entry, if defined.ReadOnlyEntrygetEntry(T o)Retrieves a read-only copy of the entry that was used to initialize the provided object, if available.java.lang.StringgetEntryDN(T o)Retrieves the DN of the entry in which the provided object is stored, if available.java.lang.reflect.FieldgetEntryField()Retrieves the field that will be used to hold a read-only copy of the entry used to create the object instance, if defined.java.util.Map<java.lang.String,FieldInfo>getFields()Retrieves a map of all fields in the class that should be persisted as LDAP attributes.java.util.Map<java.lang.String,GetterInfo>getGetters()Retrieves a map of all getter methods in the class whose values should be persisted as LDAP attributes.java.lang.String[]getLazilyLoadedAttributes()Retrieves the names of the attributes that should be lazily loaded for objects of this type.LDAPObjectgetLDAPObjectAnnotation()Retrieves theLDAPObjectannotation for the associated class.java.util.Map<java.lang.String,SetterInfo>getSetters()Retrieves a map of all setter methods in the class that should be invoked with information read from LDAP attributes.java.lang.StringgetStructuralClass()Retrieves the name of the structural object class for objects of the associated type.LDAPObjectHandler<?>getSuperclassHandler()Retrieves theLDAPObjectHandlerobject for the superclass of the associated type, if it is marked with theLDAPObject annotation.java.lang.String[]getSuperiorClasses()Retrieves the names of the superior object classes for objects of the associated type.java.lang.Class<T>getType()Retrieves the type of object handled by this class.booleanrequestAllAttributes()Indicates whether to request all attributes.
-
-
-
Method Detail
-
getType
public java.lang.Class<T> getType()
Retrieves the type of object handled by this class.- Returns:
- The type of object handled by this class.
-
getSuperclassHandler
public LDAPObjectHandler<?> getSuperclassHandler()
Retrieves theLDAPObjectHandlerobject for the superclass of the associated type, if it is marked with theLDAPObject annotation.- Returns:
- The
LDAPObjectHandlerobject for the superclass of the associated type, ornullif the superclass is not marked with theLDAPObjectannotation.
-
getLDAPObjectAnnotation
public LDAPObject getLDAPObjectAnnotation()
Retrieves theLDAPObjectannotation for the associated class.- Returns:
- The
LDAPObjectannotation for the associated class.
-
getConstructor
public java.lang.reflect.Constructor<T> getConstructor()
Retrieves the constructor used to create a new instance of the appropriate type.- Returns:
- The constructor used to create a new instance of the appropriate type.
-
getDNField
public java.lang.reflect.Field getDNField()
Retrieves the field that will be used to hold the DN of the associated entry, if defined.- Returns:
- The field that will be used to hold the DN of the associated
entry, or
nullif no DN field is defined in the associated object type.
-
getEntryField
public java.lang.reflect.Field getEntryField()
Retrieves the field that will be used to hold a read-only copy of the entry used to create the object instance, if defined.- Returns:
- The field that will be used to hold a read-only copy of the entry
used to create the object instance, or
nullif no entry field is defined in the associated object type.
-
getDefaultParentDN
public DN getDefaultParentDN()
Retrieves the default parent DN for objects of the associated type.- Returns:
- The default parent DN for objects of the associated type.
-
getStructuralClass
public java.lang.String getStructuralClass()
Retrieves the name of the structural object class for objects of the associated type.- Returns:
- The name of the structural object class for objects of the associated type.
-
getAuxiliaryClasses
public java.lang.String[] getAuxiliaryClasses()
Retrieves the names of the auxiliary object classes for objects of the associated type.- Returns:
- The names of the auxiliary object classes for objects of the associated type. It may be empty if no auxiliary classes are defined.
-
getSuperiorClasses
public java.lang.String[] getSuperiorClasses()
Retrieves the names of the superior object classes for objects of the associated type.- Returns:
- The names of the superior object classes for objects of the associated type. It may be empty if no superior classes are defined.
-
requestAllAttributes
public boolean requestAllAttributes()
Indicates whether to request all attributes. This will returntrueif the associatedLDAPObject, or anyLDAPObjectfor any superclass, hasrequestAllAttributesset totrue.- Returns:
trueifLDAPObjecthasrequestAllAttributesset totruefor any class in the hierarchy, orfalseif not.
-
getAttributesToRequest
public java.lang.String[] getAttributesToRequest()
Retrieves the names of the attributes that should be requested when performing a search. It will not include lazily-loaded attributes.- Returns:
- The names of the attributes that should be requested when performing a search.
-
getLazilyLoadedAttributes
public java.lang.String[] getLazilyLoadedAttributes()
Retrieves the names of the attributes that should be lazily loaded for objects of this type.- Returns:
- The names of the attributes that should be lazily loaded for objects of this type. It may be empty if no attributes should be lazily-loaded.
-
getEntryDN
public java.lang.String getEntryDN(T o) throws LDAPPersistException
Retrieves the DN of the entry in which the provided object is stored, if available. The entry DN will not be available if the provided object was not retrieved using the persistence framework, or if the associated class (or one of its superclasses) does not have a field marked with either theLDAPDNFieldorLDAPEntryFieldannotation.- Parameters:
o- The object for which to retrieve the associated entry DN.- Returns:
- The DN of the entry in which the provided object is stored, or
nullif that is not available. - Throws:
LDAPPersistException- If a problem occurred while attempting to obtain the entry DN.
-
getEntry
public ReadOnlyEntry getEntry(T o) throws LDAPPersistException
Retrieves a read-only copy of the entry that was used to initialize the provided object, if available. The entry will only be available if the object was retrieved from the directory using the persistence framework and the associated class (or one of its superclasses) has a field marked with theLDAPEntryFieldannotation.- Parameters:
o- The object for which to retrieve the read-only entry.- Returns:
- A read-only copy of the entry that was used to initialize the
provided object, or
nullif that is not available. - Throws:
LDAPPersistException- If a problem occurred while attempting to obtain the entry DN.
-
getFields
public java.util.Map<java.lang.String,FieldInfo> getFields()
Retrieves a map of all fields in the class that should be persisted as LDAP attributes. The keys in the map will be the lowercase names of the LDAP attributes used to persist the information, and the values will be information about the fields associated with those attributes.- Returns:
- A map of all fields in the class that should be persisted as LDAP attributes.
-
getGetters
public java.util.Map<java.lang.String,GetterInfo> getGetters()
Retrieves a map of all getter methods in the class whose values should be persisted as LDAP attributes. The keys in the map will be the lowercase names of the LDAP attributes used to persist the information, and the values will be information about the getter methods associated with those attributes.- Returns:
- A map of all getter methods in the class whose values should be persisted as LDAP attributes.
-
getSetters
public java.util.Map<java.lang.String,SetterInfo> getSetters()
Retrieves a map of all setter methods in the class that should be invoked with information read from LDAP attributes. The keys in the map will be the lowercase names of the LDAP attributes with the information used to invoke the setter, and the values will be information about the setter methods associated with those attributes.- Returns:
- A map of all setter methods in the class that should be invoked with information read from LDAP attributes.
-
constructDN
public java.lang.String constructDN(T o, java.lang.String parentDN) throws LDAPPersistException
Determines the DN that should be used for the entry associated with the given object. If the provided object was retrieved from the directory using the persistence framework and has a field with either theLDAPDNFieldorLDAPEntryFieldannotation, then the actual DN of the corresponding entry will be returned. Otherwise, it will be constructed using the fields and getter methods marked for inclusion in the entry RDN.- Parameters:
o- The object for which to determine the appropriate DN.parentDN- The parent DN to use for the constructed DN. If a non-nullvalue is provided, then that value will be used as the parent DN (and the empty string will indicate that the generated DN should not have a parent). If the value isnull, then the default parent DN as defined in theLDAPObjectannotation will be used. If the provided parent DN isnulland theLDAPObjectannotation does not specify a default parent DN, then the generated DN will not have a parent.- Returns:
- The entry DN for the provided object.
- Throws:
LDAPPersistException- If a problem occurs while obtaining the entry DN, or if the provided parent DN represents an invalid DN.
-
createBaseFilter
public Filter createBaseFilter()
Retrieves a filter that will match any entry containing the structural and auxiliary classes for this object type.- Returns:
- A filter that will match any entry containing the structural and auxiliary classes for this object type.
-
createFilter
public Filter createFilter(T o) throws LDAPPersistException
Retrieves a filter that can be used to search for entries matching the provided object. It will be constructed as an AND search using all fields with a non-nullvalue and that have aLDAPFieldannotation with theinFilterelement set totrue, and all getter methods that return a non-nullvalue and have aLDAPGetterannotation with theinFilterelement set totrue.- Parameters:
o- The object for which to create the search filter.- Returns:
- A filter that can be used to search for entries matching the provided object.
- Throws:
LDAPPersistException- If it is not possible to construct a search filter for some reason (e.g., because the provided object does not have any non-nullfields or getters that are marked for inclusion in filters).
-
-