[jboss-cvs] JBossAS SVN: r92049 - projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 6 00:30:52 EDT 2009
Author: jeff.zhang
Date: 2009-08-06 00:30:52 -0400 (Thu, 06 Aug 2009)
New Revision: 92049
Added:
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JCATraversableResolver.java
Modified:
projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/BeanValidation.java
Log:
[JBJCA-139] add BeanValidation JCATraversableResolver
Modified: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/BeanValidation.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/BeanValidation.java 2009-08-06 04:27:22 UTC (rev 92048)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/BeanValidation.java 2009-08-06 04:30:52 UTC (rev 92049)
@@ -23,6 +23,7 @@
import java.util.Set;
+import javax.validation.Configuration;
import javax.validation.ConstraintViolationException;
import javax.validation.Validation;
import javax.validation.Validator;
@@ -57,7 +58,9 @@
throw new IllegalArgumentException("Object is null");
}
- ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
+ Configuration configuration = Validation.byDefaultProvider().configure();
+ Configuration<?> conf = configuration.traversableResolver(new JCATraversableResolver());
+ ValidatorFactory vf = conf.buildValidatorFactory();
Validator v = vf.getValidator();
if (trace)
@@ -69,7 +72,7 @@
Set errors = v.validate(object, Default.class);
if (errors != null && errors.size() > 0)
{
- log.info("Validated: " + errors.size() + " validate failing");
+ log.debug("Validated: " + errors.size() + " validate failing");
throw new ConstraintViolationException(errors);
}
}
Added: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JCATraversableResolver.java
===================================================================
--- projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JCATraversableResolver.java (rev 0)
+++ projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JCATraversableResolver.java 2009-08-06 04:30:52 UTC (rev 92049)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.sjc.deployers.ra;
+
+import java.lang.annotation.ElementType;
+
+import javax.validation.Path;
+import javax.validation.TraversableResolver;
+
+/**
+ * JCATraversableResolver
+ * @author <a href="mailto:jeff.zhang at jboss.org">Jeff Zhang</a>
+ * @version $Revision: $
+ */
+public class JCATraversableResolver implements TraversableResolver
+{
+ /**
+ * Determine if Bean Validation is allowed to reach the property state
+ *
+ * @param traversableObject
+ * object hosting <code>traversableProperty</code> or null if
+ * validateValue is called
+ * @param traversableProperty
+ * the traversable property.
+ * @param rootBeanType
+ * type of the root object passed to the Validator.
+ * @param pathToTraversableObject
+ * path from the root object to <code>traversableObject</code>
+ * (using the path specification defined by Bean Validator).
+ * @param elementType
+ * either <code>FIELD</code> or <code>METHOD</code>.
+ *
+ * @return <code>true</code> if Bean Validation is allowed to reach the
+ * property state, <code>false</code> otherwise.
+ */
+ public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
+ Class<?> rootBeanType, Path pathToTraversableObject,
+ ElementType elementType)
+ {
+ return true;
+ }
+
+ /**
+ * Determine if Bean Validation is allowed to cascade validation on the bean
+ * instance returned by the property value marked as <code>@Valid</code>.
+ * Note that this method is called only if isReachable returns true for the
+ * same set of arguments and if the property is marked as <code>@Valid</code>
+ *
+ * @param traversableObject
+ * object hosting <code>traversableProperty</code> or null if
+ * validateValue is called
+ * @param traversableProperty
+ * the traversable property.
+ * @param rootBeanType
+ * type of the root object passed to the Validator.
+ * @param pathToTraversableObject
+ * path from the root object to <code>traversableObject</code>
+ * (using the path specification defined by Bean Validator).
+ * @param elementType
+ * either <code>FIELD</code> or <code>METHOD</code>.
+ *
+ * @return <code>true</code> if Bean Validation is allowed to cascade
+ * validation, <code>false</code> otherwise.
+ */
+ public boolean isCascadable(Object traversableObject,
+ Path.Node traversableProperty, Class<?> rootBeanType,
+ Path pathToTraversableObject, ElementType elementType)
+ {
+ return true;
+ }
+}
Property changes on: projects/jboss-jca/trunk/sjc/src/main/java/org/jboss/jca/sjc/deployers/ra/JCATraversableResolver.java
___________________________________________________________________
Name: svn:keywords
+ Id Reversion Date
More information about the jboss-cvs-commits
mailing list