Package com.unboundid.ldap.sdk.persist
Class ObjectEncoder
java.lang.Object
com.unboundid.ldap.sdk.persist.ObjectEncoder
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DefaultObjectEncoder
@Extensible
@ThreadSafety(level=INTERFACE_THREADSAFE)
public abstract class ObjectEncoder
extends Object
implements Serializable
This class provides an API for converting between Java objects and LDAP
attributes. Concrete instances of this class must provide a default
zero-argument constructor.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal AttributeTypeDefinitionConstructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value of the specified field.abstract AttributeTypeDefinitionConstructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value of the specified field.final AttributeTypeDefinitionConstructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value returned by the specified method.abstract AttributeTypeDefinitionConstructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value returned by the specified method.abstract voiddecodeField(Field field, Object object, Attribute attribute) Updates the provided object to assign a value for the specified field from the contents of the given attribute.abstract AttributeencodeFieldValue(Field field, Object value, String name) Encodes the provided field to an LDAP attribute.abstract AttributeencodeMethodValue(Method method, Object value, String name) Encodes the provided method to an LDAP attribute.abstract voidinvokeSetter(Method method, Object object, Attribute attribute) Updates the provided object to invoke the specified method to set a value from the contents of the given attribute.voidAssigns anullvalue to the provided field, if possible.voidInvokes the provided setter method with a single argument that will set anullvalue for that method, if possible.abstract booleansupportsMultipleValues(Field field) Indicates whether the provided field can hold multiple values.abstract booleansupportsMultipleValues(Method method) Indicates whether the provided setter method takes an argument that can hold multiple values.abstract booleansupportsType(Type t) Indicates whether this object encoder may be used to encode or decode objects of the specified type.
-
Constructor Details
-
ObjectEncoder
public ObjectEncoder()
-
-
Method Details
-
supportsType
Indicates whether this object encoder may be used to encode or decode objects of the specified type.- Parameters:
t- The type of object for which to make the determination.- Returns:
trueif this object encoder may be used for objects of the specified type, orfalseif not.
-
constructAttributeType
@NotNull public final AttributeTypeDefinition constructAttributeType(@NotNull Field f) throws LDAPPersistException Constructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value of the specified field. Note that the object identifier used for the constructed attribute type definition is not required to be valid or unique.- Parameters:
f- The field for which to construct an LDAP attribute type definition. It will include theLDAPFieldannotation type.- Returns:
- The constructed attribute type definition.
- Throws:
LDAPPersistException- If this object encoder does not support encoding values for the associated field type.
-
constructAttributeType
@NotNull public abstract AttributeTypeDefinition constructAttributeType(@NotNull Field f, @NotNull OIDAllocator a) throws LDAPPersistException Constructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value of the specified field.- Parameters:
f- The field for which to construct an LDAP attribute type definition. It will include theLDAPFieldannotation type.a- The OID allocator to use to generate the object identifier. It must not benull.- Returns:
- The constructed attribute type definition.
- Throws:
LDAPPersistException- If this object encoder does not support encoding values for the associated field type.
-
constructAttributeType
@NotNull public final AttributeTypeDefinition constructAttributeType(@NotNull Method m) throws LDAPPersistException Constructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value returned by the specified method. Note that the object identifier used for the constructed attribute type definition is not required to be valid or unique.- Parameters:
m- The method for which to construct an LDAP attribute type definition. It will include theLDAPGetterannotation type.- Returns:
- The constructed attribute type definition.
- Throws:
LDAPPersistException- If this object encoder does not support encoding values for the associated method type.
-
constructAttributeType
@NotNull public abstract AttributeTypeDefinition constructAttributeType(@NotNull Method m, @NotNull OIDAllocator a) throws LDAPPersistException Constructs a definition for an LDAP attribute type which may be added to the directory server schema to allow it to hold the value returned by the specified method. Note that the object identifier used for the constructed attribute type definition is not required to be valid or unique.- Parameters:
m- The method for which to construct an LDAP attribute type definition. It will include theLDAPGetterannotation type.a- The OID allocator to use to generate the object identifier. It must not benull.- Returns:
- The constructed attribute type definition.
- Throws:
LDAPPersistException- If this object encoder does not support encoding values for the associated method type.
-
supportsMultipleValues
Indicates whether the provided field can hold multiple values.- Parameters:
field- The field for which to make the determination. It must be marked with theLDAPFieldannotation.- Returns:
trueif the provided field can hold multiple values, orfalseif not.
-
supportsMultipleValues
Indicates whether the provided setter method takes an argument that can hold multiple values.- Parameters:
method- The setter method for which to make the determination. It must be marked with theLDAPSetterannotation type and conform to the constraints associated with that annotation.- Returns:
trueif the provided method takes an argument that can hold multiple values, orfalseif not.
-
encodeFieldValue
@NotNull public abstract Attribute encodeFieldValue(@NotNull Field field, @NotNull Object value, @NotNull String name) throws LDAPPersistException Encodes the provided field to an LDAP attribute.- Parameters:
field- The field to be encoded.value- The value for the field in the object to be encoded.name- The name to use for the constructed attribute.- Returns:
- The attribute containing the encoded representation of the provided field.
- Throws:
LDAPPersistException- If a problem occurs while attempting to construct an attribute for the field.
-
encodeMethodValue
@NotNull public abstract Attribute encodeMethodValue(@NotNull Method method, @NotNull Object value, @NotNull String name) throws LDAPPersistException Encodes the provided method to an LDAP attribute.- Parameters:
method- The method to be encoded.value- The value returned by the method in the object to be encoded.name- The name to use for the constructed attribute.- Returns:
- The attribute containing the encoded representation of the provided method value.
- Throws:
LDAPPersistException- If a problem occurs while attempting to construct an attribute for the method.
-
decodeField
public abstract void decodeField(@NotNull Field field, @NotNull Object object, @NotNull Attribute attribute) throws LDAPPersistException Updates the provided object to assign a value for the specified field from the contents of the given attribute.- Parameters:
field- The field to update in the provided object.object- The object to be updated.attribute- The attribute whose value(s) should be used to update the specified field in the given object.- Throws:
LDAPPersistException- If a problem occurs while attempting to assign a value to the specified field.
-
setNull
Assigns anullvalue to the provided field, if possible. If the field type is primitive and cannot be assigned anullvalue, then a default primitive value will be assigned instead (0 for numeric values, false forbooleanvalues, and the null character forcharvalues).- Parameters:
f- The field to which thenullvalue should be assigned. It must not benulland must be marked with theLDAPFieldannotation.o- The object to be updated. It must not benull, and the class must be marked with theannotation.- Throws:
LDAPPersistException- If a problem occurs while attempting to assign anullvalue to the specified field.
-
setNull
Invokes the provided setter method with a single argument that will set anullvalue for that method, if possible. If the argument type is and cannot be assigned anullvalue, then a default primitive value will be assigned instead (0 for numeric values, false forbooleanvalues, and the null character forcharvalues).- Parameters:
m- The setter method that should be used to set thenullvalue. It must not benull, and must have theLDAPSetterannotation.o- The object to be updated. It must not benull, and the class must be marked with theannotation.- Throws:
LDAPPersistException- If a problem occurs while attempting to assign anullvalue to the specified field.
-
invokeSetter
public abstract void invokeSetter(@NotNull Method method, @NotNull Object object, @NotNull Attribute attribute) throws LDAPPersistException Updates the provided object to invoke the specified method to set a value from the contents of the given attribute.- Parameters:
method- The method to invoke in the provided object.object- The object to be updated.attribute- The attribute whose value(s) should be used to update the specified method in the given object.- Throws:
LDAPPersistException- If a problem occurs while attempting to determine the value or invoke the specified method.
-