incubator-bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r930232 - /incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/
Date Fri, 02 Apr 2010 10:49:10 GMT
Author: simonetripodi
Date: Fri Apr  2 10:49:09 2010
New Revision: 930232

URL: http://svn.apache.org/viewvc?rev=930232&view=rev
Log:
refactoring the guice aware bootstrap binding directly bval-jsr303 module. still incomplete.

Added:
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java
  (with props)
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java
  (with props)
Removed:
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ByGenericBootstrapConfigurationProvider.java
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/BySpecificBootstrapConfigurationProvider.java
Modified:
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidatorFactoryProvider.java
    incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/package-info.java

Added: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java?rev=930232&view=auto
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java
(added)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java
Fri Apr  2 10:49:09 2010
@@ -0,0 +1,51 @@
+package org.apache.bval.extentions.guice;
+
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+import javax.validation.spi.BootstrapState;
+import javax.validation.spi.ConfigurationState;
+import javax.validation.spi.ValidationProvider;
+
+import org.apache.bval.jsr303.ConfigurationImpl;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+
+/**
+ * The {@code javax.validation.spi.ConfigurationState} provider implementation.
+ *
+ * @version $Id$
+ */
+public final class ConfigurationStateProvider implements Provider<ConfigurationState>
{
+
+    private final ConfigurationImpl configurationState;
+
+    @Inject
+    public ConfigurationStateProvider(BootstrapState aState, ValidationProvider<?>
aProvider) {
+        this.configurationState = new ConfigurationImpl(aState, aProvider);
+    }
+
+    @Inject
+    public void traversableResolver(TraversableResolver traversableResolver) {
+        this.configurationState.traversableResolver(traversableResolver);
+    }
+
+    @Inject
+    public void messageInterpolator(MessageInterpolator messageInterpolator) {
+        this.configurationState.messageInterpolator(messageInterpolator);
+    }
+
+    @Inject
+    public void constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
{
+        this.configurationState.constraintValidatorFactory(constraintValidatorFactory);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ConfigurationState get() {
+        return this.configurationState;
+    }
+
+}

Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ConfigurationStateProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java?rev=930232&view=auto
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java
(added)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java
Fri Apr  2 10:49:09 2010
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.bval.extentions.guice;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+/**
+ * {@code javax.validation.ConstraintValidatorFactory} implementation that
+ * relies on Google Guice.
+ *
+ * @version $Id$
+ */
+final class GuiceAwareConstraintValidatorFactory implements ConstraintValidatorFactory {
+
+    private final Injector injector;
+
+    @Inject
+    public GuiceAwareConstraintValidatorFactory(Injector injector) {
+        this.injector = injector;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public <T extends ConstraintValidator<?, ?>> T getInstance(Class<T>
key) {
+        return this.injector.getInstance(key);
+    }
+
+}

Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/GuiceAwareConstraintValidatorFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java?rev=930232&r1=930231&r2=930232&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
(original)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidationModule.java
Fri Apr  2 10:49:09 2010
@@ -16,17 +16,53 @@
  */
 package org.apache.bval.extentions.guice;
 
-import javax.validation.Configuration;
 import javax.validation.ConstraintValidatorFactory;
 import javax.validation.MessageInterpolator;
 import javax.validation.TraversableResolver;
-import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
+import javax.validation.spi.ConfigurationState;
+
+import org.apache.bval.constraints.AssertFalseValidator;
+import org.apache.bval.constraints.AssertTrueValidator;
+import org.apache.bval.constraints.DecimalMaxValidatorForNumber;
+import org.apache.bval.constraints.DecimalMaxValidatorForString;
+import org.apache.bval.constraints.DecimalMinValidatorForNumber;
+import org.apache.bval.constraints.DecimalMinValidatorForString;
+import org.apache.bval.constraints.DigitsValidatorForNumber;
+import org.apache.bval.constraints.DigitsValidatorForString;
+import org.apache.bval.constraints.EmailValidator;
+import org.apache.bval.constraints.FutureValidatorForCalendar;
+import org.apache.bval.constraints.FutureValidatorForDate;
+import org.apache.bval.constraints.MaxValidatorForNumber;
+import org.apache.bval.constraints.MaxValidatorForString;
+import org.apache.bval.constraints.MinValidatorForNumber;
+import org.apache.bval.constraints.MinValidatorForString;
+import org.apache.bval.constraints.NotEmptyValidator;
+import org.apache.bval.constraints.NotEmptyValidatorForCollection;
+import org.apache.bval.constraints.NotEmptyValidatorForMap;
+import org.apache.bval.constraints.NotEmptyValidatorForString;
+import org.apache.bval.constraints.NotNullValidator;
+import org.apache.bval.constraints.NullValidator;
+import org.apache.bval.constraints.PastValidatorForCalendar;
+import org.apache.bval.constraints.PastValidatorForDate;
+import org.apache.bval.constraints.PatternValidator;
+import org.apache.bval.constraints.SizeValidator;
+import org.apache.bval.constraints.SizeValidatorForArrayOfBoolean;
+import org.apache.bval.constraints.SizeValidatorForArrayOfByte;
+import org.apache.bval.constraints.SizeValidatorForArrayOfChar;
+import org.apache.bval.constraints.SizeValidatorForArrayOfDouble;
+import org.apache.bval.constraints.SizeValidatorForArrayOfFloat;
+import org.apache.bval.constraints.SizeValidatorForArrayOfInt;
+import org.apache.bval.constraints.SizeValidatorForArrayOfLong;
+import org.apache.bval.constraints.SizeValidatorForArrayOfObject;
+import org.apache.bval.constraints.SizeValidatorForArrayOfShort;
+import org.apache.bval.constraints.SizeValidatorForCollection;
+import org.apache.bval.constraints.SizeValidatorForMap;
+import org.apache.bval.constraints.SizeValidatorForString;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.resolver.DefaultTraversableResolver;
 
 import com.google.inject.AbstractModule;
-import com.google.inject.Provider;
-import com.google.inject.TypeLiteral;
-import com.google.inject.matcher.Matchers;
 
 /**
  * The Google-Guice module for Apache Bean Validation.
@@ -36,89 +72,55 @@ import com.google.inject.matcher.Matcher
 public final class ValidationModule extends AbstractModule {
 
     /**
-     * 
-     */
-    private final Class<? extends Provider<Configuration<?>>> configurationProviderType;
-
-    /**
-     * 
-     */
-    private Class<? extends Provider<? extends MessageInterpolator>> messageInterpolatorProviderType;
-
-    /**
-     * 
-     */
-    private Class<? extends Provider<? extends TraversableResolver>> traversableResolverProviderType;
-
-    /**
-     * 
-     */
-    private Class<? extends Provider<? extends ConstraintValidatorFactory>> constraintValidatorFactoryProviderType;
-
-    /**
-     * 
-     */
-    public ValidationModule() {
-        this(ByGenericBootstrapConfigurationProvider.class);
-    }
-
-    /**
-     * 
-     *
-     * @param configurationProviderType
-     */
-    public ValidationModule(Class<? extends Provider<Configuration<?>>>
configurationProviderType) {
-        this.configurationProviderType = configurationProviderType;
-    }
-
-    /**
-     * 
-     *
-     * @param messageInterpolatorProviderType
-     */
-    public void setMessageInterpolatorProviderType(Class<? extends Provider<? extends
MessageInterpolator>> messageInterpolatorProviderType) {
-        this.messageInterpolatorProviderType = messageInterpolatorProviderType;
-    }
-
-    /**
-     * 
-     *
-     * @param traversableResolverProviderType
-     */
-    public void setTraversableResolverProviderType(Class<? extends Provider<? extends
TraversableResolver>> traversableResolverProviderType) {
-        this.traversableResolverProviderType = traversableResolverProviderType;
-    }
-
-    /**
-     * 
-     *
-     * @param constraintValidatorFactoryProviderType
-     */
-    public void setConstraintValidatorFactoryProviderType(Class<? extends Provider<?
extends ConstraintValidatorFactory>> constraintValidatorFactoryProviderType) {
-        this.constraintValidatorFactoryProviderType = constraintValidatorFactoryProviderType;
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
     protected void configure() {
-        this.bind(new TypeLiteral<Configuration<?>>(){}).toProvider(this.configurationProviderType).asEagerSingleton();
-
-        if (this.messageInterpolatorProviderType != null) {
-            this.bind(MessageInterpolator.class).toProvider(this.messageInterpolatorProviderType).asEagerSingleton();
-        }
-        if (this.traversableResolverProviderType != null) {
-            this.bind(TraversableResolver.class).toProvider(this.traversableResolverProviderType).asEagerSingleton();
-        }
-        if (this.constraintValidatorFactoryProviderType != null) {
-            this.bind(ConstraintValidatorFactory.class).toProvider(this.constraintValidatorFactoryProviderType).asEagerSingleton();
-        }
-
+        // constraints
+        this.bind(AssertFalseValidator.class).asEagerSingleton();
+        this.bind(AssertTrueValidator.class).asEagerSingleton();
+        this.bind(DecimalMaxValidatorForNumber.class).asEagerSingleton();
+        this.bind(DecimalMaxValidatorForString.class).asEagerSingleton();
+        this.bind(DecimalMinValidatorForNumber.class).asEagerSingleton();
+        this.bind(DecimalMinValidatorForString.class).asEagerSingleton();
+        this.bind(DigitsValidatorForNumber.class).asEagerSingleton();
+        this.bind(DigitsValidatorForString.class).asEagerSingleton();
+        this.bind(EmailValidator.class).asEagerSingleton();
+        this.bind(FutureValidatorForCalendar.class).asEagerSingleton();
+        this.bind(FutureValidatorForDate.class).asEagerSingleton();
+        this.bind(MaxValidatorForNumber.class).asEagerSingleton();
+        this.bind(MaxValidatorForString.class).asEagerSingleton();
+        this.bind(MinValidatorForNumber.class).asEagerSingleton();
+        this.bind(MinValidatorForString.class).asEagerSingleton();
+        this.bind(NotEmptyValidator.class).asEagerSingleton();
+        this.bind(NotEmptyValidatorForCollection.class).asEagerSingleton();
+        this.bind(NotEmptyValidatorForMap.class).asEagerSingleton();
+        this.bind(NotEmptyValidatorForString.class).asEagerSingleton();
+        this.bind(NotNullValidator.class).asEagerSingleton();
+        this.bind(NullValidator.class).asEagerSingleton();
+        this.bind(PastValidatorForCalendar.class).asEagerSingleton();
+        this.bind(PastValidatorForDate.class).asEagerSingleton();
+        this.bind(PatternValidator.class).asEagerSingleton();
+        this.bind(SizeValidator.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfBoolean.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfByte.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfChar.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfDouble.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfFloat.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfInt.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfLong.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfObject.class).asEagerSingleton();
+        this.bind(SizeValidatorForArrayOfShort.class).asEagerSingleton();
+        this.bind(SizeValidatorForCollection.class).asEagerSingleton();
+        this.bind(SizeValidatorForMap.class).asEagerSingleton();
+        this.bind(SizeValidatorForString.class).asEagerSingleton();
+
+        // bootstrap
+        this.bind(MessageInterpolator.class).to(DefaultMessageInterpolator.class).asEagerSingleton();
+        this.bind(TraversableResolver.class).to(DefaultTraversableResolver.class).asEagerSingleton();
+        this.bind(ConstraintValidatorFactory.class).to(GuiceAwareConstraintValidatorFactory.class).asEagerSingleton();
+        this.bind(ConfigurationState.class).toProvider(ConfigurationStateProvider.class).asEagerSingleton();
         this.bind(ValidatorFactory.class).toProvider(ValidatorFactoryProvider.class).asEagerSingleton();
-        this.bind(Validator.class).toProvider(ValidatorProvider.class).asEagerSingleton();
-
-        this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Validate.class), new
ValidateMethodInterceptor());
     }
 
 }

