Author: epbernard
Date: 2008-11-03 21:26:44 -0500 (Mon, 03 Nov 2008)
New Revision: 15492
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidatorFactoryBuilder.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java
Removed:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ContextImpl.java
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsViolationFromComposingConstraint.java
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/HibernateValidationProvider.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java
validator/trunk/validation-api/src/main/java/javax/validation/Validation.java
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/GenericBuilderFactory.java
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/SpecializedBuilderFactory.java
validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java
Log:
BVAL-62 rename ValidatorBuilder into ValidatorFactoryBuilder
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidatorFactoryBuilder.java
(from rev 15487,
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidatorBuilder.java)
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidatorFactoryBuilder.java
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidatorFactoryBuilder.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -0,0 +1,12 @@
+package org.hibernate.validation;
+
+import javax.validation.ValidatorFactoryBuilder;
+
+/**
+ * Uniquely identify Hibernate Validator in the Bean Validation bootstrap strategy
+ * Also contains Hibernate Validator specific configurations
+ *
+ * @author Emmanuel Bernard
+ */
+public interface HibernateValidatorFactoryBuilder extends
ValidatorFactoryBuilder<HibernateValidatorFactoryBuilder> {
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/HibernateValidatorFactoryBuilder.java
___________________________________________________________________
Name: svn:keywords
+ Id
Deleted:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ContextImpl.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ContextImpl.java 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/engine/ContextImpl.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -1,69 +0,0 @@
-package org.hibernate.validation.engine;
-
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
-import javax.validation.Context;
-import javax.validation.ConstraintDescriptor;
-
-import org.hibernate.validation.impl.ConstraintDescriptorImpl;
-
-/**
- * @author Emmanuel Bernard
- */
-public class ContextImpl implements Context {
- private final ConstraintDescriptor constraintDescriptor;
- private final List<ErrorMessage> errorMessages;
- private boolean defaultDisabled;
-
- public ContextImpl(ConstraintDescriptorImpl constraintDescriptor) {
- this.constraintDescriptor = constraintDescriptor;
- this.errorMessages = new ArrayList<ErrorMessage>(3);
- }
-
- public void disableDefaultError() {
- defaultDisabled = true;
- }
-
- public String getDefaultErrorMessage() {
- return ( String ) constraintDescriptor.getParameters().get("message");
- }
-
- public void addError(String message) {
- //FIXME get the default property if property-level
- errorMessages.add( new ErrorMessage( message, null ) );
- }
-
- public void addError(String message, String property) {
- //FIXME: make sure the property is valid
- errorMessages.add( new ErrorMessage( message, property ) );
- }
-
- public List<ErrorMessage> getErrorMessages() {
- List<ErrorMessage> returnedErrorMessages = new ArrayList<ErrorMessage>(
errorMessages.size() + 1 );
- Collections.copy( returnedErrorMessages, errorMessages );
- if ( ! defaultDisabled ) {
- //FIXME get the default property if property-level
- returnedErrorMessages.add( new ErrorMessage( getDefaultErrorMessage(), null) );
- }
- return returnedErrorMessages;
- }
-
- public static class ErrorMessage {
- private final String message;
- private final String property;
-
- private ErrorMessage(String message, String property) {
- this.message = message;
- this.property = property;
- }
-
- public String getMessage() {
- return message;
- }
-
- public String getProperty() {
- return property;
- }
- }
-}
Modified:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/HibernateValidationProvider.java
===================================================================
---
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/HibernateValidationProvider.java 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/HibernateValidationProvider.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -18,13 +18,13 @@
package org.hibernate.validation.impl;
import javax.validation.ValidationException;
-import javax.validation.ValidatorBuilder;
+import javax.validation.ValidatorFactoryBuilder;
import javax.validation.ValidatorFactory;
import javax.validation.spi.ValidationProvider;
import javax.validation.spi.ValidatorBuilderImplementor;
import javax.validation.spi.BootstrapState;
-import org.hibernate.validation.HibernateValidatorBuilder;
+import org.hibernate.validation.HibernateValidatorFactoryBuilder;
/**
* Default implementation of <code>ValidationProvider</code> within Hibernate
validator.
@@ -37,23 +37,23 @@
/**
* {@inheritDoc}
*/
- public boolean isSuitable(Class<? extends ValidatorBuilder<?>> builderClass)
{
- return builderClass == HibernateValidatorBuilder.class;
+ public boolean isSuitable(Class<? extends ValidatorFactoryBuilder<?>>
builderClass) {
+ return builderClass == HibernateValidatorFactoryBuilder.class;
}
- public <T extends ValidatorBuilder<T>> T
createSpecializedValidatorBuilder(BootstrapState state, Class<T> builderClass) {
+ public <T extends ValidatorFactoryBuilder<T>> T
createSpecializedValidatorFactoryBuilder(BootstrapState state, Class<T>
builderClass) {
if ( ! isSuitable( builderClass ) ) {
- throw new ValidationException("Illegal call to
createSpecializedValidatorBuilder() for a non suitable provider");
+ throw new ValidationException("Illegal call to
createSpecializedValidatorFactoryBuilder() for a non suitable provider");
}
//cast protected by isSuitable call
- return builderClass.cast( new ValidatorBuilderImpl( this ) );
+ return builderClass.cast( new ValidatorFactoryBuilderImpl( this ) );
}
/**
* {@inheritDoc}
*/
- public ValidatorBuilder<?> createGenericValidatorBuilder(BootstrapState state) {
- return new ValidatorBuilderImpl( state );
+ public ValidatorFactoryBuilder<?>
createGenericValidatorFactoryBuilder(BootstrapState state) {
+ return new ValidatorFactoryBuilderImpl( state );
}
/**
Copied:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java
(from rev 15487,
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
(rev 0)
+++
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -0,0 +1,116 @@
+// $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.io.InputStream;
+import java.util.List;
+import javax.validation.ConstraintFactory;
+import javax.validation.MessageResolver;
+import javax.validation.ValidationException;
+import javax.validation.ValidationProviderResolver;
+import javax.validation.ValidatorFactoryBuilder;
+import javax.validation.ValidatorFactory;
+import javax.validation.bootstrap.DefaultValidationProviderResolver;
+import javax.validation.spi.ValidationProvider;
+import javax.validation.spi.ValidatorBuilderImplementor;
+import javax.validation.spi.BootstrapState;
+
+import org.hibernate.validation.HibernateValidatorFactoryBuilder;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class ValidatorFactoryBuilderImpl implements HibernateValidatorFactoryBuilder,
ValidatorBuilderImplementor {
+ private MessageResolver messageResolver = new ResourceBundleMessageResolver();
+ private ConstraintFactory constraintFactory = new ConstraintFactoryImpl();
+ private String configurationFile = "META-INF/validation.xml";
+ private final ValidationProvider provider;
+ private final ValidationProviderResolver providerResolver;
+
+ public ValidatorFactoryBuilderImpl(BootstrapState state) {
+ if (state.getValidationProviderResolver() == null) {
+ this.providerResolver = new DefaultValidationProviderResolver();
+ }
+ else {
+ this.providerResolver = state.getValidationProviderResolver();
+ }
+ this.provider = null;
+ }
+
+ public ValidatorFactoryBuilderImpl(ValidationProvider provider) {
+ if ( provider == null ) {
+ throw new ValidationException( "Assertion error: inconsistent
ValidatorFactoryBuilderImpl construction");
+ }
+ this.provider = provider;
+ this.providerResolver = null;
+ }
+
+ public ValidatorFactoryBuilderImpl messageResolver(MessageResolver resolver) {
+ this.messageResolver = resolver;
+ return this;
+ }
+
+ public ValidatorFactoryBuilderImpl constraintFactory(ConstraintFactory
constraintFactory) {
+ this.constraintFactory = constraintFactory;
+ return this;
+ }
+
+ public ValidatorFactory build() {
+ if ( isSpecificProvider() ) {
+ return provider.buildValidatorFactory( this );
+ }
+ else {
+ //read provider name from configuration
+ Class<? extends ValidatorFactoryBuilder<?>> providerClass = null;
+
+ if ( providerClass != null ) {
+ for ( ValidationProvider provider : providerResolver.getValidationProviders() ) {
+ if ( provider.isSuitable( providerClass ) ) {
+ return provider.buildValidatorFactory( this );
+ }
+ }
+ throw new ValidationException( "Unable to find provider: " + providerClass
);
+ }
+ else {
+ List<ValidationProvider> providers =
providerResolver.getValidationProviders();
+ assert providers.size() != 0; //I run therefore I am
+ return providers.get( 0 ).buildValidatorFactory( this );
+ }
+ }
+ }
+
+ private boolean isSpecificProvider() {
+ return provider != null;
+ }
+
+ public MessageResolver getMessageResolver() {
+ return messageResolver;
+ }
+
+ public ConstraintFactory getConstraintFactory() {
+ return constraintFactory;
+ }
+
+ public ValidatorFactoryBuilderImpl configure(InputStream stream) {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+
+ public InputStream getConfigurationStream() {
+ return null; //To change body of implemented methods use File | Settings | File
Templates.
+ }
+}
Property changes on:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validation/impl/ValidatorFactoryBuilderImpl.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
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 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validation/bootstrap/ValidationTest.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -29,7 +29,7 @@
import javax.validation.ValidationException;
import javax.validation.ValidationProviderResolver;
import javax.validation.Validator;
-import javax.validation.ValidatorBuilder;
+import javax.validation.ValidatorFactoryBuilder;
import javax.validation.ValidatorFactory;
import javax.validation.ConstraintContext;
import javax.validation.bootstrap.SpecializedBuilderFactory;
@@ -41,11 +41,11 @@
import static org.junit.Assert.fail;
import org.junit.Test;
-import org.hibernate.validation.HibernateValidatorBuilder;
+import org.hibernate.validation.HibernateValidatorFactoryBuilder;
import org.hibernate.validation.constraints.NotNullConstraint;
import org.hibernate.validation.eg.Customer;
import org.hibernate.validation.impl.ConstraintFactoryImpl;
-import org.hibernate.validation.impl.ValidatorBuilderImpl;
+import org.hibernate.validation.impl.ValidatorFactoryBuilderImpl;
import org.hibernate.validation.impl.ValidatorFactoryImpl;
import org.hibernate.validation.impl.HibernateValidationProvider;
@@ -58,21 +58,21 @@
@Test
public void testBootstrapAsServiceWithBuilder() {
- HibernateValidatorBuilder builder = Validation
- .builderType( HibernateValidatorBuilder.class )
- .getValidatorBuilder();
+ HibernateValidatorFactoryBuilder builder = Validation
+ .builderType( HibernateValidatorFactoryBuilder.class )
+ .getBuilder();
assertDefaultBuilderAndFactory( builder );
}
@Test
public void testBootstrapAsServiceDefault() {
- ValidatorBuilder<?> builder = Validation.getValidatorBuilder();
+ ValidatorFactoryBuilder<?> builder = Validation.getBuilder();
assertDefaultBuilderAndFactory( builder );
}
@Test
public void testGetCustomerValiator() {
- ValidatorBuilder<?> builder = Validation.getValidatorBuilder();
+ ValidatorFactoryBuilder<?> builder = Validation.getBuilder();
assertDefaultBuilderAndFactory( builder );
ValidatorFactory factory = builder.build();
@@ -95,7 +95,7 @@
public void testCustomMessageResolver() {
// first try with the default message resolver
- ValidatorBuilder<?> builder = Validation.getValidatorBuilder();
+ ValidatorFactoryBuilder<?> builder = Validation.getBuilder();
assertDefaultBuilderAndFactory( builder );
ValidatorFactory factory = builder.build();
@@ -129,7 +129,7 @@
@Test
public void testCustomConstraintFactory() {
- ValidatorBuilder<?> builder = Validation.getValidatorBuilder();
+ ValidatorFactoryBuilder<?> builder = Validation.getBuilder();
assertDefaultBuilderAndFactory( builder );
ValidatorFactory factory = builder.build();
@@ -173,10 +173,10 @@
};
- HibernateValidatorBuilder builder = Validation
- .builderType( HibernateValidatorBuilder.class )
+ HibernateValidatorFactoryBuilder builder = Validation
+ .builderType( HibernateValidatorFactoryBuilder.class )
.providerResolver( resolver )
- .getValidatorBuilder();
+ .getBuilder();
assertDefaultBuilderAndFactory( builder );
}
@@ -192,10 +192,10 @@
};
- ValidatorBuilder<?> builder = Validation
+ ValidatorFactoryBuilder<?> builder = Validation
.defineBootstrapState()
.providerResolver( resolver )
- .getValidatorBuilder();
+ .getBuilder();
assertDefaultBuilderAndFactory( builder );
}
@@ -208,27 +208,27 @@
}
};
- final SpecializedBuilderFactory<HibernateValidatorBuilder>
specializedBuilderFactory =
+ final SpecializedBuilderFactory<HibernateValidatorFactoryBuilder>
specializedBuilderFactory =
Validation
- .builderType(HibernateValidatorBuilder.class)
+ .builderType( HibernateValidatorFactoryBuilder.class)
.providerResolver( resolver );
try {
- specializedBuilderFactory.getValidatorBuilder();
+ specializedBuilderFactory.getBuilder();
fail();
}
catch ( ValidationException e ) {
assertEquals(
"Wrong error message",
- "Unable to find provider: interface
org.hibernate.validation.HibernateValidatorBuilder",
+ "Unable to find provider: interface
org.hibernate.validation.HibernateValidatorFactoryBuilder",
e.getMessage()
);
}
}
- private void assertDefaultBuilderAndFactory(ValidatorBuilder builder) {
+ private void assertDefaultBuilderAndFactory(ValidatorFactoryBuilder builder) {
assertNotNull( builder );
- assertTrue( builder instanceof ValidatorBuilderImpl );
+ assertTrue( builder instanceof ValidatorFactoryBuilderImpl );
ValidatorFactory factory = builder.build();
assertNotNull( factory );
Deleted:
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsViolationFromComposingConstraint.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsViolationFromComposingConstraint.java 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/validation-api/src/main/java/javax/validation/ReportAsViolationFromComposingConstraint.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -1,35 +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.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
-
-/**
- * A constraint annotation annotated with this annotation
- * will return the composed annotation error report if any of the composing annotations
- * fail. The error reports of each individual composing constraint is ignored.
- *
- * @author Emmanuel Bernard
- */
-@Target({ ANNOTATION_TYPE })
-@Retention(RUNTIME)
-public @interface ReportAsViolationFromComposingConstraint {
-}
Modified: validator/trunk/validation-api/src/main/java/javax/validation/Validation.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/Validation.java 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/validation-api/src/main/java/javax/validation/Validation.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -29,7 +29,7 @@
* <li>
* The easiest approach is to use the default Bean Validation provider.
* <pre>
- * ValidatorFactory factory = Validation.getValidatorBuilder().build();
+ * ValidatorFactory factory = Validation.getBuilder().build();
* </pre>
* In this case {@link javax.validation.bootstrap.DefaultValidationProviderResolver
DefaultValidationProviderResolver}
* will be used to locate available providers.
@@ -45,10 +45,10 @@
* The second bootstrap approach allows to choose a custom
<code>ValidationProviderResolver</code>. The chosen
* <code>ValidationProvider</code> is then determined in the same way as in
the default bootstrapping case (see above).
* <pre>
- * ValidatorBuilder<?> builder = Validation
+ * ValidatorFactoryBuilder<?> builder = Validation
* .defineBootstrapState()
* .providerResolver( new MyResolverStrategy() )
- * .getValidatorBuilder();
+ * .getBuilder();
* ValidatorFactory factory = builder.build();
* </pre>
* </li>
@@ -56,14 +56,14 @@
* <p/>
* <li>
* The third approach allows you to specify explicitly and in a type safe fashion the
expected provider by
- * using its specific <code>ValidatorBuilder</code> sub-interface.
+ * using its specific <code>ValidatorFactoryBuilder</code> sub-interface.
*
* Optionally you can choose a custom
<code>ValidationProviderResolver</code>.
* <pre>
- * ACMEValidatorBuilder builder = Validation
- * .builderType(ACMEValidatorBuilder.class)
+ * ACMEValidatorFactoryBuilder builder = Validation
+ * .builderType(ACMEValidatorFactoryBuilder.class)
* .providerResolver( new MyResolverStrategy() ) // optionally set the provider
resolver
- * .getValidatorBuilder();
+ * .getBuilder();
* ValidatorFactory factory = builder.build();
* </pre>
* </li>
@@ -86,61 +86,61 @@
public class Validation {
/**
- * Build a <code>ValidatorBuilder</code>. The actual provider choice is
given by the XML configuration. If the
+ * Build a <code>ValidatorFactoryBuilder</code>. The actual provider choice
is given by the XML configuration. If the
* XML configuration does not exsist the default is taken.
* <p/>
* The provider list is resolved using the {@link
javax.validation.bootstrap.DefaultValidationProviderResolver
DefaultValidationProviderResolver}.
*
- * @return <code>ValidatorBuilder</code> instance.
+ * @return <code>ValidatorFactoryBuilder</code> instance.
*/
- public static ValidatorBuilder<?> getValidatorBuilder() {
- return defineBootstrapState().getValidatorBuilder();
+ public static ValidatorFactoryBuilder<?> getBuilder() {
+ return defineBootstrapState().getBuilder();
}
/**
- * Build a <code>ValidatorBuilder</code>. The provider list is resolved
using the strategy provided to the bootstrap state.
+ * Build a <code>ValidatorFactoryBuilder</code>. The provider list is
resolved using the strategy provided to the bootstrap state.
* <pre>
- * ValidatorBuilder<?> builder = Validation
+ * ValidatorFactoryBuilder<?> builder = Validation
* .defineBootstrapState()
* .providerResolver( new MyResolverStrategy() )
- * .getValidatorBuilder();
+ * .getBuilder();
* ValidatorFactory factory = builder.build();
* </pre>
* The actual provider choice is given by the XML configuration. If the XML
configuration does not exsist the first
* available provider will be returned.
*
- * @return instance building a generic <code>ValidatorBuilder</code>
compliant with the bootstrap state provided.
+ * @return instance building a generic <code>ValidatorFactoryBuilder</code>
compliant with the bootstrap state provided.
*/
public static GenericBuilderFactory defineBootstrapState() {
return new GenericBuilderFactoryImpl();
}
/**
- * Build a <code>ValidatorBuilder</code> for a particular provider
implementation.
+ * Build a <code>ValidatorFactoryBuilder</code> for a particular provider
implementation.
* Optionally override the provider resolution strategy used to determine the provider.
* <p/>
* Used by applications targeting a specific provider programmatically.
* <p/>
* <pre>
- * ACMEValidatorBuilder builder = Validation.builderType(ACMEValidatorBuilder.class)
+ * ACMEValidatorFactoryBuilder builder =
Validation.builderType(ACMEValidatorFactoryBuilder.class)
* .providerResolver( new MyResolverStrategy() )
* .build();
* </pre>,
- * where <code>ACMEValidatorBuilder</code> is the
<code>ValidatorBuiler</code> sub interface uniquely identifying
+ * where <code>ACMEValidatorFactoryBuilder</code> is the
<code>ValidatorFactoryBuilder</code> sub interface uniquely identifying
* the ACME Bean Validation provider.
*
- * @param builderType the <code>ValidatorBuilder</code> sub interface
uniquely defining the targeted provider.
+ * @param builderType the <code>ValidatorFactoryBuilder</code> sub interface
uniquely defining the targeted provider.
*
- * @return instance building a provider specific
<code>ValidatorBuilder</code> sub interface implementation.
+ * @return instance building a provider specific
<code>ValidatorFactoryBuilder</code> sub interface implementation.
*
- * @see #getValidatorBuilder()
+ * @see #getBuilder()
*/
- public static <T extends ValidatorBuilder<T>>
SpecializedBuilderFactory<T> builderType(Class<T> builderType) {
+ public static <T extends ValidatorFactoryBuilder<T>>
SpecializedBuilderFactory<T> builderType(Class<T> builderType) {
return new SpecializedBuilderFactoryImpl<T>( builderType );
}
//private class, not exposed
- private static class SpecializedBuilderFactoryImpl<T extends
ValidatorBuilder<T>>
+ private static class SpecializedBuilderFactoryImpl<T extends
ValidatorFactoryBuilder<T>>
implements SpecializedBuilderFactory<T> {
private Class<T> builderType;
@@ -165,14 +165,14 @@
/**
* Determine the provider implementation suitable for builderType and delegate the
creation
- * of this specific ValidatorBuilder subclass to the provider.
+ * of this specific ValidatorFactoryBuilder subclass to the provider.
*
- * @return a ValidatorBuilder sub interface implementation
+ * @return a ValidatorFactoryBuilder sub interface implementation
*/
- public T getValidatorBuilder() {
+ public T getBuilder() {
if ( builderType == null ) {
throw new ValidationException(
- "builder is mandatory. Use getValidatorBuilder() to use the generic provider
discovery mechanism"
+ "builder is mandatory. Use getBuilder() to use the generic provider discovery
mechanism"
);
}
if ( resolver == null ) {
@@ -182,7 +182,7 @@
if ( provider.isSuitable( builderType ) ) {
GenericBuilderFactoryImpl state = new GenericBuilderFactoryImpl();
state.providerResolver( resolver );
- return provider.createSpecializedValidatorBuilder( state, builderType );
+ return provider.createSpecializedValidatorFactoryBuilder( state, builderType );
}
}
throw new ValidationException( "Unable to find provider: " + builderType );
@@ -203,7 +203,7 @@
return resolver;
}
- public ValidatorBuilder<?> getValidatorBuilder() {
+ public ValidatorFactoryBuilder<?> getBuilder() {
ValidationProviderResolver resolver = this.resolver == null ?
new DefaultValidationProviderResolver() :
this.resolver;
@@ -212,7 +212,7 @@
//FIXME looks like an assertion error almost
throw new ValidationException( "Unable to find a default provider" );
}
- return resolver.getValidationProviders().get( 0 ).createGenericValidatorBuilder( this
);
+ return resolver.getValidationProviders().get( 0
).createGenericValidatorFactoryBuilder( this );
}
}
}
Copied:
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java
(from rev 15487,
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorBuilder.java)
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java
(rev 0)
+++
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -0,0 +1,86 @@
+// $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.io.InputStream;
+
+/**
+ * Receives configuration information, selects the appropriate
+ * Bean Validation provider and build the appropriate
+ * ValidatorFactory.
+ * <p/>
+ * Usage:
+ * <pre>
+ * ValidatorFactoryBuilder<?> builder = //provided by one of the Validation
bootstrap methods
+ * ValidatorFactory = builder
+ * .messageResolver( new CustomMessageResolver() )
+ * .build();
+ * </pre>
+ * <p/>
+ * The ValidationProviderResolver is specified at ValidatorFactoryBuilder time (see
{@link javax.validation.spi.ValidationProvider}).
+ * If none is explicitely requested, the default ValidationProviderResolver is used.
+ * <p/>
+ * The provider is selected in the following way:
+ * - if a specific ValidatorFactoryBuilder subclass is requested programmatically using
Validation.builderType(),
+ * find the first provider matching it
+ * - if a specific ValidatorFactoryBuilder subclass is defined in
META-INF/validation.xml,
+ * find the first provider matching it
+ * - otherwise, use the first provider returned by the ValidationProviderResolver
+ * <p/>
+ * Implementations are not meant to be thread safe
+ *
+ * @author Emmanuel Bernard
+ */
+public interface ValidatorFactoryBuilder<T extends ValidatorFactoryBuilder> {
+ /**
+ * Defines the message resolver used. Has priority over the configuration based message
resolver.
+ *
+ * @param resolver message resolver implementation.
+ *
+ * @return <code>this</code> following the chaining method pattern.
+ */
+ T messageResolver(MessageResolver resolver);
+
+ /**
+ * Defines the constraint factory. Has priority over the configuration based constraint
factory.
+ *
+ * @param constraintFactory constraint factory inmplementation.
+ *
+ * @return <code>this</code> following the chaining method pattern.
+ */
+ T constraintFactory(ConstraintFactory constraintFactory);
+
+ /**
+ * Configure the ValidatorFactory based on <code>stream</code>
+ * If not specified, META-INF/validation.xml is used
+ * <p/>
+ * The stream should be closed by the client API after the ValidatorFactory has been
returned
+ *
+ * @param stream configuration stream.
+ *
+ * @return <code>this</code> following the chaining method pattern.
+ */
+ T configure(InputStream stream);
+
+ /**
+ * Build a ValidatorFactory implementation.
+ *
+ * @return ValidatorFactory
+ */
+ ValidatorFactory build();
+}
Property changes on:
validator/trunk/validation-api/src/main/java/javax/validation/ValidatorFactoryBuilder.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Id
Modified:
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/GenericBuilderFactory.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/GenericBuilderFactory.java 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/GenericBuilderFactory.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -1,11 +1,11 @@
package javax.validation.bootstrap;
import javax.validation.ValidationProviderResolver;
-import javax.validation.ValidatorBuilder;
+import javax.validation.ValidatorFactoryBuilder;
/**
* Defines the state used to bootstrap Bean Validation and create an appropriate
- * ValidatorBuilder
+ * ValidatorFactoryBuilder
*
* @author Emmanuel Bernard
*/
@@ -23,13 +23,13 @@
GenericBuilderFactory providerResolver(ValidationProviderResolver resolver);
/**
- * Returns a generic ValidatorBuilder implementation.
+ * Returns a generic ValidatorFactoryBuilder implementation.
* At this stage the provider used to build the ValidationFactory is not defined.
* <p/>
- * The ValidatorBuilder implementation is provided by the first provider returned
+ * The ValidatorFactoryBuilder implementation is provided by the first provider
returned
* by the ValidationProviderResolver strategy.
*
- * @return a ValidatorBuilder implementation compliant with the bootstrap state
+ * @return a ValidatorFactoryBuilder implementation compliant with the bootstrap state
*/
- ValidatorBuilder<?> getValidatorBuilder();
+ ValidatorFactoryBuilder<?> getBuilder();
}
Modified:
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/SpecializedBuilderFactory.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/SpecializedBuilderFactory.java 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/validation-api/src/main/java/javax/validation/bootstrap/SpecializedBuilderFactory.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -1,10 +1,10 @@
package javax.validation.bootstrap;
import javax.validation.ValidationProviderResolver;
-import javax.validation.ValidatorBuilder;
+import javax.validation.ValidatorFactoryBuilder;
/**
- * Build implementations of builderType, the specific ValidationBuilder sub interface
uniquely identifying
+ * Build implementations of builderType, the specific ValidatorFactoryBuilder sub
interface uniquely identifying
* a provider.
* <p/>
* The requested provider is the first provider suitable for T (as defined in
@@ -14,7 +14,7 @@
*
* @author Emmanuel Bernard
*/
-public interface SpecializedBuilderFactory<T extends ValidatorBuilder<T>> {
+public interface SpecializedBuilderFactory<T extends
ValidatorFactoryBuilder<T>> {
/**
* Optionally define the provider resolver implementation used.
@@ -28,9 +28,9 @@
/**
* Determine the provider implementation suitable for builderType and delegate the
creation
- * of this specific ValidatorBuilder subclass to the provider.
+ * of this specific ValidatorFactoryBuilder subclass to the provider.
*
- * @return a ValidatorBuilder sub interface implementation
+ * @return a ValidatorFactoryBuilder sub interface implementation
*/
- public T getValidatorBuilder();
+ public T getBuilder();
}
Modified:
validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java
===================================================================
---
validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java 2008-11-04
00:14:54 UTC (rev 15491)
+++
validator/trunk/validation-api/src/main/java/javax/validation/spi/ValidationProvider.java 2008-11-04
02:26:44 UTC (rev 15492)
@@ -17,7 +17,7 @@
*/
package javax.validation.spi;
-import javax.validation.ValidatorBuilder;
+import javax.validation.ValidatorFactoryBuilder;
import javax.validation.ValidatorFactory;
/**
@@ -33,14 +33,14 @@
/**
* @param builderClass targeted builder class.
*
- * @return <code>true</code> if <code>builderClass</code> is the
Bean Validation Provider sub interface for ValidatorBuilder
+ * @return <code>true</code> if <code>builderClass</code> is the
Bean Validation Provider sub interface for ValidatorFactoryBuilder
* This sub interface uniquely identify a provider.
*/
- boolean isSuitable(Class<? extends ValidatorBuilder<?>> builderClass);
+ boolean isSuitable(Class<? extends ValidatorFactoryBuilder<?>>
builderClass);
/**
- * Returns a ValidatorBuilder instance implementing the
<code>builderType</code> interface.
- * The ValidatorBuilder instance uses the current provider
(<code>this</code>) to build
+ * Returns a ValidatorFactoryBuilder instance implementing the
<code>builderType</code> interface.
+ * The ValidatorFactoryBuilder instance uses the current provider
(<code>this</code>) to build
* the ValidatorFactory instance.
* <p/>
* This method can only be called on providers returning true on
<code>#issuitable(builderType)</code>
@@ -50,12 +50,12 @@
*
* @return specific validator builder implementation
*/
- <T extends ValidatorBuilder<T>> T
createSpecializedValidatorBuilder(BootstrapState state, Class<T> builderClass);
+ <T extends ValidatorFactoryBuilder<T>> T
createSpecializedValidatorFactoryBuilder(BootstrapState state, Class<T>
builderClass);
/**
- * Returns a ValidatorBuilder instance. This instance is not bound to
+ * Returns a ValidatorFactoryBuilder instance. This instance is not bound to
* use the current provider. The choice of provider follows the algorithm described
- * in {@link javax.validation.ValidatorBuilder}
+ * in {@link javax.validation.ValidatorFactoryBuilder}
* <p/>
* The ValidationProviderResolver used is provided by <code>state</code>.
* If null, the default ValidationProviderResolver is used.
@@ -64,7 +64,7 @@
*
* @return validator builder implementation
*/
- ValidatorBuilder<?> createGenericValidatorBuilder(BootstrapState state);
+ ValidatorFactoryBuilder<?> createGenericValidatorFactoryBuilder(BootstrapState
state);
/**
* Build a ValidatorFactory using the current provider implementation. The
ValidationFactory