use of org.hibernate.validator.messageinterpolation.HibernateMessageInterpolatorContext in project hibernate-validator by hibernate.
the class ElTermResolver method bindContextValues.
private ValueExpression bindContextValues(String messageTemplate, MessageInterpolator.Context messageInterpolatorContext, ELContext elContext) {
// bind the validated value
ValueExpression valueExpression = expressionFactory.createValueExpression(messageInterpolatorContext.getValidatedValue(), Object.class);
elContext.getVariableMapper().setVariable(VALIDATED_VALUE_NAME, valueExpression);
// bind a formatter instantiated with proper locale
valueExpression = expressionFactory.createValueExpression(new FormatterWrapper(locale), FormatterWrapper.class);
elContext.getVariableMapper().setVariable(RootResolver.FORMATTER, valueExpression);
// map the parameters provided by the annotation values and the parameters + expression variables explicitly
// added to the context
addVariablesToElContext(elContext, messageInterpolatorContext.getConstraintDescriptor().getAttributes());
if (messageInterpolatorContext instanceof HibernateMessageInterpolatorContext) {
addVariablesToElContext(elContext, ((HibernateMessageInterpolatorContext) messageInterpolatorContext).getExpressionVariables());
}
return expressionFactory.createValueExpression(elContext, messageTemplate, String.class);
}
use of org.hibernate.validator.messageinterpolation.HibernateMessageInterpolatorContext in project hibernate-validator by hibernate.
the class MessageInterpolatorContextTest method testUnwrapToInterfaceTypesSucceeds.
@Test
public void testUnwrapToInterfaceTypesSucceeds() {
Context context = new MessageInterpolatorContext(null, null, null, null, Collections.<String, Object>emptyMap(), Collections.<String, Object>emptyMap(), ExpressionLanguageFeatureLevel.BEAN_METHODS, false);
MessageInterpolator.Context asMessageInterpolatorContext = context.unwrap(MessageInterpolator.Context.class);
assertSame(asMessageInterpolatorContext, context);
HibernateMessageInterpolatorContext asHibernateMessageInterpolatorContext = context.unwrap(HibernateMessageInterpolatorContext.class);
assertSame(asHibernateMessageInterpolatorContext, context);
Object asObject = context.unwrap(Object.class);
assertSame(asObject, context);
}
use of org.hibernate.validator.messageinterpolation.HibernateMessageInterpolatorContext in project hibernate-validator by hibernate.
the class ParameterTermResolverTest method createHibernateContextWithConstraintDescriptorAttr.
@SuppressWarnings({ "rawtypes", "unchecked" })
private static MessageInterpolator.Context createHibernateContextWithConstraintDescriptorAttr(String attrName, Object attrValue) {
final Map<String, Object> attrs = createConstraintDescriptorAttr(attrName, attrValue);
final HibernateMessageInterpolatorContext context = EasyMock.mock(HibernateMessageInterpolatorContext.class);
final ConstraintDescriptor constraintDescriptor = EasyMock.mock(ConstraintDescriptor.class);
EasyMock.expect(context.getMessageParameters()).andStubReturn(attrs);
EasyMock.expect(context.getConstraintDescriptor()).andStubReturn(constraintDescriptor);
EasyMock.expect(constraintDescriptor.getAttributes()).andStubReturn(attrs);
EasyMock.replay(context);
EasyMock.replay(constraintDescriptor);
return context;
}
Aggregations