Modified: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidatorFactoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidatorFactoryProvider.java?rev=930232&r1=930231&r2=930232&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidatorFactoryProvider.java
(original)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidatorFactoryProvider.java
Fri Apr  2 10:49:09 2010
@@ -16,11 +16,10 @@
  */
 package org.apache.bval.extentions.guice;
 
-import javax.validation.Configuration;
-import javax.validation.ConstraintValidatorFactory;
-import javax.validation.MessageInterpolator;
-import javax.validation.TraversableResolver;
 import javax.validation.ValidatorFactory;
+import javax.validation.spi.ConfigurationState;
+
+import org.apache.bval.jsr303.ApacheValidatorFactory;
 
 import com.google.inject.Inject;
 import com.google.inject.Provider;
@@ -28,35 +27,23 @@ import com.google.inject.Provider;
 /**
  * Validator Factory guice provider implementation.
  *
- * @author Simone Tripodi
  * @version $Id$
  */
 public final class ValidatorFactoryProvider implements Provider<ValidatorFactory> {
 
-    private final Configuration<?> configuration;
+    private final ApacheValidatorFactory validatorFactory;
 
     @Inject
-    public ValidatorFactoryProvider(Configuration<?> configuration) {
-        this.configuration = configuration;
-    }
-
-    @Inject(optional = true)
-    public void setMessageInterpolator(MessageInterpolator messageInterpolator) {
-        this.configuration.messageInterpolator(messageInterpolator);
-    }
-
-    @Inject(optional = true)
-    public void setTraversableResolver(TraversableResolver traversableResolver) {
-        this.configuration.traversableResolver(traversableResolver);
-    }
-
-    @Inject(optional = true)
-    public void setConstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
{
-        this.configuration.constraintValidatorFactory(constraintValidatorFactory);
+    public ValidatorFactoryProvider(ConfigurationState configurationState) {
+        this.validatorFactory = new ApacheValidatorFactory();
+        this.validatorFactory.configure(configurationState);
     }
 
+    /**
+     * {@inheritDoc}
+     */
     public ValidatorFactory get() {
-        return this.configuration.buildValidatorFactory();
+        return this.validatorFactory;
     }
 
 }

Modified: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/package-info.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/package-info.java?rev=930232&r1=930231&r2=930232&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/package-info.java
(original)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/package-info.java
Fri Apr  2 10:49:09 2010
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-
 /**
  * Contains Apache Bean Validation support for Google-Guice.
  *



Mime
View raw message