@NotMutable @ThreadSafety(level=COMPLETELY_THREADSAFE) public final class DefaultObjectEncoder extends ObjectEncoder
ObjectEncoder
object that will be used when encoding and decoding fields to be written to
or read from an LDAP directory server.
java.util.concurrent.atomic.AtomicInteger
-- Encoded using the
string representation of the valuejava.util.concurrent.atomic.AtomicLong
-- Encoded using the
string representation of the valuejava.math.BigDecimal
-- Encoded using the string representation
of the valuejava.math.BigInteger
-- Encoded using the string representation
of the valueboolean
-- Encoded as either "TRUE" or "FALSE"java.lang.Boolean
-- Encoded as either "TRUE" or "FALSE"byte[]
-- Encoded as the raw bytes contained in the arraychar[]
-- Encoded as a string containing the characters in the
arrayjava.util.Date
-- Encoded using the generalized time
syntaxcom.unboundid.ldap.sdk.DN
-- Encoded using the string
representation of the valuedouble
-- Encoded using the string representation of the
valuejava.lang.Double
-- Encoded using the string representation of
the valuecom.unboundid.ldap.sdk.Filter
-- Encoded using the string
representation of the valuefloat
-- Encoded using the string representation of the
valuejava.lang.Float
-- Encoded using the string representation of
the valueint
-- Encoded using the string representation of the
valuejava.lang.Integer
-- Encoded using the string representation of
the valuecom.unboundid.ldap.sdk.LDAPURL
-- Encoded using the string
representation of the valuelong
-- Encoded using the string representation of the
valuejava.lang.Long
-- Encoded using the string representation of
the valuecom.unboundid.ldap.sdk.RDN
-- Encoded using the string
representation of the valueshort
-- Encoded using the string representation of the
valuejava.lang.Short
-- Encoded using the string representation of
the valuejava.lang.String
-- Encoded using the valuejava.lang.StringBuffer
-- Encoded using the string
representation of the valuejava.lang.StringBuilder
-- Encoded using the string
representation of the valuejava.net.URI
-- Encoded using the string representation of the
value.java.net.URL
-- Encoded using the string representation of the
value.java.util.UUID
-- Encoded using the string representation of
the valuewriteObject
, readObject
, and
readObjectNoData
methods that use the desired encoding. Alternately,
you may create a custom ObjectEncoder
implementation for that object
type, or use getter/setter methods that convert between string/byte[]
representations and the desired object types.
ArrayList
, LinkedList
, and
CopyOnWriteArrayList
) and sets (including HashSet
,
LinkedHashSet
, TreeSet
, and CopyOnWriteArraySet
) of
the above types are also supported.
java.lang.Boolean
instead of the boolean
primitive), in which
case any fields associated with attributes that are not present in the entry
being de-serialized will be explicitly set to null
.Constructor and Description |
---|
DefaultObjectEncoder()
Creates a new instance of this encoder.
|
Modifier and Type | Method and Description |
---|---|
AttributeTypeDefinition |
constructAttributeType(java.lang.reflect.Field f,
OIDAllocator a)
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.
|
AttributeTypeDefinition |
constructAttributeType(java.lang.reflect.Method m,
OIDAllocator a)
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.
|
void |
decodeField(java.lang.reflect.Field field,
java.lang.Object object,
Attribute attribute)
Updates the provided object to assign a value for the specified field from
the contents of the given attribute.
|
Attribute |
encodeFieldValue(java.lang.reflect.Field field,
java.lang.Object value,
java.lang.String name)
Encodes the provided field to an LDAP attribute.
|
Attribute |
encodeMethodValue(java.lang.reflect.Method method,
java.lang.Object value,
java.lang.String name)
Encodes the provided method to an LDAP attribute.
|
void |
invokeSetter(java.lang.reflect.Method method,
java.lang.Object object,
Attribute attribute)
Updates the provided object to invoke the specified method to set a value
from the contents of the given attribute.
|
boolean |
supportsMultipleValues(java.lang.reflect.Field field)
Indicates whether the provided field can hold multiple values.
|
boolean |
supportsMultipleValues(java.lang.reflect.Method method)
Indicates whether the provided setter method takes an argument that can
hold multiple values.
|
boolean |
supportsType(java.lang.reflect.Type t)
Indicates whether this object encoder may be used to encode or decode
objects of the specified type.
|
constructAttributeType, constructAttributeType, setNull, setNull
public DefaultObjectEncoder()
public boolean supportsType(@NotNull java.lang.reflect.Type t)
supportsType
in class ObjectEncoder
t
- The type of object for which to make the determination.true
if this object encoder may be used for objects of
the specified type, or false
if not.@NotNull public AttributeTypeDefinition constructAttributeType(@NotNull java.lang.reflect.Field f, @NotNull OIDAllocator a) throws LDAPPersistException
constructAttributeType
in class ObjectEncoder
f
- The field for which to construct an LDAP attribute type
definition. It will include the LDAPField
annotation
type.a
- The OID allocator to use to generate the object identifier. It
must not be null
.LDAPPersistException
- If this object encoder does not support
encoding values for the associated field
type.@NotNull public AttributeTypeDefinition constructAttributeType(@NotNull java.lang.reflect.Method m, @NotNull OIDAllocator a) throws LDAPPersistException
constructAttributeType
in class ObjectEncoder
m
- The method for which to construct an LDAP attribute type
definition. It will include the LDAPGetter
annotation type.a
- The OID allocator to use to generate the object identifier. It
must not be null
.LDAPPersistException
- If this object encoder does not support
encoding values for the associated method
type.public boolean supportsMultipleValues(@NotNull java.lang.reflect.Field field)
supportsMultipleValues
in class ObjectEncoder
field
- The field for which to make the determination. It must be
marked with the LDAPField
annotation.true
if the provided field can hold multiple values, or
false
if not.public boolean supportsMultipleValues(@NotNull java.lang.reflect.Method method)
supportsMultipleValues
in class ObjectEncoder
method
- The setter method for which to make the determination. It
must be marked with the LDAPSetter
annotation
type and conform to the constraints associated with that
annotation.true
if the provided method takes an argument that can
hold multiple values, or false
if not.@NotNull public Attribute encodeFieldValue(@NotNull java.lang.reflect.Field field, @NotNull java.lang.Object value, @NotNull java.lang.String name) throws LDAPPersistException
encodeFieldValue
in class ObjectEncoder
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.LDAPPersistException
- If a problem occurs while attempting to
construct an attribute for the field.@NotNull public Attribute encodeMethodValue(@NotNull java.lang.reflect.Method method, @NotNull java.lang.Object value, @NotNull java.lang.String name) throws LDAPPersistException
encodeMethodValue
in class ObjectEncoder
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.LDAPPersistException
- If a problem occurs while attempting to
construct an attribute for the method.public void decodeField(@NotNull java.lang.reflect.Field field, @NotNull java.lang.Object object, @NotNull Attribute attribute) throws LDAPPersistException
decodeField
in class ObjectEncoder
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.LDAPPersistException
- If a problem occurs while attempting to
assign a value to the specified field.public void invokeSetter(@NotNull java.lang.reflect.Method method, @NotNull java.lang.Object object, @NotNull Attribute attribute) throws LDAPPersistException
invokeSetter
in class ObjectEncoder
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.LDAPPersistException
- If a problem occurs while attempting to
determine the value or invoke the specified
method.