geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1392563 - /geronimo/server/branches/3.0/plugins/bval/geronimo-bval/src/main/java/org/apache/geronimo/bval/DefaultValidatorReference.java
Date Mon, 01 Oct 2012 20:08:10 GMT
Author: gawor
Date: Mon Oct  1 20:08:09 2012
New Revision: 1392563

URL: http://svn.apache.org/viewvc?rev=1392563&view=rev
Log:
GERONIMO-6393: Reuse ValidatorContext to avoid annotation scanning on each Validator lookup

Modified:
    geronimo/server/branches/3.0/plugins/bval/geronimo-bval/src/main/java/org/apache/geronimo/bval/DefaultValidatorReference.java

Modified: geronimo/server/branches/3.0/plugins/bval/geronimo-bval/src/main/java/org/apache/geronimo/bval/DefaultValidatorReference.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/plugins/bval/geronimo-bval/src/main/java/org/apache/geronimo/bval/DefaultValidatorReference.java?rev=1392563&r1=1392562&r2=1392563&view=diff
==============================================================================
--- geronimo/server/branches/3.0/plugins/bval/geronimo-bval/src/main/java/org/apache/geronimo/bval/DefaultValidatorReference.java
(original)
+++ geronimo/server/branches/3.0/plugins/bval/geronimo-bval/src/main/java/org/apache/geronimo/bval/DefaultValidatorReference.java
Mon Oct  1 20:08:09 2012
@@ -17,13 +17,14 @@
  * under the License.
  */
 
-
 package org.apache.geronimo.bval;
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.validation.Validation;
 import javax.validation.ValidationException;
+import javax.validation.Validator;
+import javax.validation.ValidatorContext;
 import javax.validation.ValidatorFactory;
 
 import org.apache.xbean.naming.reference.SimpleReference;
@@ -32,20 +33,27 @@ import org.apache.xbean.naming.reference
  * @version $Rev$ $Date$
  */
 public class DefaultValidatorReference extends SimpleReference {
+    
+    private transient ValidatorContext validatorContext;
+    
     @Override
     public Object getContent() throws NamingException {
-        ValidatorFactory factory = null;
-        
-        try {
+        if (validatorContext == null) {
             try {
-                factory = (ValidatorFactory)new InitialContext().lookup("java:comp/ValidatorFactory");
-            } catch(NamingException e) {
-                factory = Validation.buildDefaultValidatorFactory();
+                ValidatorFactory factory = getValidatorFactory();
+                validatorContext = factory.usingContext();
+            } catch (ValidationException v) {
+                throw (NamingException)new NamingException("Could not create Validator instance").initCause(v);
             }
-            return factory.getValidator();
-        } catch (ValidationException v) {
-            throw (NamingException)new NamingException("Could not create Validator instance").initCause(v);
         }
-        
+        return validatorContext.getValidator();        
+    }
+    
+    private ValidatorFactory getValidatorFactory() {
+        try {
+            return (ValidatorFactory)new InitialContext().lookup("java:comp/ValidatorFactory");
+        } catch(NamingException e) {
+            return Validation.buildDefaultValidatorFactory();
+        }
     }
-}
\ No newline at end of file
+}



Mime
View raw message