You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bval.apache.org by si...@apache.org on 2010/05/13 10:52:07 UTC
svn commit: r943848 - in /incubator/bval/trunk: ./ bval-guice/
bval-guice/src/ bval-guice/src/main/ bval-guice/src/main/java/
bval-guice/src/main/java/org/ bval-guice/src/main/java/org/apache/
bval-guice/src/main/java/org/apache/bval/ bval-guice/src/ma...
Author: simonetripodi
Date: Thu May 13 08:52:06 2010
New Revision: 943848
URL: http://svn.apache.org/viewvc?rev=943848&view=rev
Log:
moved the google-guice integration module from the sandbox
Added:
incubator/bval/trunk/bval-guice/ (with props)
incubator/bval/trunk/bval-guice/pom.xml (with props)
incubator/bval/trunk/bval-guice/src/
incubator/bval/trunk/bval-guice/src/main/
incubator/bval/trunk/bval-guice/src/main/java/
incubator/bval/trunk/bval-guice/src/main/java/org/
incubator/bval/trunk/bval-guice/src/main/java/org/apache/
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java (with props)
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java (with props)
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java (with props)
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java (with props)
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java (with props)
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java (with props)
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java (with props)
incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java (with props)
incubator/bval/trunk/bval-guice/src/main/resources/
incubator/bval/trunk/bval-guice/src/test/
incubator/bval/trunk/bval-guice/src/test/java/
incubator/bval/trunk/bval-guice/src/test/java/org/
incubator/bval/trunk/bval-guice/src/test/java/org/apache/
incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/
incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/
incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java (with props)
incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java (with props)
incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java (with props)
incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java (with props)
incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java (with props)
incubator/bval/trunk/bval-guice/src/test/resources/
Modified:
incubator/bval/trunk/pom.xml
Propchange: incubator/bval/trunk/bval-guice/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu May 13 08:52:06 2010
@@ -0,0 +1 @@
+target
Added: incubator/bval/trunk/bval-guice/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/pom.xml?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/pom.xml (added)
+++ incubator/bval/trunk/bval-guice/pom.xml Thu May 13 08:52:06 2010
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!--
+ Maven release plugin requires the project tag to be on a single line.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.bval</groupId>
+ <artifactId>bval-parent</artifactId>
+ <version>0.1-incubating-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>bval-guice</artifactId>
+ <name>Apache Bean Validation :: bval-guice</name>
+ <packaging>bundle</packaging>
+
+ <description>Bean Validation - Google Guice Integration</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.bval</groupId>
+ <artifactId>bval-jsr303</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.inject</groupId>
+ <artifactId>guice</artifactId>
+ <version>2.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ <version>1.0</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <defaultGoal>install</defaultGoal>
+
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
+
+</project>
Propchange: incubator/bval/trunk/bval-guice/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: incubator/bval/trunk/bval-guice/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java Thu May 13 08:52:06 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.guice;
+
+import javax.validation.ConstraintValidatorFactory;
+import javax.validation.MessageInterpolator;
+import javax.validation.TraversableResolver;
+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;
+import com.google.inject.Singleton;
+
+/**
+ * The {@code javax.validation.spi.ConfigurationState} provider implementation.
+ *
+ * @version $Id$
+ */
+@Singleton
+public final class ConfigurationStateProvider implements Provider<ConfigurationState> {
+
+ private final ConfigurationImpl configurationState;
+
+ @Inject
+ public ConfigurationStateProvider(ValidationProvider<?> aProvider) {
+ this.configurationState = new ConfigurationImpl(null, 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/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ConfigurationStateProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java Thu May 13 08:52:06 2010
@@ -0,0 +1,49 @@
+/*
+ * 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.guice;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+import com.google.inject.Singleton;
+
+/**
+ * {@code javax.validation.ConstraintValidatorFactory} implementation that
+ * relies on Google Guice.
+ *
+ * @version $Id$
+ */
+@Singleton
+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/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/GuiceAwareConstraintValidatorFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java Thu May 13 08:52:06 2010
@@ -0,0 +1,50 @@
+/*
+ * 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.guice;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import com.google.inject.BindingAnnotation;
+
+/**
+ * Marker for methods which arguments have to be validated.
+ *
+ * @version $Id$
+ */
+@BindingAnnotation
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ ElementType.METHOD })
+public @interface Validate {
+
+ /**
+ * TODO fill me
+ *
+ * @return
+ */
+ Class<?>[] groups() default {};
+
+ /**
+ * TODO fill me
+ *
+ * @return
+ */
+ boolean validateReturnedValue() default false;
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/Validate.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java Thu May 13 08:52:06 2010
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2010 The gmodules Team
+ *
+ * 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.apache.bval.guice;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Validator;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+import org.apache.bval.jsr303.extensions.MethodValidator;
+
+import com.google.inject.Inject;
+
+/**
+ * Method interceptor for {@link Validate} annotation.
+ *
+ * @version $Id$
+ */
+public final class ValidateMethodInterceptor implements MethodInterceptor {
+
+ /**
+ * The Validator reference.
+ */
+ @Inject
+ private Validator validator;
+
+ /**
+ * Sets the Validator reference.
+ *
+ * @param validator the Validator reference.
+ */
+ public void setValidator(Validator validator) {
+ this.validator = validator;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object invoke(MethodInvocation invocation) throws Throwable {
+ Validate validate = invocation.getMethod().getAnnotation(Validate.class);
+ MethodValidator methodValidator = this.validator.unwrap(MethodValidator.class);
+
+ Set<ConstraintViolation<?>> constraintViolations = new HashSet<ConstraintViolation<?>>();
+ Class<?> clazz = invocation.getMethod().getDeclaringClass();
+ Method method = invocation.getMethod();
+ Object[] arguments = invocation.getArguments();
+ Class<?>[] groups = validate.groups();
+
+ constraintViolations.addAll(methodValidator.validateParameters(clazz,
+ method,
+ arguments,
+ groups));
+
+ if (!constraintViolations.isEmpty()) {
+ throw new ConstraintViolationException("Validation error when calling method '"
+ + method
+ + "' with arguments "
+ + Arrays.deepToString(arguments), constraintViolations);
+ }
+
+ Object returnedValue = invocation.proceed();
+
+ if (validate.validateReturnedValue()) {
+ constraintViolations.addAll(methodValidator.validateReturnedValue(clazz, method, returnedValue, groups));
+ if (!constraintViolations.isEmpty()) {
+ throw new ConstraintViolationException("Method '"
+ + method
+ + "' returned a not valid value "
+ + returnedValue, constraintViolations);
+ }
+ }
+
+ return returnedValue;
+ }
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidateMethodInterceptor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java Thu May 13 08:52:06 2010
@@ -0,0 +1,64 @@
+/*
+ * 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.guice;
+
+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 javax.validation.spi.ValidationProvider;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.apache.bval.jsr303.ApacheValidationProvider;
+import org.apache.bval.jsr303.DefaultMessageInterpolator;
+import org.apache.bval.jsr303.resolver.DefaultTraversableResolver;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Scopes;
+import com.google.inject.TypeLiteral;
+import com.google.inject.matcher.Matchers;
+
+/**
+ * The Google-Guice module for Apache Bean Validation.
+ *
+ * @version $Id$
+ */
+public final class ValidationModule extends AbstractModule {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void configure() {
+ // apache bval bootstrap
+ this.bind(MessageInterpolator.class).to(DefaultMessageInterpolator.class).in(Scopes.SINGLETON);
+ this.bind(TraversableResolver.class).to(DefaultTraversableResolver.class).in(Scopes.SINGLETON);
+ this.bind(ConstraintValidatorFactory.class).to(GuiceAwareConstraintValidatorFactory.class);
+ this.bind(new TypeLiteral<ValidationProvider<?>>() {}).to(ApacheValidationProvider.class).in(Scopes.SINGLETON);
+ this.bind(ConfigurationState.class).toProvider(ConfigurationStateProvider.class);
+ this.bind(ValidatorFactory.class).toProvider(ValidatorFactoryProvider.class);
+ this.bind(Validator.class).toProvider(ValidatorProvider.class);
+
+ // AOP stuff
+ MethodInterceptor validateMethodInterceptor = new ValidateMethodInterceptor();
+ this.binder().requestInjection(validateMethodInterceptor);
+ this.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Validate.class), validateMethodInterceptor);
+ }
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidationModule.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java Thu May 13 08:52:06 2010
@@ -0,0 +1,51 @@
+/*
+ * 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.guice;
+
+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;
+import com.google.inject.Singleton;
+
+/**
+ * Validator Factory guice provider implementation.
+ *
+ * @version $Id$
+ */
+@Singleton
+public final class ValidatorFactoryProvider implements Provider<ValidatorFactory> {
+
+ private final ApacheValidatorFactory validatorFactory;
+
+ @Inject
+ public ValidatorFactoryProvider(ConfigurationState configurationState) {
+ this.validatorFactory = new ApacheValidatorFactory();
+ this.validatorFactory.configure(configurationState);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ValidatorFactory get() {
+ return this.validatorFactory;
+ }
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorFactoryProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java Thu May 13 08:52:06 2010
@@ -0,0 +1,56 @@
+/*
+ * 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.guice;
+
+import javax.validation.Validator;
+import javax.validation.ValidatorFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Provider;
+import com.google.inject.Singleton;
+
+/**
+ * Validator guice provider implementation.
+ *
+ * @version $Id$
+ */
+@Singleton
+public final class ValidatorProvider implements Provider<Validator> {
+
+ /**
+ * The validator reference.
+ */
+ private final Validator validator;
+
+ /**
+ * Build a new ValidatorProvider by ValidatorFactory.
+ *
+ * @param validatorFactory the ValidatorFactory reference.
+ */
+ @Inject
+ public ValidatorProvider(ValidatorFactory validatorFactory) {
+ this.validator = validatorFactory.getValidator();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Validator get() {
+ return this.validator;
+ }
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/ValidatorProvider.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java (added)
+++ incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java Thu May 13 08:52:06 2010
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+/**
+ * Contains Apache Bean Validation support for Google-Guice.
+ *
+ * @version $Id$
+ */
+package org.apache.bval.guice;
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/main/java/org/apache/bval/guice/package-info.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java (added)
+++ incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java Thu May 13 08:52:06 2010
@@ -0,0 +1,77 @@
+/*
+ * 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.guice;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+public class Country {
+
+ @NotNull(groups = { Update.class })
+ private Long id;
+
+ @NotNull(groups = { Insert.class })
+ private String name;
+
+ @NotNull(groups = { Insert.class })
+ @Size(max = 2, groups = { Insert.class, Update.class })
+ private String iso2Code;
+
+ @NotNull(groups = { Insert.class })
+ @Size(max = 3, groups = { Insert.class, Update.class })
+ private String iso3Code;
+
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getIso2Code() {
+ return iso2Code;
+ }
+
+ public void setIso2Code(String iso2Code) {
+ this.iso2Code = iso2Code;
+ }
+
+ public String getIso3Code() {
+ return iso3Code;
+ }
+
+ public void setIso3Code(String iso3Code) {
+ this.iso3Code = iso3Code;
+ }
+
+}
\ No newline at end of file
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Country.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java (added)
+++ incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java Thu May 13 08:52:06 2010
@@ -0,0 +1,46 @@
+/*
+ * 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.guice;
+
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import com.google.inject.Singleton;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+@Singleton
+public class DummyCountryDao {
+
+ @Validate(
+ groups = { Insert.class },
+ validateReturnedValue = true
+ )
+ public Country insertCountry(@NotNull(groups = { Insert.class }) String name,
+ @NotNull(groups = { Insert.class }) @Size(max = 2, groups = { Insert.class, Update.class }) String iso2Code,
+ @NotNull(groups = { Insert.class }) @Size(max = 3, groups = { Insert.class, Update.class }) String iso3Code) {
+ Country country = new Country();
+ country.setName(name);
+ country.setIso2Code(iso2Code);
+ country.setIso3Code(iso3Code);
+ return country;
+ }
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/DummyCountryDao.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java (added)
+++ incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java Thu May 13 08:52:06 2010
@@ -0,0 +1,81 @@
+/*
+ * 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.guice;
+
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Validator;
+
+import junit.framework.TestCase;
+
+import com.google.inject.Guice;
+import com.google.inject.Inject;
+import com.google.inject.Injector;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+public final class GuiceAwareValidationTestCase extends TestCase {
+
+ @Inject
+ private Validator validator;
+
+ @Inject
+ private DummyCountryDao dummyCountryDao;
+
+ public void setValidator(Validator validator) {
+ this.validator = validator;
+ }
+
+ public void setDummyCountryDao(DummyCountryDao dummyCountryDao) {
+ this.dummyCountryDao = dummyCountryDao;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ Injector injector = Guice.createInjector(new ValidationModule());
+ injector.injectMembers(this);
+ }
+
+ public void testInjectedValidation() {
+ Country country = new Country();
+ country.setName("Italy");
+ country.setIso2Code("it");
+ country.setIso3Code("ita");
+
+ Set<ConstraintViolation<Country>> violations = this.validator.validate(country);
+ assertTrue(violations.isEmpty());
+ }
+
+ public void testAOPInjectedValidation() {
+ this.dummyCountryDao.insertCountry("Italy", "it", "ita");
+ }
+
+ public void testAOPInjectedFailedValidation() {
+ try {
+ this.dummyCountryDao.insertCountry("Italy", "ita", "ita");
+ fail("javax.validation.ConstraintViolationException expected");
+ } catch (ConstraintViolationException cve) {
+ // do nothing
+ }
+ }
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/GuiceAwareValidationTestCase.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java (added)
+++ incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java Thu May 13 08:52:06 2010
@@ -0,0 +1,28 @@
+/*
+ * 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.guice;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+public interface Insert {
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Insert.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java?rev=943848&view=auto
==============================================================================
--- incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java (added)
+++ incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java Thu May 13 08:52:06 2010
@@ -0,0 +1,28 @@
+/*
+ * 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.guice;
+
+/**
+ *
+ *
+ * @version $Id$
+ */
+public interface Update {
+
+}
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/trunk/bval-guice/src/test/java/org/apache/bval/guice/Update.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: incubator/bval/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/trunk/pom.xml?rev=943848&r1=943847&r2=943848&view=diff
==============================================================================
--- incubator/bval/trunk/pom.xml (original)
+++ incubator/bval/trunk/pom.xml Thu May 13 08:52:06 2010
@@ -509,6 +509,7 @@
<module>bval-core</module>
<module>bval-jsr303</module>
<module>bval-json</module>
+ <module>bval-guice</module>
<!-- <module>bval-tck</module> -->
</modules>