Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEAMVALIDATE-17: Making ValidationInterceptor serializable #13

Merged
merged 1 commit into from
May 28, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package org.jboss.seam.validation;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Set;
Expand All @@ -33,13 +34,37 @@
import org.hibernate.validator.method.MethodConstraintViolationException;
import org.hibernate.validator.method.MethodValidator;

/**
* An interceptor which performs a validation of the Bean Validation constraints specified at the parameters and/or return
* values of intercepted methods using the method validation functionality provided by Hibernate Validator.
*
*
* @author Gunnar Morling
*/
@AutoValidating
@Interceptor
public class ValidationInterceptor {
public class ValidationInterceptor implements Serializable {

private static final long serialVersionUID = 604440259030722151L;

/**
* The validator to be used for method validation.
*
* Although the concrete validator is not necessarily serializable (and HV's implementation indeed isn't) it is still
* alright to have it as non-transient field here. Upon passivation not the validator itself will be serialized, but the
* proxy injected here, which in turn is serializable.
*/
@Inject
private Validator validator;

/**
* Validates the Bean Validation constraints specified at the parameters and/or return value of the intercepted method.
*
* @param ctx The context of the intercepted method invocation.
* @return The result of the method invocation.
* @throws Exception Any exception caused by the intercepted method invocation. A {@link MethodConstraintViolationException}
* in case at least one constraint violation occurred either during parameter or return value validation.
*/
@AroundInvoke
public Object validateMethodInvocation(InvocationContext ctx) throws Exception {

Expand Down