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/03/20 22:53:02 UTC
svn commit: r925691 - in /incubator/bval/sandbox/guice-integration: pom.xml
src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
Author: simonetripodi
Date: Sat Mar 20 21:53:02 2010
New Revision: 925691
URL: http://svn.apache.org/viewvc?rev=925691&view=rev
Log:
first checkin of ValidateMethodInterceptor class
Added:
incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java (with props)
Modified:
incubator/bval/sandbox/guice-integration/pom.xml
Modified: incubator/bval/sandbox/guice-integration/pom.xml
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/pom.xml?rev=925691&r1=925690&r2=925691&view=diff
==============================================================================
--- incubator/bval/sandbox/guice-integration/pom.xml (original)
+++ incubator/bval/sandbox/guice-integration/pom.xml Sat Mar 20 21:53:02 2010
@@ -46,6 +46,13 @@
<version>2.0</version>
<scope>compile</scope>
</dependency>
+
+ <dependency>
+ <groupId>aopalliance</groupId>
+ <artifactId>aopalliance</artifactId>
+ <version>1.0</version>
+ <scope>compile</scope>
+ </dependency>
</dependencies>
<build>
Added: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java?rev=925691&view=auto
==============================================================================
--- incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java (added)
+++ incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java Sat Mar 20 21:53:02 2010
@@ -0,0 +1,68 @@
+/*
+ * 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.extentions.guice;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
+
+import com.google.inject.Inject;
+
+/**
+ * Method interceptor for {@link Validate} annotation.
+ *
+ * @version $Id$
+ */
+public final class ValidateMethodInterceptor implements MethodInterceptor {
+
+ /**
+ * The Validator reference.
+ */
+ private final Validator validator;
+
+ /**
+ * Creates a new Valitation Inerceptor given a Validator reference.
+ *
+ * @param validator
+ */
+ @Inject
+ public ValidateMethodInterceptor(Validator validator) {
+ this.validator = validator;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object invoke(MethodInvocation invocation) throws Throwable {
+ Set<ConstraintViolation<Object>> constraintViolations = new HashSet<ConstraintViolation<Object>>();
+
+ for (Object arg : invocation.getArguments()) {
+ constraintViolations.addAll(this.validator.validate(arg));
+ }
+
+ if (!constraintViolations.isEmpty()) {
+ throw new ValidationException(constraintViolations);
+ }
+
+ return invocation.proceed();
+ }
+
+}
Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: incubator/bval/sandbox/guice-integration/src/main/java/org/apache/bval/extentions/guice/ValidateMethodInterceptor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain