Package org.ldaptive.beans.spring
Class SpelAttributeValueMutator
- java.lang.Object
-
- org.ldaptive.beans.spring.SpelAttributeValueMutator
-
- All Implemented Interfaces:
AttributeValueMutator
public class SpelAttributeValueMutator extends Object implements AttributeValueMutator
Attribute mutator that uses a SPEL expression and evaluation context.
-
-
Field Summary
Fields Modifier and Type Field Description private AttributeattributeAttribute containing the SPEL expression.private org.springframework.expression.EvaluationContextevaluationContextEvaluation context.private org.springframework.expression.ExpressionexpressionSPEL expression to access values.protected LoggerloggerLogger for this class.private ValueTranscodertranscoderCustom transcoder for this attribute.
-
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> TconvertValue(Object value, Class<?> sourceType, Class<T> targetType)Converts the supplied value to the target type.protected static <T> Collection<T>createCollection(Class<?> type, int size)Creates the best fit collection for the supplied type.Collection<byte[]>getBinaryValues(Object object)Returns the binary values of the attribute.StringgetName()Returns the name of the attribute.Collection<String>getStringValues(Object object)Returns the string values of the attribute.protected <T> Collection<T>getValues(Object object, Class<T> type)Uses the configured expression and evaluation context to retrieve values from the supplied object.booleanisBinary()Returns whether the attribute is binary.voidsetBinaryValues(Object object, Collection<byte[]> values)Sets the binary values of the attribute.voidsetStringValues(Object object, Collection<String> values)Sets the string values of the attribute.protected <T> voidsetValues(Object object, Collection<T> values, Class<T> type)Uses the configured expression and evaluation context to set values on the supplied object.StringtoString()
-
-
-
Field Detail
-
logger
protected final Logger logger
Logger for this class.
-
attribute
private final Attribute attribute
Attribute containing the SPEL expression.
-
expression
private final org.springframework.expression.Expression expression
SPEL expression to access values.
-
evaluationContext
private final org.springframework.expression.EvaluationContext evaluationContext
Evaluation context.
-
transcoder
private final ValueTranscoder transcoder
Custom transcoder for this attribute.
-
-
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 String getName()
Description copied from interface:AttributeValueMutatorReturns the name of the attribute.- Specified by:
getNamein interfaceAttributeValueMutator- Returns:
- attribute name
-
isBinary
public boolean isBinary()
Description copied from interface:AttributeValueMutatorReturns whether the attribute is binary.- Specified by:
isBinaryin interfaceAttributeValueMutator- Returns:
- whether the attribute is binary
-
getStringValues
public Collection<String> getStringValues(Object object)
Description copied from interface:AttributeValueMutatorReturns the string values of the attribute.- Specified by:
getStringValuesin interfaceAttributeValueMutator- Parameters:
object- containing attribute values- Returns:
- attribute values
-
getBinaryValues
public Collection<byte[]> getBinaryValues(Object object)
Description copied from interface:AttributeValueMutatorReturns the binary values of the attribute.- Specified by:
getBinaryValuesin interfaceAttributeValueMutator- Parameters:
object- containing attribute values- Returns:
- attribute values
-
getValues
protected <T> Collection<T> getValues(Object object, 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(Object value, Class<?> sourceType, 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(Object object, Collection<String> values)
Description copied from interface:AttributeValueMutatorSets the string values of the attribute.- Specified by:
setStringValuesin interfaceAttributeValueMutator- Parameters:
object- to set values onvalues- to set
-
setBinaryValues
public void setBinaryValues(Object object, Collection<byte[]> values)
Description copied from interface:AttributeValueMutatorSets the binary values of the attribute.- Specified by:
setBinaryValuesin interfaceAttributeValueMutator- Parameters:
object- to set values onvalues- to set
-
setValues
protected <T> void setValues(Object object, Collection<T> values, 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
-
createCollection
protected static <T> Collection<T> createCollection(Class<?> type, int size)
Creates the best fit collection for the supplied type.- Type Parameters:
T- collection type- Parameters:
type- of collection to createsize- of the collection- Returns:
- collection
-
-