[hibernate-commits] Hibernate SVN: r15816 - in validator/trunk: hibernate-validator/src/main/java/org/hibernate/validation/impl and 5 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Sun Jan 25 15:45:00 EST 2009
Author: epbernard
Date: 2009-01-25 15:44:59 -0500 (Sun, 25 Jan 2009)
New Revision: 15816
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolatorTest.java
validator/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageResolver.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java
validator/trunk/validation-api/src/main/java/javax/validation/MessageResolver.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorBuilderImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryImpl.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
validator/trunk/hibernate-validator/src/test/resources/log4j.properties
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorBuilder.java
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java
validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidatorFactoryConfiguration.java
Log:
BVAL-84 Rename MessageResolver to MessageInterpolator
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/BeanMetaDataImpl.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -32,7 +32,7 @@
import javax.validation.PropertyDescriptor;
import javax.validation.Valid;
import javax.validation.ValidationException;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import javax.validation.ConstraintFactory;
import org.slf4j.Logger;
@@ -55,7 +55,7 @@
private static final Logger log = LoggerFactory.make();
- private final MessageResolver messageResolver;
+ private final MessageInterpolator messageInterpolator;
private final ConstraintFactory constraintFactory;
@@ -95,9 +95,9 @@
*/
private Map<Class<?>, List<Class<?>>> groupSequences = new HashMap<Class<?>, List<Class<?>>>();
- public BeanMetaDataImpl(Class<T> beanClass, MessageResolver messageResolver, ConstraintFactory constraintFactory) {
+ public BeanMetaDataImpl(Class<T> beanClass, MessageInterpolator messageInterpolator, ConstraintFactory constraintFactory) {
this.beanClass = beanClass;
- this.messageResolver = messageResolver;
+ this.messageInterpolator = messageInterpolator;
this.constraintFactory = constraintFactory;
createMetaData();
}
@@ -197,7 +197,8 @@
List<ConstraintDescriptorImpl> fieldMetadata = findFieldLevelConstraints( field );
for ( ConstraintDescriptorImpl constraintDescription : fieldMetadata ) {
ReflectionHelper.setAccessibility( field );
- MetaConstraint metaConstraint = new MetaConstraint( field, constraintDescription, messageResolver, constraintFactory );
+ MetaConstraint metaConstraint = new MetaConstraint( field, constraintDescription,
+ messageInterpolator, constraintFactory );
metaConstraintList.add( metaConstraint );
}
if ( field.isAnnotationPresent( Valid.class ) ) {
@@ -212,7 +213,8 @@
List<ConstraintDescriptorImpl> methodMetadata = findMethodLevelConstraints( method );
for ( ConstraintDescriptorImpl constraintDescription : methodMetadata ) {
ReflectionHelper.setAccessibility( method );
- MetaConstraint metaConstraint = new MetaConstraint( method, constraintDescription, messageResolver, constraintFactory );
+ MetaConstraint metaConstraint = new MetaConstraint( method, constraintDescription,
+ messageInterpolator, constraintFactory );
metaConstraintList.add( metaConstraint );
}
if ( method.isAnnotationPresent( Valid.class ) ) {
@@ -225,7 +227,8 @@
private void initClassConstraints(Class clazz) {
List<ConstraintDescriptorImpl> classMetadata = findClassLevelConstraints( clazz );
for ( ConstraintDescriptorImpl constraintDescription : classMetadata ) {
- MetaConstraint metaConstraint = new MetaConstraint( clazz, constraintDescription, messageResolver, constraintFactory );
+ MetaConstraint metaConstraint = new MetaConstraint( clazz, constraintDescription,
+ messageInterpolator, constraintFactory );
metaConstraintList.add( metaConstraint );
}
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -23,7 +23,7 @@
import javax.validation.ConstraintDescriptor;
import javax.validation.ValidationException;
import javax.validation.ConstraintFactory;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import org.slf4j.Logger;
@@ -45,23 +45,23 @@
private Constraint constraint;
private final ConstraintDescriptor descriptor;
private final ConstraintFactory constraintFactory;
- private final MessageResolver messageResolver;
+ private final MessageInterpolator messageInterpolator;
- public ConstraintTree(ConstraintDescriptor descriptor, ConstraintFactory constraintFactory, MessageResolver messageResolver) {
- this( descriptor, null, constraintFactory, messageResolver );
+ public ConstraintTree(ConstraintDescriptor descriptor, ConstraintFactory constraintFactory, MessageInterpolator messageInterpolator) {
+ this( descriptor, null, constraintFactory, messageInterpolator );
}
- private ConstraintTree(ConstraintDescriptor descriptor, ConstraintTree parent, ConstraintFactory constraintFactory, MessageResolver messageResolver) {
+ private ConstraintTree(ConstraintDescriptor descriptor, ConstraintTree parent, ConstraintFactory constraintFactory, MessageInterpolator messageInterpolator) {
this.parent = parent;
this.descriptor = descriptor;
this.constraintFactory = constraintFactory;
- this.messageResolver = messageResolver;
+ this.messageInterpolator = messageInterpolator;
this.constraint = getConstraint( descriptor );
children = new ArrayList<ConstraintTree>( descriptor.getComposingConstraints().size() );
for ( ConstraintDescriptor composingDescriptor : descriptor.getComposingConstraints() ) {
ConstraintTree treeNode = new ConstraintTree(
- composingDescriptor, this, constraintFactory, messageResolver
+ composingDescriptor, this, constraintFactory, messageInterpolator
);
children.add( treeNode );
}
@@ -123,7 +123,7 @@
}
private <T> void createConstraintViolation(Object value, Class<T> beanClass, ValidationContext<T> validationContext, Object leafBeanInstance, String message, ConstraintDescriptor descriptor) {
- String interpolatedMessage = messageResolver.interpolate(
+ String interpolatedMessage = messageInterpolator.interpolate(
message,
descriptor,
leafBeanInstance
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/MetaConstraint.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -23,7 +23,7 @@
import java.lang.reflect.Type;
import javax.validation.ConstraintDescriptor;
import javax.validation.ValidationException;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import javax.validation.ConstraintFactory;
import org.hibernate.validation.util.ReflectionHelper;
@@ -70,11 +70,11 @@
*/
private final ElementType elementType;
- public MetaConstraint(Type t, ConstraintDescriptor constraintDescriptor, MessageResolver messageResolver, ConstraintFactory factory) {
- this( t, null, null, ElementType.FIELD, constraintDescriptor, "", messageResolver, factory );
+ public MetaConstraint(Type t, ConstraintDescriptor constraintDescriptor, MessageInterpolator messageInterpolator, ConstraintFactory factory) {
+ this( t, null, null, ElementType.FIELD, constraintDescriptor, "", messageInterpolator, factory );
}
- public MetaConstraint(Method m, ConstraintDescriptor constraintDescriptor, MessageResolver messageResolver, ConstraintFactory factory) {
+ public MetaConstraint(Method m, ConstraintDescriptor constraintDescriptor, MessageInterpolator messageInterpolator, ConstraintFactory factory) {
this(
null,
m,
@@ -82,22 +82,22 @@
ElementType.METHOD,
constraintDescriptor,
ReflectionHelper.getPropertyName( m ),
- messageResolver,
+ messageInterpolator,
factory
);
}
- public MetaConstraint(Field f, ConstraintDescriptor constraintDescriptor, MessageResolver messageResolver, ConstraintFactory factory) {
- this( null, null, f, ElementType.FIELD, constraintDescriptor, f.getName(), messageResolver, factory );
+ public MetaConstraint(Field f, ConstraintDescriptor constraintDescriptor, MessageInterpolator messageInterpolator, ConstraintFactory factory) {
+ this( null, null, f, ElementType.FIELD, constraintDescriptor, f.getName(), messageInterpolator, factory );
}
- private MetaConstraint(Type t, Method m, Field f, ElementType elementType, ConstraintDescriptor constraintDescriptor, String property, MessageResolver messageResolver, ConstraintFactory factory) {
+ private MetaConstraint(Type t, Method m, Field f, ElementType elementType, ConstraintDescriptor constraintDescriptor, String property, MessageInterpolator messageInterpolator, ConstraintFactory factory) {
this.type = t;
this.method = m;
this.field = f;
this.elementType = elementType;
this.propertyName = property;
- constraintTree = new ConstraintTree( constraintDescriptor, factory, messageResolver );
+ constraintTree = new ConstraintTree( constraintDescriptor, factory, messageInterpolator );
}
/**
Copied: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolator.java (from rev 15815, validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageResolver.java)
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolator.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -0,0 +1,155 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.impl;
+
+import java.util.Locale;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.validation.ConstraintDescriptor;
+import javax.validation.MessageInterpolator;
+
+import org.slf4j.Logger;
+
+import org.hibernate.validation.util.LoggerFactory;
+
+
+/**
+ * Resource bundle backed message interpolator.
+ *
+ * @author Emmanuel Bernard
+ */
+public class ResourceBundleMessageInterpolator implements MessageInterpolator {
+ private static final String DEFAULT_VALIDATION_MESSAGES = "org.hibernate.validation.ValidationMessages";
+ private static final String USER_VALIDATION_MESSAGES = "ValidationMessages";
+ private static final Logger log = LoggerFactory.make();
+
+ /**
+ * Regular expression used to do message interpolation.
+ */
+ private static final Pattern messagePattern = Pattern.compile( "\\{([\\w\\.]+)\\}" );
+ private ResourceBundle defaultResourceBundle;
+ private ResourceBundle userResourceBundle;
+
+ public ResourceBundleMessageInterpolator() {
+ userResourceBundle = getFileBasedResourceBundle();
+ defaultResourceBundle = ResourceBundle.getBundle( DEFAULT_VALIDATION_MESSAGES );
+ }
+
+ public ResourceBundleMessageInterpolator(ResourceBundle resourceBundle) {
+ if ( resourceBundle == null ) {
+ userResourceBundle = getFileBasedResourceBundle();
+ }
+ else {
+ this.userResourceBundle = resourceBundle;
+ }
+ defaultResourceBundle = ResourceBundle.getBundle( DEFAULT_VALIDATION_MESSAGES );
+ }
+
+ /**
+ * Search current thread classloader for the resource bundle. If not found, search validator (this) classloader.
+ *
+ * @return the resource bundle or <code>null</code> if none is found.
+ */
+ private ResourceBundle getFileBasedResourceBundle() {
+ ResourceBundle rb = null;
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if ( classLoader != null ) {
+ rb = loadBundle( classLoader, USER_VALIDATION_MESSAGES + " not found by thread local classloader" );
+ }
+ if ( rb == null ) {
+ rb = loadBundle(
+ this.getClass().getClassLoader(), USER_VALIDATION_MESSAGES + " not found by validator classloader"
+ );
+ }
+ if ( log.isDebugEnabled() ) {
+ if ( rb != null ) {
+ log.debug( USER_VALIDATION_MESSAGES + " found" );
+ }
+ else {
+ log.debug( USER_VALIDATION_MESSAGES + " not found. Delegating to " + DEFAULT_VALIDATION_MESSAGES );
+ }
+ }
+ return rb;
+ }
+
+ private ResourceBundle loadBundle(ClassLoader classLoader, String message) {
+ ResourceBundle rb = null;
+ try {
+ rb = ResourceBundle.getBundle( USER_VALIDATION_MESSAGES, Locale.getDefault(), classLoader );
+ }
+ catch ( MissingResourceException e ) {
+ log.trace( message );
+ }
+ return rb;
+ }
+
+ public String interpolate(String message, ConstraintDescriptor constraintDescriptor, Object value) {
+ //probably no need for caching, but it could be done by parameters since the map
+ //is immutable and uniquely built per Validation definition, the comparaison has to be based on == and not equals though
+ return replace( message, constraintDescriptor.getParameters() );
+ }
+
+ public String interpolate(String message, ConstraintDescriptor constraintDescriptor, Object value, Locale locale) {
+ throw new UnsupportedOperationException( "Interpolation for Locale. Has to be done." );
+ }
+
+
+ private String replace(String message, Map<String, Object> parameters) {
+ Matcher matcher = messagePattern.matcher( message );
+ StringBuffer sb = new StringBuffer();
+ while ( matcher.find() ) {
+ matcher.appendReplacement( sb, resolveParameter( matcher.group( 1 ), parameters ) );
+ }
+ matcher.appendTail( sb );
+ return sb.toString();
+ }
+
+
+ private String resolveParameter(String token, Map<String, Object> parameters) {
+ Object variable = parameters.get( token );
+ if ( variable != null ) {
+ return variable.toString();
+ }
+
+ StringBuffer buffer = new StringBuffer();
+ String string = null;
+ try {
+ string = userResourceBundle != null ? userResourceBundle.getString( token ) : null;
+ }
+ catch ( MissingResourceException e ) {
+ //give a second chance with the default resource bundle
+ }
+ if ( string == null ) {
+ try {
+ string = defaultResourceBundle.getString( token );
+ }
+ catch ( MissingResourceException e ) {
+ //return the unchanged string
+ buffer.append( "{" ).append( token ).append( '}' );
+ }
+ }
+ if ( string != null ) {
+ // call resolve recusively!
+ buffer.append( replace( string, parameters ) );
+ }
+ return buffer.toString();
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageResolver.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageResolver.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ResourceBundleMessageResolver.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -1,155 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.impl;
-
-import java.util.Locale;
-import java.util.Map;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.validation.ConstraintDescriptor;
-import javax.validation.MessageResolver;
-
-import org.slf4j.Logger;
-
-import org.hibernate.validation.util.LoggerFactory;
-
-
-/**
- * Resource bundle backed message resolver.
- *
- * @author Emmanuel Bernard
- */
-public class ResourceBundleMessageResolver implements MessageResolver {
- private static final String DEFAULT_VALIDATION_MESSAGES = "org.hibernate.validation.ValidationMessages";
- private static final String USER_VALIDATION_MESSAGES = "ValidationMessages";
- private static final Logger log = LoggerFactory.make();
-
- /**
- * Regular expression used to do message interpolation.
- */
- private static final Pattern messagePattern = Pattern.compile( "\\{([\\w\\.]+)\\}" );
- private ResourceBundle defaultResourceBundle;
- private ResourceBundle userResourceBundle;
-
- public ResourceBundleMessageResolver() {
- userResourceBundle = getFileBasedResourceBundle();
- defaultResourceBundle = ResourceBundle.getBundle( DEFAULT_VALIDATION_MESSAGES );
- }
-
- public ResourceBundleMessageResolver(ResourceBundle resourceBundle) {
- if ( resourceBundle == null ) {
- userResourceBundle = getFileBasedResourceBundle();
- }
- else {
- this.userResourceBundle = resourceBundle;
- }
- defaultResourceBundle = ResourceBundle.getBundle( DEFAULT_VALIDATION_MESSAGES );
- }
-
- /**
- * Search current thread classloader for the resource bundle. If not found, search validator (this) classloader.
- *
- * @return the resource bundle or <code>null</code> if none is found.
- */
- private ResourceBundle getFileBasedResourceBundle() {
- ResourceBundle rb = null;
- ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- if ( classLoader != null ) {
- rb = loadBundle( classLoader, USER_VALIDATION_MESSAGES + " not found by thread local classloader" );
- }
- if ( rb == null ) {
- rb = loadBundle(
- this.getClass().getClassLoader(), USER_VALIDATION_MESSAGES + " not found by validator classloader"
- );
- }
- if ( log.isDebugEnabled() ) {
- if ( rb != null ) {
- log.debug( USER_VALIDATION_MESSAGES + " found" );
- }
- else {
- log.debug( USER_VALIDATION_MESSAGES + " not found. Delegating to " + DEFAULT_VALIDATION_MESSAGES );
- }
- }
- return rb;
- }
-
- private ResourceBundle loadBundle(ClassLoader classLoader, String message) {
- ResourceBundle rb = null;
- try {
- rb = ResourceBundle.getBundle( USER_VALIDATION_MESSAGES, Locale.getDefault(), classLoader );
- }
- catch ( MissingResourceException e ) {
- log.trace( message );
- }
- return rb;
- }
-
- public String interpolate(String message, ConstraintDescriptor constraintDescriptor, Object value) {
- //probably no need for caching, but it could be done by parameters since the map
- //is immutable and uniquely built per Validation definition, the comparaison has to be based on == and not equals though
- return replace( message, constraintDescriptor.getParameters() );
- }
-
- public String interpolate(String message, ConstraintDescriptor constraintDescriptor, Object value, Locale locale) {
- throw new UnsupportedOperationException( "Interpolation for Locale. Has to be done." );
- }
-
-
- private String replace(String message, Map<String, Object> parameters) {
- Matcher matcher = messagePattern.matcher( message );
- StringBuffer sb = new StringBuffer();
- while ( matcher.find() ) {
- matcher.appendReplacement( sb, resolveParameter( matcher.group( 1 ), parameters ) );
- }
- matcher.appendTail( sb );
- return sb.toString();
- }
-
-
- private String resolveParameter(String token, Map<String, Object> parameters) {
- Object variable = parameters.get( token );
- if ( variable != null ) {
- return variable.toString();
- }
-
- StringBuffer buffer = new StringBuffer();
- String string = null;
- try {
- string = userResourceBundle != null ? userResourceBundle.getString( token ) : null;
- }
- catch ( MissingResourceException e ) {
- //give a second chance with the default resource bundle
- }
- if ( string == null ) {
- try {
- string = defaultResourceBundle.getString( token );
- }
- catch ( MissingResourceException e ) {
- //return the unchanged string
- buffer.append( "{" ).append( token ).append( '}' );
- }
- }
- if ( string != null ) {
- // call resolve recusively!
- buffer.append( replace( string, parameters ) );
- }
- return buffer.toString();
- }
-}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorBuilderImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorBuilderImpl.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorBuilderImpl.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -1,6 +1,6 @@
package org.hibernate.validation.impl;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.Validator;
import javax.validation.ValidatorBuilder;
@@ -11,28 +11,28 @@
* @author Emmanuel Bernard
*/
public class ValidatorBuilderImpl implements ValidatorBuilder {
- private MessageResolver messageResolver;
+ private MessageInterpolator messageInterpolator;
private TraversableResolver traversableResolver;
- private final MessageResolver factoryMessageResolver;
+ private final MessageInterpolator factoryMessageInterpolator;
private final TraversableResolver factoryTraversableResolver;
private final ValidatorFactoryImpl validatorFactory;
public ValidatorBuilderImpl(ValidatorFactoryImpl validatorFactory,
- MessageResolver factoryMessageResolver,
+ MessageInterpolator factoryMessageInterpolator,
TraversableResolver factoryTraversableResolver) {
this.validatorFactory = validatorFactory;
- this.factoryMessageResolver = factoryMessageResolver;
+ this.factoryMessageInterpolator = factoryMessageInterpolator;
this.factoryTraversableResolver = factoryTraversableResolver;
- messageResolver(factoryMessageResolver);
+ messageInterpolator( factoryMessageInterpolator );
traversableResolver(factoryTraversableResolver);
}
- public ValidatorBuilder messageResolver(MessageResolver messageResolver) {
- if (messageResolver == null) {
- this.messageResolver = factoryMessageResolver;
+ public ValidatorBuilder messageInterpolator(MessageInterpolator messageInterpolator) {
+ if ( messageInterpolator == null) {
+ this.messageInterpolator = factoryMessageInterpolator;
}
else {
- this.messageResolver = messageResolver;
+ this.messageInterpolator = messageInterpolator;
}
return this;
}
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -20,7 +20,7 @@
import java.io.InputStream;
import java.util.List;
import javax.validation.ConstraintFactory;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.ValidationException;
import javax.validation.ValidationProviderResolver;
@@ -44,10 +44,10 @@
}
//FIXME not sure why it is like that. We should cache these instances somehow. Static?
- private final MessageResolver defaultMessageResolver = new ResourceBundleMessageResolver();
+ private final MessageInterpolator defaultMessageInterpolator = new ResourceBundleMessageInterpolator();
private final TraversableResolver defaultTraversableResolver = new DefaultTraversableResolver();
- private MessageResolver messageResolver;
+ private MessageInterpolator messageInterpolator;
private ConstraintFactory constraintFactory = new ConstraintFactoryImpl();
private String configurationFile = "META-INF/validation.xml";
private final ValidationProvider provider;
@@ -62,7 +62,7 @@
this.providerResolver = state.getValidationProviderResolver();
}
this.provider = null;
- this.messageResolver = defaultMessageResolver;
+ this.messageInterpolator = defaultMessageInterpolator;
this.traversableResolver = defaultTraversableResolver;
}
@@ -72,12 +72,12 @@
}
this.provider = provider;
this.providerResolver = null;
- this.messageResolver = defaultMessageResolver;
+ this.messageInterpolator = defaultMessageInterpolator;
this.traversableResolver = defaultTraversableResolver;
}
- public ValidatorFactoryBuilderImpl messageResolver(MessageResolver resolver) {
- this.messageResolver = resolver;
+ public ValidatorFactoryBuilderImpl messageInterpolator(MessageInterpolator interpolator) {
+ this.messageInterpolator = interpolator;
return this;
}
@@ -119,8 +119,8 @@
return provider != null;
}
- public MessageResolver getMessageResolver() {
- return messageResolver;
+ public MessageInterpolator getMessageInterpolator() {
+ return messageInterpolator;
}
public ConstraintFactory getConstraintFactory() {
@@ -135,8 +135,8 @@
return null; //To change body of implemented methods use File | Settings | File Templates.
}
- public MessageResolver getDefaultMessageResolver() {
- return defaultMessageResolver;
+ public MessageInterpolator getDefaultMessageInterpolator() {
+ return defaultMessageInterpolator;
}
public InputStream getConfigurationStream() {
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryImpl.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryImpl.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryImpl.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -20,7 +20,7 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.validation.ConstraintFactory;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
import javax.validation.Validator;
import javax.validation.ValidatorBuilder;
@@ -35,7 +35,7 @@
*/
public class ValidatorFactoryImpl implements ValidatorFactoryImplementor {
- private final MessageResolver messageResolver;
+ private final MessageInterpolator messageInterpolator;
private final TraversableResolver traversableResolver;
private final ConstraintFactory constraintFactory;
@@ -45,7 +45,7 @@
public ValidatorFactoryImpl(ValidatorFactoryConfiguration configuration) {
- this.messageResolver = configuration.getMessageResolver();
+ this.messageInterpolator = configuration.getMessageInterpolator();
this.constraintFactory = configuration.getConstraintFactory();
this.traversableResolver = configuration.getTraversableResolver();
//do init metadata from XML form
@@ -58,12 +58,12 @@
return defineValidatorState().getValidator();
}
- public MessageResolver getMessageResolver() {
- return messageResolver;
+ public MessageInterpolator getMessageInterpolator() {
+ return messageInterpolator;
}
public ValidatorBuilder defineValidatorState() {
- return new ValidatorBuilderImpl(this, messageResolver, traversableResolver);
+ return new ValidatorBuilderImpl(this, messageInterpolator, traversableResolver);
}
public <T> BeanMetaDataImpl<T> getBeanMetaData(Class<T> beanClass) {
@@ -72,7 +72,7 @@
@SuppressWarnings( "unchecked")
BeanMetaDataImpl<T> metadata = ( BeanMetaDataImpl<T> ) metadataProviders.get(beanClass);
if (metadata == null) {
- metadata = new BeanMetaDataImpl<T>(beanClass, messageResolver, constraintFactory);
+ metadata = new BeanMetaDataImpl<T>(beanClass, messageInterpolator, constraintFactory);
metadataProviders.put( beanClass, metadata );
}
return metadata;
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -25,7 +25,7 @@
import javax.validation.ConstraintDescriptor;
import javax.validation.ConstraintFactory;
import javax.validation.ConstraintViolation;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import javax.validation.Validation;
import javax.validation.ValidationException;
import javax.validation.ValidationProviderResolver;
@@ -93,7 +93,7 @@
@Test
- public void testCustomMessageResolver() {
+ public void testCustomMessageInterpolator() {
// first try with the default message resolver
ValidatorFactoryBuilder<?> builder = Validation.getBuilder();
@@ -112,8 +112,8 @@
//FIXME nothing guarantee that a builder can be reused
// now we modify the builder, get a new factory and valiator and try again
- builder.messageResolver(
- new MessageResolver() {
+ builder.messageInterpolator(
+ new MessageInterpolator() {
public String interpolate(String message, ConstraintDescriptor constraintDescriptor, Object value) {
return "my custom message";
}
Copied: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolatorTest.java (from rev 15815, validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java)
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolatorTest.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -0,0 +1,146 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validation.impl;
+
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.ResourceBundle;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
+
+/**
+ * Tests for message resolution.
+ *
+ * @author Hardy Ferentschik
+ */
+public class ResourceBundleMessageInterpolatorTest {
+
+ private ResourceBundleMessageInterpolator interpolator;
+ private NotNull notNull;
+ private Size size;
+
+ @Before
+ public void setUp() {
+ interpolator = new ResourceBundleMessageInterpolator( new TestResources() );
+
+ AnnotationDescriptor descriptor = new AnnotationDescriptor( NotNull.class );
+ notNull = AnnotationFactory.create( descriptor );
+
+ descriptor = new AnnotationDescriptor( Size.class );
+ size = AnnotationFactory.create( descriptor );
+ }
+
+ @Test
+ public void testSuccessfulInterpolation() {
+ ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
+
+ String expected = "replacement worked";
+ String actual = interpolator.interpolate( "{foo}", desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+
+ expected = "replacement worked replacement worked";
+ actual = interpolator.interpolate( "{foo} {foo}", desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+
+ expected = "This replacement worked just fine";
+ actual = interpolator.interpolate( "This {foo} just fine", desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+
+ expected = "{} { replacement worked }";
+ actual = interpolator.interpolate( "{} { {foo} }", desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+ }
+
+ @Test
+ public void testUnSuccessfulInterpolation() {
+ ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
+ String expected = "foo"; // missing {}
+ String actual = interpolator.interpolate( "foo", desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+
+ expected = "#{foo {}";
+ actual = interpolator.interpolate( "#{foo {}", desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+ }
+
+ @Test
+ public void testUnkownTokenInterpolation() {
+ ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
+ String expected = "{bar}"; // unkown token {}
+ String actual = interpolator.interpolate( "{bar}", desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+ }
+
+ @Test
+ public void testDefaultInterpolation() {
+ ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
+ String expected = "may not be null";
+ String actual = interpolator.interpolate( notNull.message(), desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+
+ desciptor = new ConstraintDescriptorImpl( size, new Class<?>[] { } );
+ expected = "size must be between -2147483648 and 2147483647"; // unkown token {}
+ actual = interpolator.interpolate( size.message(), desciptor, null );
+ assertEquals( "Wrong substitution", expected, actual );
+ }
+
+
+ class TestResources extends ResourceBundle implements Enumeration<String> {
+ private Map<String, String> testResources;
+ Iterator<String> iter;
+
+ public TestResources() {
+ testResources = new HashMap<String, String>();
+ // add some test messages
+ testResources.put( "foo", "replacement worked" );
+
+ iter = testResources.keySet().iterator();
+ }
+
+ public Object handleGetObject(String key) {
+ return testResources.get( key );
+ }
+
+ public Enumeration<String> getKeys() {
+ return this;
+ }
+
+ public boolean hasMoreElements() {
+ return iter.hasNext();
+ }
+
+ public String nextElement() {
+ if ( hasMoreElements() ) {
+ return iter.next();
+ }
+ else {
+ throw new NoSuchElementException();
+ }
+ }
+ }
+}
Property changes on: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageInterpolatorTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/impl/ResourceBundleMessageResolverTest.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -1,146 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package org.hibernate.validation.impl;
-
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.ResourceBundle;
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-import static org.junit.Assert.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
-
-import org.hibernate.validation.util.annotationfactory.AnnotationDescriptor;
-import org.hibernate.validation.util.annotationfactory.AnnotationFactory;
-
-/**
- * Tests for message resolution.
- *
- * @author Hardy Ferentschik
- */
-public class ResourceBundleMessageResolverTest {
-
- private ResourceBundleMessageResolver resolver;
- private NotNull notNull;
- private Size size;
-
- @Before
- public void setUp() {
- resolver = new ResourceBundleMessageResolver( new TestResources() );
-
- AnnotationDescriptor descriptor = new AnnotationDescriptor( NotNull.class );
- notNull = AnnotationFactory.create( descriptor );
-
- descriptor = new AnnotationDescriptor( Size.class );
- size = AnnotationFactory.create( descriptor );
- }
-
- @Test
- public void testSuccessfulInterpolation() {
- ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
-
- String expected = "replacement worked";
- String actual = resolver.interpolate( "{foo}", desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
-
- expected = "replacement worked replacement worked";
- actual = resolver.interpolate( "{foo} {foo}", desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
-
- expected = "This replacement worked just fine";
- actual = resolver.interpolate( "This {foo} just fine", desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
-
- expected = "{} { replacement worked }";
- actual = resolver.interpolate( "{} { {foo} }", desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
- }
-
- @Test
- public void testUnSuccessfulInterpolation() {
- ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
- String expected = "foo"; // missing {}
- String actual = resolver.interpolate( "foo", desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
-
- expected = "#{foo {}";
- actual = resolver.interpolate( "#{foo {}", desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
- }
-
- @Test
- public void testUnkownTokenInterpolation() {
- ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
- String expected = "{bar}"; // unkown token {}
- String actual = resolver.interpolate( "{bar}", desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
- }
-
- @Test
- public void testDefaultInterpolation() {
- ConstraintDescriptorImpl desciptor = new ConstraintDescriptorImpl( notNull, new Class<?>[] { } );
- String expected = "may not be null";
- String actual = resolver.interpolate( notNull.message(), desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
-
- desciptor = new ConstraintDescriptorImpl( size, new Class<?>[] { } );
- expected = "size must be between -2147483648 and 2147483647"; // unkown token {}
- actual = resolver.interpolate( size.message(), desciptor, null );
- assertEquals( "Wrong substitution", expected, actual );
- }
-
-
- class TestResources extends ResourceBundle implements Enumeration<String> {
- private Map<String, String> testResources;
- Iterator<String> iter;
-
- public TestResources() {
- testResources = new HashMap<String, String>();
- // add some test messages
- testResources.put( "foo", "replacement worked" );
-
- iter = testResources.keySet().iterator();
- }
-
- public Object handleGetObject(String key) {
- return testResources.get( key );
- }
-
- public Enumeration<String> getKeys() {
- return this;
- }
-
- public boolean hasMoreElements() {
- return iter.hasNext();
- }
-
- public String nextElement() {
- if ( hasMoreElements() ) {
- return iter.next();
- }
- else {
- throw new NoSuchElementException();
- }
- }
- }
-}
Modified: validator/trunk/hibernate-validator/src/test/resources/log4j.properties
===================================================================
--- validator/trunk/hibernate-validator/src/test/resources/log4j.properties 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/hibernate-validator/src/test/resources/log4j.properties 2009-01-25 20:44:59 UTC (rev 15816)
@@ -22,5 +22,5 @@
log4j.logger.org.hibernate.validation.engine.ValidatorImpl=debug
log4j.logger.org.hibernate.validation.engine.ConstraintTree=trace
-org.hibernate.validation.impl.ResourceBundleMessageResolver=info
+org.hibernate.validation.impl.ResourceBundleMessageInterpolator=info
Copied: validator/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java (from rev 15815, validator/trunk/validation-api/src/main/java/javax/validation/MessageResolver.java)
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java (rev 0)
+++ validator/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -0,0 +1,59 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package javax.validation;
+
+import java.util.Locale;
+
+/**
+ * Interpolate a given constraint violation message.
+ *
+ * @author Emmanuel Bernard
+ * @author Hardy Ferentschik
+ */
+public interface MessageInterpolator {
+ /**
+ * Interpolate the message from the constraint parameters and the actual validated object.
+ * The locale is defaulted according to the <code>MessageInterpolator</code> implementation
+ * See the implementation documentation for more detail.
+ *
+ * @param message The message to interpolate.
+ * @param constraintDescriptor The constraint descriptor.
+ * @param value The object being validated
+ *
+ * @return Interpolated error message.
+ */
+ String interpolate(String message,
+ ConstraintDescriptor constraintDescriptor,
+ Object value);
+
+ /**
+ * Interpolate the message from the constraint parameters and the actual validated object.
+ * The Locale used is provided as a parameter
+ *
+ * @param message The message to interpolate.
+ * @param constraintDescriptor The constraint descriptor.
+ * @param value The object being validated
+ * @param locale the locale targeted for the message
+ *
+ * @return Interpolated error message.
+ */
+ String interpolate(String message,
+ ConstraintDescriptor constraintDescriptor,
+ Object value,
+ Locale locale);
+}
Property changes on: validator/trunk/validation-api/src/main/java/javax/validation/MessageInterpolator.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted: validator/trunk/validation-api/src/main/java/javax/validation/MessageResolver.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/MessageResolver.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/validation-api/src/main/java/javax/validation/MessageResolver.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -1,59 +0,0 @@
-// $Id$
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2008, Red Hat Middleware LLC, and individual contributors
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-* http://www.apache.org/licenses/LICENSE-2.0
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-package javax.validation;
-
-import java.util.Locale;
-
-/**
- * Interpolate a given constraint violation message.
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-public interface MessageResolver {
- /**
- * Interpolate the message from the constraint parameters and the actual validated object.
- * The locale is defaulted according to the <code>MessageResolver</code> implementation
- * See the implementation documentation for more detail.
- *
- * @param message The message to interpolate.
- * @param constraintDescriptor The constraint descriptor.
- * @param value The object being validated
- *
- * @return Interpolated error message.
- */
- String interpolate(String message,
- ConstraintDescriptor constraintDescriptor,
- Object value);
-
- /**
- * Interpolate the message from the constraint parameters and the actual validated object.
- * The Locale used is provided as a parameter
- *
- * @param message The message to interpolate.
- * @param constraintDescriptor The constraint descriptor.
- * @param value The object being validated
- * @param locale the locale targeted for the message
- *
- * @return Interpolated error message.
- */
- String interpolate(String message,
- ConstraintDescriptor constraintDescriptor,
- Object value,
- Locale locale);
-}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ValidatorBuilder.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ValidatorBuilder.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ValidatorBuilder.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -7,12 +7,12 @@
*/
public interface ValidatorBuilder {
/**
- * Defines the message resolver implementation used by the Validator.
- * If unset, the message resolver of the ValidatorFactory is used.
+ * Defines the message interpolator implementation used by the Validator.
+ * If unset, the message interpolator of the ValidatorFactory is used.
*
* @return self following the chaining method pattern
*/
- ValidatorBuilder messageResolver(MessageResolver messageResolver);
+ ValidatorBuilder messageInterpolator(MessageInterpolator messageInterpolator);
/**
* Defines the traversable resolver implementation used by the Validator.
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactory.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -27,7 +27,7 @@
public interface ValidatorFactory {
/**
* return an initialized Validator instance using the default factory instances
- * for message resolver and traversable resolver.
+ * for message interpolator and traversable resolver.
*
* Validator instances can be pooled and shared by the implementation
*/
@@ -42,11 +42,11 @@
ValidatorBuilder defineValidatorState();
/**
- * Returns the MessageResolver instance configured at initialization time
+ * Returns the MessageInterpolator instance configured at initialization time
* for the ValidatorFactory
* This is the instance used by #getValidator(Class)
*
- * @return MessageResolver instance
+ * @return MessageInterpolator instance
*/
- MessageResolver getMessageResolver();
+ MessageInterpolator getMessageInterpolator();
}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -28,7 +28,7 @@
* <pre>
* ValidatorFactoryBuilder<?> builder = //provided by one of the Validation bootstrap methods
* ValidatorFactory = builder
- * .messageResolver( new CustomMessageResolver() )
+ * .messageInterpolator( new CustomMessageInterpolator() )
* .build();
* </pre>
* <p/>
@@ -49,14 +49,14 @@
*/
public interface ValidatorFactoryBuilder<T extends ValidatorFactoryBuilder> {
/**
- * Defines the message resolver used. Has priority over the configuration
- * based message resolver.
+ * Defines the message interpolator used. Has priority over the configuration
+ * based message interpolator.
*
- * @param resolver message resolver implementation.
+ * @param interpolator message interpolator implementation.
*
* @return <code>this</code> following the chaining method pattern.
*/
- T messageResolver(MessageResolver resolver);
+ T messageInterpolator(MessageInterpolator interpolator);
/**
* Defines the traversable resolver used. Has priority over the configuration
@@ -92,14 +92,14 @@
T configure(InputStream stream);
/**
- * Return an implementation of the MessageResolver interface following the
- * default MessageREsolver defined in the specification:
+ * Return an implementation of the MessageInterpolator interface following the
+ * default MessageInterpolator defined in the specification:
* - use the ValidationMessages resource bundle to load keys
* - use Locale.getDefault()
*
- * @return default MessageResolver implementation compliant with the specification
+ * @return default MessageInterpolator implementation compliant with the specification
*/
- MessageResolver getDefaultMessageResolver();
+ MessageInterpolator getDefaultMessageInterpolator();
/**
* Build a ValidatorFactory implementation.
Modified: validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidatorFactoryConfiguration.java
===================================================================
--- validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidatorFactoryConfiguration.java 2009-01-23 23:17:08 UTC (rev 15815)
+++ validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidatorFactoryConfiguration.java 2009-01-25 20:44:59 UTC (rev 15816)
@@ -19,7 +19,7 @@
import java.io.InputStream;
import javax.validation.ConstraintFactory;
-import javax.validation.MessageResolver;
+import javax.validation.MessageInterpolator;
import javax.validation.TraversableResolver;
/**
@@ -33,12 +33,12 @@
*/
public interface ValidatorFactoryConfiguration {
/**
- * Message resolver as defined by the client programmatically
+ * Message interpolator as defined by the client programmatically
* or null if undefined.
*
* @return message provider instance or null if not defined
*/
- MessageResolver getMessageResolver();
+ MessageInterpolator getMessageInterpolator();
/**
* Returns the configuration stream defined by the client programmatically
More information about the hibernate-commits
mailing list