Package org.ldaptive.beans.spring
Class SpelAttributeValueMutator
- java.lang.Object
-
- org.ldaptive.beans.spring.SpelAttributeValueMutator
-
- All Implemented Interfaces:
AttributeValueMutator
public class SpelAttributeValueMutator extends java.lang.Object implements AttributeValueMutator
Attribute mutator that uses a SPEL expression and evaluation context.- Author:
- Middleware Services
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
logger
Logger for this class.
-
Constructor Summary
Constructors Constructor Description SpelAttributeValueMutator(Attribute attr, org.springframework.expression.EvaluationContext context)
Creates a new spel attribute value mutator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T> T
convertValue(java.lang.Object value, java.lang.Class<?> sourceType, java.lang.Class<T> targetType)
Converts the supplied value to the target type.protected static <T> java.util.Collection<T>
createCollection(java.lang.Class<?> type, int size)
Creates a best fit collection for the supplied type.java.util.Collection<byte[]>
getBinaryValues(java.lang.Object object)
Returns the binary values of the attribute.java.lang.String
getName()
Returns the name of the attribute.java.util.Collection<java.lang.String>
getStringValues(java.lang.Object object)
Returns the string values of the attribute.protected <T> java.util.Collection<T>
getValues(java.lang.Object object, java.lang.Class<T> type)
Uses the configured expression and evaluation context to retrieve values from the supplied object.boolean
isBinary()
Returns whether the attribute is binary.void
setBinaryValues(java.lang.Object object, java.util.Collection<byte[]> values)
Sets the binary values of the attribute.void
setStringValues(java.lang.Object object, java.util.Collection<java.lang.String> values)
Sets the string values of the attribute.protected <T> void
setValues(java.lang.Object object, java.util.Collection<T> values, java.lang.Class<T> type)
Uses the configured expression and evaluation context to set values on the supplied object.java.lang.String
toString()
-
-
-
Constructor Detail
-
SpelAttributeValueMutator
public SpelAttributeValueMutator(Attribute attr, org.springframework.expression.EvaluationContext context)
Creates a new spel attribute value mutator.- Parameters:
attr
- containing the SPEL configurationcontext
- containing the values
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:AttributeValueMutator
Returns the name of the attribute.- Specified by:
getName
in interfaceAttributeValueMutator
- Returns:
- attribute name
-
isBinary
public boolean isBinary()
Description copied from interface:AttributeValueMutator
Returns whether the attribute is binary.- Specified by:
isBinary
in interfaceAttributeValueMutator
- Returns:
- whether the attribute is binary
-
getStringValues
public java.util.Collection<java.lang.String> getStringValues(java.lang.Object object)
Description copied from interface:AttributeValueMutator
Returns the string values of the attribute.- Specified by:
getStringValues
in interfaceAttributeValueMutator
- Parameters:
object
- containing attribute values- Returns:
- attribute values
-
getBinaryValues
public java.util.Collection<byte[]> getBinaryValues(java.lang.Object object)
Description copied from interface:AttributeValueMutator
Returns the binary values of the attribute.- Specified by:
getBinaryValues
in interfaceAttributeValueMutator
- Parameters:
object
- containing attribute values- Returns:
- attribute values
-
getValues
protected <T> java.util.Collection<T> getValues(java.lang.Object object, java.lang.Class<T> type)
Uses the configured expression and evaluation context to retrieve values from the supplied object. Values are the placed in a collection and returned.- Type Parameters:
T
- either String or byte[]- Parameters:
object
- to get values fromtype
- of objects to place in the collection- Returns:
- values in the supplied object
-
convertValue
protected <T> T convertValue(java.lang.Object value, java.lang.Class<?> sourceType, java.lang.Class<T> targetType)
Converts the supplied value to the target type. If a custom transcoder has been configured it is used. Otherwise the type converter from the evaluation context is used.- Type Parameters:
T
- either String or byte[]- Parameters:
value
- to convertsourceType
- to convert fromtargetType
- to convert to- Returns:
- converted value
-
setStringValues
public void setStringValues(java.lang.Object object, java.util.Collection<java.lang.String> values)
Description copied from interface:AttributeValueMutator
Sets the string values of the attribute.- Specified by:
setStringValues
in interfaceAttributeValueMutator
- Parameters:
object
- to set values onvalues
- to set
-
setBinaryValues
public void setBinaryValues(java.lang.Object object, java.util.Collection<byte[]> values)
Description copied from interface:AttributeValueMutator
Sets the binary values of the attribute.- Specified by:
setBinaryValues
in interfaceAttributeValueMutator
- Parameters:
object
- to set values onvalues
- to set
-
setValues
protected <T> void setValues(java.lang.Object object, java.util.Collection<T> values, java.lang.Class<T> type)
Uses the configured expression and evaluation context to set values on the supplied object. If a custom transcoder has been configured it is executed on the values before they are passed to the expression.- Type Parameters:
T
- either String or byte[]- Parameters:
object
- to set values onvalues
- to settype
- of objects in the collection
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
createCollection
protected static <T> java.util.Collection<T> createCollection(java.lang.Class<?> type, int size)
Creates a best fit collection for the supplied type.- Type Parameters:
T
- collection type- Parameters:
type
- of collection to createsize
- of the collection- Returns:
- collection
-
-