Hibernate SVN: r16734 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-10 06:44:41 -0400 (Wed, 10 Jun 2009)
New Revision: 16734
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java
Log:
Deleted obsolete class
Deleted: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java 2009-06-10 10:43:12 UTC (rev 16733)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/DefaultValidationProviderResolver.java 2009-06-10 10:44:41 UTC (rev 16734)
@@ -1,121 +0,0 @@
-package org.hibernate.validation.engine;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-import java.util.WeakHashMap;
-import javax.validation.ValidationException;
-import javax.validation.ValidationProviderResolver;
-import javax.validation.spi.ValidationProvider;
-
-/**
- * Find <code>ValidationProvider</code> according to the default <code>ValidationProviderResolver</code> defined in the
- * Bean Validation specification. This implementation uses the current classloader or the classloader which has loaded
- * the current class if the current class loader is unavailable. The classloader is used to retrieve the Service Provider files.
- * <p>
- * This class implements the Service Provider pattern described <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Service%20Provider">here</a>.
- * Since we cannot rely on Java 6 we have to reimplement the <code>Service</code> functionality.
- * </p>
- *
- * Duplicated from the private innner class Validation#DefaultValidationProviderResolver
- *
- * @author Emmanuel Bernard
- * @author Hardy Ferentschik
- */
-public class DefaultValidationProviderResolver implements ValidationProviderResolver {
-
- //cache per classloader for an appropriate discovery
- //keep them in a weak hashmap to avoid memory leaks and allow proper hot redeployment
- //TODO use a WeakConcurrentHashMap
- private static final Map<ClassLoader, List<ValidationProvider>> providersPerClassloader =
- new WeakHashMap<ClassLoader, List<ValidationProvider>>();
-
- private static final String SERVICES_FILE = "META-INF/services/" + ValidationProvider.class.getName();
-
- public List<ValidationProvider> getValidationProviders() {
- ClassLoader classloader = Thread.currentThread().getContextClassLoader();
- if ( classloader == null ) {
- classloader = DefaultValidationProviderResolver.class.getClassLoader();
- }
-
- List<ValidationProvider> providers;
- synchronized ( providersPerClassloader ) {
- providers = providersPerClassloader.get( classloader );
- }
-
- if ( providers == null ) {
- providers = new ArrayList<ValidationProvider>();
- String name = null;
- try {
- Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE );
- while ( providerDefinitions.hasMoreElements() ) {
- URL url = providerDefinitions.nextElement();
- InputStream stream = url.openStream();
- BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100 );
- try {
- name = reader.readLine();
- while ( name != null ) {
- name = name.trim();
- if ( !name.startsWith( "#" ) ) {
- final Class<?> providerClass = loadClass(
- name,
- DefaultValidationProviderResolver.class
- );
-
- providers.add(
- ( ValidationProvider ) providerClass.newInstance()
- );
- }
- name = reader.readLine();
- }
- }
- finally {
- reader.close();
- }
- }
- }
- catch ( IOException e ) {
- throw new ValidationException( "Unable to read " + SERVICES_FILE, e );
- }
- catch ( ClassNotFoundException e ) {
- //TODO is it better to not fail the whole loading because of a black sheep?
- throw new ValidationException( "Unable to load Bean Validation provider " + name, e );
- }
- catch ( IllegalAccessException e ) {
- throw new ValidationException( "Unable to instanciate Bean Validation provider" + name, e );
- }
- catch ( InstantiationException e ) {
- throw new ValidationException( "Unable to instanciate Bean Validation provider" + name, e );
- }
-
- synchronized ( providersPerClassloader ) {
- providersPerClassloader.put( classloader, providers );
- }
- }
-
- return providers;
- }
-
- private static Class<?> loadClass(String name, Class caller) throws ClassNotFoundException {
- try {
- //try context classloader, if fails try caller classloader
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- if ( loader != null ) {
- return loader.loadClass( name );
- }
- }
- catch ( ClassNotFoundException e ) {
- //trying caller classloader
- if ( caller == null ) {
- throw e;
- }
- }
- return Class.forName( name, true, caller.getClassLoader() );
- }
-}
15 years, 5 months
Hibernate SVN: r16733 - in beanvalidation/trunk/validation-tck/src/main: java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-10 06:43:12 -0400 (Wed, 10 Jun 2009)
New Revision: 16733
Added:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/
beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java
Log:
Added bootstrapping tests.
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java 2009-06-10 10:43:12 UTC (rev 16733)
@@ -0,0 +1,53 @@
+// $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.jsr303.tck.tests.bootstrap.customprovider;
+
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.test.audit.annotations.SpecAssertion;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
+@Resource( source = "javax.validation.spi.ValidationProvider", destination = "WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
+@IntegrationTest
+public class ExplicitCustomProviderBootstrapTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "4.4.4.2", id = "a")
+ public void testGetFactoryByProviderSpecifiedProgrammatically() {
+ TCKValidatorConfiguration configuration = Validation.byProvider( TCKValidatorConfiguration.class ).configure();
+ ValidatorFactory factory = configuration.buildValidatorFactory();
+ assertNotNull( factory );
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/ExplicitCustomProviderBootstrapTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java 2009-06-10 10:43:12 UTC (rev 16733)
@@ -0,0 +1,75 @@
+// $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.jsr303.tck.tests.bootstrap.customprovider;
+
+import javax.validation.Configuration;
+import javax.validation.MessageInterpolator;
+import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.BootstrapState;
+import javax.validation.spi.ConfigurationState;
+import javax.validation.spi.ValidationProvider;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class TCKValidationProvider implements ValidationProvider {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isSuitable(Class<? extends Configuration<?>> builderClass) {
+ return builderClass == TCKValidatorConfiguration.class;
+ }
+
+ public <T extends Configuration<T>> T createSpecializedConfiguration(BootstrapState state, Class<T> configurationClass) {
+ if ( !isSuitable( configurationClass ) ) {
+ throw new ValidationException(
+ "Illegal call to createSpecializedConfiguration() for a non suitable provider"
+ );
+ }
+ //cast protected by isSuitable call
+ return configurationClass.cast( new TCKValidatorConfiguration( this ) );
+ }
+
+
+ public Configuration<?> createGenericConfiguration(BootstrapState state) {
+ return new TCKValidatorConfiguration( this );
+ }
+
+ public ValidatorFactory buildValidatorFactory(ConfigurationState configurationState) {
+ return new DummyValidatorFactory();
+ }
+
+ public static class DummyValidatorFactory implements ValidatorFactory {
+
+ public Validator getValidator() {
+ return null;
+ }
+
+ public ValidatorContext usingContext() {
+ return null;
+ }
+
+ public MessageInterpolator getMessageInterpolator() {
+ return null;
+ }
+ }
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidationProvider.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java 2009-06-10 10:43:12 UTC (rev 16733)
@@ -0,0 +1,73 @@
+// $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.jsr303.tck.tests.bootstrap.customprovider;
+
+import java.io.InputStream;
+import javax.validation.Configuration;
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.ValidatorFactory;
+import javax.validation.spi.ValidationProvider;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class TCKValidatorConfiguration implements Configuration<TCKValidatorConfiguration> {
+ private final ValidationProvider provider;
+
+ public TCKValidatorConfiguration(){
+ provider = null;
+ }
+
+ public TCKValidatorConfiguration(ValidationProvider provider) {
+ this.provider = provider;
+ }
+
+ public TCKValidatorConfiguration ignoreXmlConfiguration() {
+ return this;
+ }
+
+ public TCKValidatorConfiguration messageInterpolator(MessageInterpolator interpolator) {
+ return this;
+ }
+
+ public TCKValidatorConfiguration traversableResolver(TraversableResolver resolver) {
+ return this;
+ }
+
+ public TCKValidatorConfiguration constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory) {
+ return this;
+ }
+
+ public TCKValidatorConfiguration addMapping(InputStream stream) {
+ return this;
+ }
+
+ public TCKValidatorConfiguration addProperty(String name, String value) {
+ return this;
+ }
+
+ public MessageInterpolator getDefaultMessageInterpolator() {
+ return null;
+ }
+
+ public ValidatorFactory buildValidatorFactory() {
+ return provider.buildValidatorFactory( null );
+ }
+}
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/TCKValidatorConfiguration.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java 2009-06-10 10:43:12 UTC (rev 16733)
@@ -0,0 +1,62 @@
+// $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.jsr303.tck.tests.bootstrap.customprovider.xmldefined;
+
+import javax.validation.Validation;
+import javax.validation.ValidatorFactory;
+
+import org.jboss.test.audit.annotations.SpecAssertion;
+import org.jboss.testharness.AbstractTest;
+import org.jboss.testharness.impl.packaging.Artifact;
+import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
+import org.jboss.testharness.impl.packaging.IntegrationTest;
+import org.jboss.testharness.impl.packaging.Resource;
+import org.jboss.testharness.impl.packaging.jsr303.ValidationXml;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.jsr303.tck.tests.bootstrap.customprovider.TCKValidationProvider;
+import org.hibernate.jsr303.tck.tests.bootstrap.customprovider.TCKValidatorConfiguration;
+import org.hibernate.jsr303.tck.util.TestUtil;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Artifact(artifactType = ArtifactType.JSR303)
+@Classes({
+ TestUtil.class,
+ TCKValidationProvider.class,
+ TCKValidatorConfiguration.class,
+ TCKValidationProvider.DummyValidatorFactory.class
+})
+@Resource(source = "/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider",
+ destination = "WEB-INF/classes/META-INF/services/javax.validation.spi.ValidationProvider")
+@ValidationXml("validation.xml")
+@IntegrationTest
+public class CustomProviderInXmlBootstrapTest extends AbstractTest {
+
+ @Test
+ @SpecAssertion(section = "4.4.4.2", id = "a")
+ public void testGetFactoryByProviderSpecifiedInXml() {
+ ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
+ assertNotNull( factory );
+ assertTrue( factory instanceof TCKValidationProvider.DummyValidatorFactory );
+ }
+}
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/CustomProviderInXmlBootstrapTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java 2009-06-10 10:41:50 UTC (rev 16732)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java 2009-06-10 10:43:12 UTC (rev 16733)
@@ -86,7 +86,7 @@
@Test
@SpecAssertion(section = "4.4.4.1", id = "c")
- public void testServiceFileExista() {
+ public void testServiceFileExists() {
List<ValidationProvider> providers = readBeanValidationServiceFile();
assertTrue( !providers.isEmpty(), "There should be at least one provider" );
}
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider 2009-06-10 10:43:12 UTC (rev 16733)
@@ -0,0 +1 @@
+org.hibernate.jsr303.tck.tests.bootstrap.customprovider.TCKValidationProvider
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/javax.validation.spi.ValidationProvider
___________________________________________________________________
Name: svn:eol-style
+ native
Added: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml (rev 0)
+++ beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml 2009-06-10 10:43:12 UTC (rev 16733)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<validation-config xmlns="http://jboss.org/xml/ns/javax/validation/configuration"
+ xsi:schemaLocation="http://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <default-provider>org.hibernate.jsr303.tck.tests.bootstrap.customprovider.TCKValidatorConfiguration</default-provider>
+</validation-config>
\ No newline at end of file
Property changes on: beanvalidation/trunk/validation-tck/src/main/resources/org/hibernate/jsr303/tck/tests/bootstrap/customprovider/xmldefined/validation.xml
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
15 years, 5 months
Hibernate SVN: r16732 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-10 06:41:50 -0400 (Wed, 10 Jun 2009)
New Revision: 16732
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java
Log:
javadoc
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java 2009-06-09 19:31:53 UTC (rev 16731)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/Configuration.java 2009-06-10 10:41:50 UTC (rev 16732)
@@ -25,10 +25,11 @@
* <p/>
* Usage:
* <pre>
+ * {@code
* Configuration<?> configuration = //provided by one of the Validation bootstrap methods
* ValidatorFactory = configuration
* .messageInterpolator( new CustomMessageInterpolator() )
- * .buildValidatorFactory();
+ * .buildValidatorFactory();}
* </pre>
* <p/>
* By default, the configuration information is retrieved from
@@ -36,7 +37,7 @@
* It is possible to override the configuration retrieved from the XML file
* by using one or more of the <code>Configuration</code> methods.
* <p/>
- * The {@link ValidationProviderResolver) is specified at configuration time
+ * The {@link ValidationProviderResolver} is specified at configuration time
* (see {@link javax.validation.spi.ValidationProvider}).
* If none is explicitely requested, the default <code>ValidationProviderResolver</code> is used.
* <p/>
15 years, 5 months
Hibernate SVN: r16731 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-09 15:31:53 -0400 (Tue, 09 Jun 2009)
New Revision: 16731
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java
Log:
typo
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-06-09 18:54:36 UTC (rev 16730)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintDescriptor.java 2009-06-09 19:31:53 UTC (rev 16731)
@@ -33,7 +33,7 @@
/**
* Returns the annotation describing the constraint declaration.
* If a composing constraint, attribute values are reflecting
- * the overridden attributes from the composing constraint
+ * the overridden attributes of the composing constraint
*
* @return The annotation for this constraint.
*/
@@ -60,7 +60,7 @@
* Returns a map containing the annotation attribute names as keys and the
* annotation attribute values as value.
* If this constraint is used as part of a composed constraint, attribute
- * values are reflecting the overridden attribute from the composing constraint.
+ * values are reflecting the overridden attribute of the composing constraint.
*
* @return a map containing the annotation attribute names as keys
* and the annotation attribute values as value.
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java 2009-06-09 18:54:36 UTC (rev 16730)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidatorContext.java 2009-06-09 19:31:53 UTC (rev 16731)
@@ -56,7 +56,7 @@
/**
* Add a new error message to a given sub property <code>property</code>. The subproperty
- * is relative to the path tot he bean or property hosting the constraint.
+ * is relative to the path to the bean or property hosting the constraint.
*
* This error message will be interpolated.
* <p/>
15 years, 5 months
Hibernate SVN: r16730 - beanvalidation/trunk/validation-api/src/main/java/javax/validation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-06-09 14:54:36 -0400 (Tue, 09 Jun 2009)
New Revision: 16730
Modified:
beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidator.java
Log:
typo
Modified: beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidator.java
===================================================================
--- beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidator.java 2009-06-09 16:50:05 UTC (rev 16729)
+++ beanvalidation/trunk/validation-api/src/main/java/javax/validation/ConstraintValidator.java 2009-06-09 18:54:36 UTC (rev 16730)
@@ -31,7 +31,7 @@
public interface ConstraintValidator<A extends Annotation, T> {
/**
* Initialize the validator in preparation for isValid calls.
- * The onstraint annotation for a given constraint declaration
+ * The constraint annotation for a given constraint declaration
* is passed.
* <p/>
* This method is guaranteed to be called before any of the other Constraint
15 years, 5 months
Hibernate SVN: r16729 - validator/trunk/hibernate-validator-legacy/src/main/java/org/hibernate/validator.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 12:50:05 -0400 (Tue, 09 Jun 2009)
New Revision: 16729
Modified:
validator/trunk/hibernate-validator-legacy/src/main/java/org/hibernate/validator/DigitsValidator.java
Log:
removed a IDE inspection warning
Modified: validator/trunk/hibernate-validator-legacy/src/main/java/org/hibernate/validator/DigitsValidator.java
===================================================================
--- validator/trunk/hibernate-validator-legacy/src/main/java/org/hibernate/validator/DigitsValidator.java 2009-06-09 16:49:24 UTC (rev 16728)
+++ validator/trunk/hibernate-validator-legacy/src/main/java/org/hibernate/validator/DigitsValidator.java 2009-06-09 16:50:05 UTC (rev 16729)
@@ -27,7 +27,7 @@
return true;
}
- String stringValue = null;
+ String stringValue;
if ( value instanceof String ) {
try {
15 years, 5 months
Hibernate SVN: r16728 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 12:49:24 -0400 (Tue, 09 Jun 2009)
New Revision: 16728
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java
Log:
Removed obsolete javadoc
Modified: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java 2009-06-09 16:48:27 UTC (rev 16727)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidationProvider.java 2009-06-09 16:49:24 UTC (rev 16728)
@@ -36,9 +36,6 @@
*/
public class HibernateValidationProvider implements ValidationProvider {
- /**
- * {@inheritDoc}
- */
public boolean isSuitable(Class<? extends Configuration<?>> builderClass) {
return builderClass == HibernateValidatorConfiguration.class;
}
@@ -53,16 +50,12 @@
return configurationClass.cast( new ConfigurationImpl( this ) );
}
- /**
- * {@inheritDoc}
- */
+
public Configuration<?> createGenericConfiguration(BootstrapState state) {
return new ConfigurationImpl( state );
}
- /**
- * {@inheritDoc}
- */
+
public ValidatorFactory buildValidatorFactory(ConfigurationState configurationState) {
return new ValidatorFactoryImpl( configurationState );
}
15 years, 5 months
Hibernate SVN: r16727 - beanvalidation/trunk/validation-tck/src/main/resources.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 12:48:27 -0400 (Tue, 09 Jun 2009)
New Revision: 16727
Modified:
beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
Log:
Modified: beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-09 16:47:42 UTC (rev 16726)
+++ beanvalidation/trunk/validation-tck/src/main/resources/tck-audit.xml 2009-06-09 16:48:27 UTC (rev 16727)
@@ -3,18 +3,6 @@
xsi:schemaLocation="http://jboss.com/products/webbeans/tck/audit http://snapshots.jboss.org/maven2/org/hibernate/tck-utils-api/0.9-SNAPSHO..."
name="JSR-303: Bean Validation" version="Revised Public Review Draft">
- <section id="2" title="Constraint definition">
- <assertion id="a">
- <text>Constraints are defined by the combination of a constraint annotation and a list
- of constraint validation implement- ations</text>
- </assertion>
-
- <assertion id="b">
- <text>The constraint annotation is applied on types, methods, fields or other constraint
- annotations </text>
- </assertion>
- </section>
-
<section id="2.1" title="Constraint Definition">
<assertion id="a">
<text>An annotation is considered a constraint definition if its retention policy
@@ -166,7 +154,7 @@
<assertion id="g">
<text>It returns false if the value is not valid, true otherwise</text>
</assertion>
- <assertion id="h">
+ <assertion id="h" testable="false">
<text>isValid implementations must be thread-safe</text>
</assertion>
<assertion id="i">
@@ -505,7 +493,7 @@
</assertion>
</section>
<section id="4.1" title="Validator API ">
- <assertion id="a">
+ <assertion id="a" testable="false">
<text>Validator implementations are thread-safe</text>
</assertion>
</section>
@@ -678,7 +666,7 @@
</assertion>
</section>
<section id="4.3.2" title="Custom message interpolation">
- <assertion id="a">
+ <assertion id="a" testable="false">
<text>A message interpolator implementation shall be thread-safe</text>
</assertion>
<assertion id="b">
@@ -694,7 +682,7 @@
</assertion>
</section>
<section id="4.4.1" title="Examples">
- <assertion id="">
+ <assertion id="a" testable="false">
<text>The ValidatorFactory object is thread-safe</text>
</assertion>
</section>
@@ -749,10 +737,10 @@
<section id="4.4.4.1" title="">
<assertion id="a">
<text>ValidationProviderResolver returns the list of Bean Validation providers available
- at runtime and more specific- ally a ValidationProvider instance for each provider
+ at runtime and more specifically a ValidationProvider instance for each provider
available in the context</text>
</assertion>
- <assertion id="b">
+ <assertion id="b" testable="false">
<text>Implementations must be thread-safe</text>
</assertion>
<assertion id="c">
@@ -876,11 +864,11 @@
</assertion>
</section>
<section id="4.4.7" title="Usage">
- <assertion id="a">
+ <assertion id="a" testable="false">
<text>ValidatorFactory is a thread-safe object that should be built once per deployment
unit</text>
</assertion>
- <assertion id="b">
+ <assertion id="b" testable="false" >
<text>Validator is thread-safe too and should be considered a lightweight object</text>
</assertion>
</section>
15 years, 5 months
Hibernate SVN: r16726 - beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 12:47:42 -0400 (Tue, 09 Jun 2009)
New Revision: 16726
Modified:
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java
beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java
Log:
bootstrap tests
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java 2009-06-09 14:32:46 UTC (rev 16725)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/DefaultBootstrapTest.java 2009-06-09 16:47:42 UTC (rev 16726)
@@ -17,24 +17,43 @@
*/
package org.hibernate.jsr303.tck.tests.bootstrap.defaultprovider;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
+import javax.validation.spi.ValidationProvider;
+import org.jboss.test.audit.annotations.SpecAssertion;
import org.jboss.testharness.AbstractTest;
import org.jboss.testharness.impl.packaging.Artifact;
import org.jboss.testharness.impl.packaging.ArtifactType;
+import org.jboss.testharness.impl.packaging.Classes;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
+import org.hibernate.jsr303.tck.util.TestUtil;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertConstraintViolation;
+import static org.hibernate.jsr303.tck.util.TestUtil.assertInvalidPropertyPaths;
+
/**
* @author Hardy Ferentschik
*/
@Artifact(artifactType = ArtifactType.JSR303)
+(a)Classes(TestUtil.class)
public class DefaultBootstrapTest extends AbstractTest {
+ private static final String SERVICES_FILE = "META-INF/services/" + ValidationProvider.class.getName();
+
@Test
public void testGetDefaultValidator() {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
@@ -42,14 +61,297 @@
assertNotNull( validator, "We should be able to get a validator." );
Person person = new Person();
- person.setFirstName( "John" );
+ person.setPersonalNumber( 12345678900l );
Set<ConstraintViolation<Person>> constraintViolations = validator.validate( person );
- assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertEquals( constraintViolations.size(), 3, "Wrong number of constraints" );
+ assertInvalidPropertyPaths(
+ constraintViolations,
+ new String[] { "firstName", "lastName", "personalNumber" }
+ );
+ person.setFirstName( "John" );
person.setLastName( "Doe" );
constraintViolations = validator.validate( person );
+ assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+ assertConstraintViolation(
+ constraintViolations.iterator().next(), Person.class, 12345678900l, "personalNumber"
+ );
+
+ person.setPersonalNumber( 1234567890l );
+ constraintViolations = validator.validate( person );
assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
}
+
+ @Test
+ @SpecAssertion(section = "4.4.4.1", id = "c")
+ public void testServiceFileExista() {
+ List<ValidationProvider> providers = readBeanValidationServiceFile();
+ assertTrue( !providers.isEmpty(), "There should be at least one provider" );
+ }
+
+ private List<ValidationProvider> readBeanValidationServiceFile() {
+ ClassLoader classloader = Thread.currentThread().getContextClassLoader();
+ if ( classloader == null ) {
+ classloader = DefaultBootstrapTest.class.getClassLoader();
+ }
+ List<ValidationProvider> providers = new ArrayList<ValidationProvider>();
+ try {
+
+ Enumeration<URL> providerDefinitions = classloader.getResources( SERVICES_FILE );
+ while ( providerDefinitions.hasMoreElements() ) {
+ URL url = providerDefinitions.nextElement();
+ addProviderToList( providers, url );
+ }
+ }
+ catch ( Exception e ) {
+ throw new RuntimeException( "Unable to load service file", e );
+ }
+ return providers;
+ }
+
+ private void addProviderToList(List<ValidationProvider> providers, URL url)
+ throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
+ InputStream stream = url.openStream();
+ try {
+ BufferedReader reader = new BufferedReader( new InputStreamReader( stream ), 100 );
+ String name = reader.readLine();
+ while ( name != null ) {
+ name = name.trim();
+ if ( !name.startsWith( "#" ) ) {
+ final Class<?> providerClass = loadClass(
+ name,
+ DefaultBootstrapTest.class
+ );
+
+ providers.add(
+ ( ValidationProvider ) providerClass.newInstance()
+ );
+ }
+ name = reader.readLine();
+ }
+ }
+ finally {
+ stream.close();
+ }
+ }
+
+ private static Class<?> loadClass(String name, Class caller) throws ClassNotFoundException {
+ try {
+ //try context classloader, if fails try caller classloader
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if ( loader != null ) {
+ return loader.loadClass( name );
+ }
+ }
+ catch ( ClassNotFoundException e ) {
+ //trying caller classloader
+ if ( caller == null ) {
+ throw e;
+ }
+ }
+ return Class.forName( name, true, caller.getClassLoader() );
+ }
+
+
+//
+// @Test
+// public void testCustomMessageInterpolator() {
+//
+// // first try with the default message resolver
+// Configuration<?> configuration = Validation.byDefaultProvider().configure();
+// assertDefaultBuilderAndFactory( configuration );
+//
+// ValidatorFactory factory = configuration.buildValidatorFactory();
+// Validator validator = factory.getValidator();
+//
+// Customer customer = new Customer();
+// customer.setFirstName( "John" );
+//
+// Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+// assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+// ConstraintViolation<Customer> constraintViolation = constraintViolations.iterator().next();
+// assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+//
+// // now we modify the configuration, get a new factory and valiator and try again
+// configuration = Validation.byDefaultProvider().configure();
+// configuration.messageInterpolator(
+// new MessageInterpolator() {
+// public String interpolate(String message, Context context) {
+// return "my custom message";
+// }
+//
+// public String interpolate(String message, Context context, Locale locale) {
+// throw new UnsupportedOperationException( "No specific locale is possible" );
+// }
+// }
+// );
+// factory = configuration.buildValidatorFactory();
+// validator = factory.getValidator();
+// constraintViolations = validator.validate( customer );
+// assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+// constraintViolation = constraintViolations.iterator().next();
+// assertEquals( "my custom message", constraintViolation.getMessage(), "Wrong message" );
+// }
+//
+// @Test
+// public void testCustomConstraintValidatorFactory() {
+//
+// Configuration<?> configuration = Validation.byDefaultProvider().configure();
+// assertDefaultBuilderAndFactory( configuration );
+//
+// ValidatorFactory factory = configuration.buildValidatorFactory();
+// Validator validator = factory.getValidator();
+//
+// Customer customer = new Customer();
+// customer.setFirstName( "John" );
+//
+// Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+// assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+// ConstraintViolation<Customer> constraintViolation = constraintViolations.iterator().next();
+// assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+//
+// // get a new factory using a custom configuration
+// configuration = Validation.byDefaultProvider().configure();
+// configuration.constraintValidatorFactory(
+// new ConstraintValidatorFactory() {
+//
+// public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T> key) {
+// if ( key == NotNullValidator.class ) {
+// return ( T ) new BadlyBehavedNotNullConstraintValidator();
+// }
+// return new ConstraintValidatorFactoryImpl().getInstance( key );
+// }
+// }
+// );
+// factory = configuration.buildValidatorFactory();
+// validator = factory.getValidator();
+// constraintViolations = validator.validate( customer );
+// assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+// }
+//
+// @Test
+// public void testCustomResolverAndType() {
+// ValidationProviderResolver resolver = new ValidationProviderResolver() {
+//
+// public List<ValidationProvider> getValidationProviders() {
+// List<ValidationProvider> list = new ArrayList<ValidationProvider>();
+// list.add( new HibernateValidationProvider() );
+// return list;
+// }
+// };
+//
+//
+// HibernateValidatorConfiguration configuration = Validation
+// .byProvider( HibernateValidatorConfiguration.class )
+// .providerResolver( resolver )
+// .configure();
+// assertDefaultBuilderAndFactory( configuration );
+// }
+//
+// @Test
+// public void testCustomResolver() {
+// ValidationProviderResolver resolver = new ValidationProviderResolver() {
+//
+// public List<ValidationProvider> getValidationProviders() {
+// List<ValidationProvider> list = new ArrayList<ValidationProvider>();
+// list.add( new HibernateValidationProvider() );
+// return list;
+// }
+// };
+//
+//
+// Configuration<?> configuration = Validation
+// .byDefaultProvider()
+// .providerResolver( resolver )
+// .configure();
+// assertDefaultBuilderAndFactory( configuration );
+// }
+//
+// @Test
+// public void testFailingCustomResolver() {
+// ValidationProviderResolver resolver = new ValidationProviderResolver() {
+//
+// public List<ValidationProvider> getValidationProviders() {
+// return new ArrayList<ValidationProvider>();
+// }
+// };
+//
+// final ProviderSpecificBootstrap<HibernateValidatorConfiguration> providerSpecificBootstrap =
+// Validation
+// .byProvider( HibernateValidatorConfiguration.class )
+// .providerResolver( resolver );
+//
+// try {
+// providerSpecificBootstrap.configure();
+// fail();
+// }
+// catch ( ValidationException e ) {
+// assertEquals(
+// "Unable to find provider: interface org.hibernate.validation.engine.HibernateValidatorConfiguration",
+// e.getMessage(),
+// "Wrong error message"
+// );
+// }
+// }
+//
+// private void assertDefaultBuilderAndFactory(Configuration configuration) {
+// assertNotNull( configuration );
+// assertTrue( configuration instanceof ConfigurationImpl );
+//
+// ValidatorFactory factory = configuration.buildValidatorFactory();
+// assertDefaultFactory( factory );
+// }
+//
+// private void assertDefaultFactory(ValidatorFactory factory) {
+// assertNotNull( factory );
+// assertTrue( factory instanceof ValidatorFactoryImpl );
+// }
+//
+// class BadlyBehavedNotNullConstraintValidator extends NotNullValidator {
+// @Override
+// public boolean isValid(Object object, ConstraintValidatorContext constraintValidatorContext) {
+// return true;
+// }
+// }
+//
+// @Test
+// public void testCustomTraversableResolver() {
+//
+// Configuration<?> configuration = Validation.byDefaultProvider().configure();
+// assertDefaultBuilderAndFactory( configuration );
+//
+// ValidatorFactory factory = configuration.buildValidatorFactory();
+// Validator validator = factory.getValidator();
+//
+// Customer customer = new Customer();
+// customer.setFirstName( "John" );
+//
+// Set<ConstraintViolation<Customer>> constraintViolations = validator.validate( customer );
+// assertEquals( constraintViolations.size(), 1, "Wrong number of constraints" );
+// ConstraintViolation<Customer> constraintViolation = constraintViolations.iterator().next();
+// assertEquals( "may not be null", constraintViolation.getMessage(), "Wrong message" );
+//
+// // get a new factory using a custom configuration
+// configuration = Validation.byDefaultProvider().configure();
+// configuration.traversableResolver(
+// new TraversableResolver() {
+// public boolean isReachable(Object traversableObject, String traversableProperty, Class<?> rootBeanType, String pathToTraversableObject, ElementType elementType) {
+// return false;
+// }
+//
+// public boolean isCascadable(Object traversableObject, String traversableProperty, Class<?> rootBeanType, String pathToTraversableObject, ElementType elementType) {
+// return false;
+// }
+// }
+// );
+// factory = configuration.buildValidatorFactory();
+// validator = factory.getValidator();
+// constraintViolations = validator.validate( customer );
+// assertEquals( constraintViolations.size(), 0, "Wrong number of constraints" );
+// }
+//}
+
+
}
Modified: beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java
===================================================================
--- beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java 2009-06-09 14:32:46 UTC (rev 16725)
+++ beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/tests/bootstrap/defaultprovider/Person.java 2009-06-09 16:47:42 UTC (rev 16726)
@@ -17,6 +17,7 @@
*/
package org.hibernate.jsr303.tck.tests.bootstrap.defaultprovider;
+import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;
/**
@@ -29,7 +30,10 @@
@NotNull
private String lastName;
+ @Digits(integer = 10, fraction = 0)
+ private long personalNumber;
+
public String getFirstName() {
return firstName;
}
@@ -45,4 +49,12 @@
public void setLastName(String lastName) {
this.lastName = lastName;
}
+
+ public long getPersonalNumber() {
+ return personalNumber;
+ }
+
+ public void setPersonalNumber(long personalNumber) {
+ this.personalNumber = personalNumber;
+ }
}
15 years, 5 months
Hibernate SVN: r16725 - validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-06-09 10:32:46 -0400 (Tue, 09 Jun 2009)
New Revision: 16725
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java
Log:
HV-153 Caching created ConstraintValidators.
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-06-09 14:27:55 UTC (rev 16724)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ConstraintTree.java 2009-06-09 14:32:46 UTC (rev 16725)
@@ -18,9 +18,9 @@
package org.hibernate.validation.engine;
import java.lang.annotation.Annotation;
-import java.lang.reflect.Array;
import java.lang.reflect.Type;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -51,6 +51,8 @@
private final List<ConstraintTree<?>> children;
private final ConstraintDescriptor<A> descriptor;
+ private final Map<Class<? extends ConstraintValidator<?, ?>>, ConstraintValidator<A, ?>> constraintValidatorCache;
+
public ConstraintTree(ConstraintDescriptor<A> descriptor) {
this( descriptor, null );
}
@@ -58,6 +60,8 @@
private ConstraintTree(ConstraintDescriptor<A> descriptor, ConstraintTree<?> parent) {
this.parent = parent;
this.descriptor = descriptor;
+ this.constraintValidatorCache = new HashMap<Class<? extends ConstraintValidator<?, ?>>, ConstraintValidator<A, ?>>();
+
final Set<ConstraintDescriptor<?>> composingConstraints = descriptor.getComposingConstraints();
children = new ArrayList<ConstraintTree<?>>( composingConstraints.size() );
@@ -117,13 +121,19 @@
executionContext.peekParentPath(), executionContext.peekProperty(), descriptor
);
if ( !validator.isValid( value, constraintValidatorContext ) ) {
- constraintViolations.addAll( executionContext.createConstraintViolations( value, constraintValidatorContext ) );
+ constraintViolations.addAll(
+ executionContext.createConstraintViolations(
+ value, constraintValidatorContext
+ )
+ );
}
if ( reportAsSingleViolation() && constraintViolations.size() > 0 ) {
constraintViolations.clear();
final String message = ( String ) getParent().getDescriptor().getAttributes().get( "message" );
final String property = executionContext.peekPropertyPath();
- ConstraintValidatorContextImpl.ErrorMessage error = constraintValidatorContext.new ErrorMessage( message, property );
+ ConstraintValidatorContextImpl.ErrorMessage error = constraintValidatorContext.new ErrorMessage(
+ message, property
+ );
constraintViolations.add( executionContext.createConstraintViolation( value, error, descriptor ) );
}
}
@@ -143,10 +153,21 @@
private <V> ConstraintValidator<A, V> getInitalizedValidator(V value, Type type, ConstraintValidatorFactory constraintFactory) {
Class<? extends ConstraintValidator<?, ?>> validatorClass = findMatchingValidatorClass( value, type );
- @SuppressWarnings("unchecked")
- ConstraintValidator<A, V> constraintValidator = ( ConstraintValidator<A, V> ) constraintFactory.getInstance(
- validatorClass
- );
+ ConstraintValidator<A, V> constraintValidator;
+
+ if ( !constraintValidatorCache.containsKey( validatorClass ) ) {
+ constraintValidator = ( ConstraintValidator<A, V> ) constraintFactory.getInstance(
+ validatorClass
+ );
+ constraintValidatorCache.put( validatorClass, constraintValidator );
+ }
+ else {
+ if ( log.isTraceEnabled() ) {
+ log.trace( "Constraint validator {} found in cache" );
+ }
+ constraintValidator = ( ConstraintValidator<A, V> ) constraintValidatorCache.get( validatorClass );
+ }
+
initializeConstraint( descriptor, constraintValidator );
return constraintValidator;
}
@@ -165,10 +186,9 @@
List<Type> suitableTypes = new ArrayList<Type>();
findSuitableValidatorTypes( type, validatorsTypes, suitableTypes );
- // TODO - do we really have to take the actual value into consideration here as well? Or is it enough to
- // work with the type the constraint was placed on?
+
if ( value != null ) {
- findSuitableValidatorTypes( determineValueClass( value ), validatorsTypes, suitableTypes );
+ findSuitableValidatorTypes( value.getClass(), validatorsTypes, suitableTypes );
}
resolveAssignableTypes( suitableTypes );
@@ -177,14 +197,6 @@
return validatorsTypes.get( suitableTypes.get( 0 ) );
}
- private Class determineValueClass(Object value) {
- Class valueClass = value.getClass();
- if ( valueClass.isArray() ) {
- valueClass = Array.class;
- }
- return valueClass;
- }
-
private void verifyResolveWasUnique(Type valueClass, List<Type> assignableClasses) {
if ( assignableClasses.size() == 0 ) {
throw new UnexpectedTypeException( "No validator could be found for type: " + valueClass );
15 years, 5 months