bval-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1631103 - in /bval/branches/bval-11/bval-jsr: pom.xml src/main/java/org/apache/bval/cdi/BValExtension.java src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java src/main/resources/META-INF/beans.xml
Date Sat, 11 Oct 2014 19:31:35 GMT
Author: rmannibucau
Date: Sat Oct 11 19:31:34 2014
New Revision: 1631103

URL: http://svn.apache.org/r1631103
Log:
using CDI 1.1 since we are not compatible with CDI 1.0 ATM. We could rework it later but in
all case this update ensure we don't leak with redeploy which was the case before

Removed:
    bval/branches/bval-11/bval-jsr/src/main/resources/META-INF/beans.xml
Modified:
    bval/branches/bval-11/bval-jsr/pom.xml
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java
    bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java

Modified: bval/branches/bval-11/bval-jsr/pom.xml
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/pom.xml?rev=1631103&r1=1631102&r2=1631103&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/pom.xml (original)
+++ bval/branches/bval-11/bval-jsr/pom.xml Sat Oct 11 19:31:34 2014
@@ -185,8 +185,8 @@
         </dependency>
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
-            <artifactId>geronimo-jcdi_1.0_spec</artifactId>
-            <version>1.0</version>
+            <artifactId>geronimo-jcdi_1.1_spec</artifactId>
+            <version>1.0-alpha-1</version>
             <scope>provided</scope>
             <optional>true</optional>
         </dependency>

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java?rev=1631103&r1=1631102&r2=1631103&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java (original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/cdi/BValExtension.java Sat
Oct 11 19:31:34 2014
@@ -21,19 +21,16 @@ package org.apache.bval.cdi;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.AfterDeploymentValidation;
 import javax.enterprise.inject.spi.AnnotatedCallable;
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.BeforeBeanDiscovery;
-import javax.enterprise.inject.spi.BeforeShutdown;
+import javax.enterprise.inject.spi.CDI;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.InjectionTarget;
 import javax.enterprise.inject.spi.ProcessAnnotatedType;
 import javax.enterprise.inject.spi.ProcessBean;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
 import javax.validation.BootstrapConfiguration;
 import javax.validation.Configuration;
 import javax.validation.Validation;
@@ -49,16 +46,11 @@ import java.lang.reflect.Type;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-// mainly copied from deltaspike to not force users to use deltaspike
-// which would be a pain in app servers
-// TODO: get rid of beans.xml adding interceptor automatically
 public class BValExtension implements Extension {
     private static final Logger LOGGER = Logger.getLogger(BValExtension.class.getName());
 
@@ -73,9 +65,6 @@ public class BValExtension implements Ex
         SKIPPED_PREFIXES.add("org.apache.myfaces."); // should be checked when upgrading
     }
 
-    private static BValExtension bmpSingleton = null;
-    private volatile Map<ClassLoader, BeanManagerInfo> bmInfos = new ConcurrentHashMap<ClassLoader,
BeanManagerInfo>();
-
     private boolean validatorFound = Boolean.getBoolean("bval.in-container");
     private boolean validatorFactoryFound = Boolean.getBoolean("bval.in-container");
 
@@ -142,10 +131,6 @@ public class BValExtension implements Ex
         return globalExecutableTypes;
     }
 
-    public static BValExtension getInstance() {
-        return bmpSingleton;
-    }
-
     public void addBvalBinding(final @Observes BeforeBeanDiscovery beforeBeanDiscovery, final
BeanManager beanManager) {
         beforeBeanDiscovery.addInterceptorBinding(BValBinding.class);
         beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(BValInterceptor.class));
@@ -229,24 +214,9 @@ public class BValExtension implements Ex
             factory.close();
         }
 
-        captureBeanManager(beanManager); // next method will need it
         cdiIntegration(afterBeanDiscovery, beanManager);
     }
 
-    private void captureBeanManager(final BeanManager beanManager) {
-        // bean manager holder
-        if (bmpSingleton == null) {
-            synchronized (LOGGER) { // a static instance
-                if (bmpSingleton == null) {
-                    bmpSingleton = this;
-                }
-            }
-        }
-
-        final BeanManagerInfo bmi = getBeanManagerInfo(loader());
-        bmi.loadTimeBm = beanManager;
-    }
-
     private void cdiIntegration(final AfterBeanDiscovery afterBeanDiscovery, final BeanManager
beanManager) {
         try {
             config.addProperty("bval.before.cdi", "false"); // now take into account all
the config
@@ -280,65 +250,9 @@ public class BValExtension implements Ex
         return Thread.currentThread().getContextClassLoader();
     }
 
-    public BeanManager getBeanManager() {
-        final BeanManagerInfo bmi = getBeanManagerInfo(loader());
-
-        BeanManager result = bmi.finalBm;
-        if (result == null && bmi.cdi == null) {
-            synchronized (this) {
-                result = resolveBeanManagerViaJndi();
-                if (result == null) {
-                    result = bmi.loadTimeBm;
-                }
-                if (result == null) {
-                    bmi.cdi = false;
-                    return null;
-                }
-                bmi.cdi = true;
-                bmi.finalBm = result;
-            }
-        }
-
-        return result;
-    }
-
-    public void cleanupFinalBeanManagers(final @Observes AfterDeploymentValidation ignored)
{
-        for (final BeanManagerInfo bmi : bmpSingleton.bmInfos.values()) {
-            bmi.finalBm = null;
-        }
-    }
-
-    public void cleanupStoredBeanManagerOnShutdown(final @Observes BeforeShutdown ignored)
{
-        if (bmpSingleton != null && bmpSingleton.bmInfos != null) {
-            bmpSingleton.bmInfos.remove(loader());
-        }
-    }
-
-    private static BeanManager resolveBeanManagerViaJndi() {
-        try {
-            return (BeanManager) new InitialContext().lookup("java:comp/BeanManager");
-        } catch (final NamingException e) {
-            return null;
-        }
-    }
-
-    private BeanManagerInfo getBeanManagerInfo(final ClassLoader cl) {
-        BeanManagerInfo bmi = bmpSingleton.bmInfos.get(cl);
-        if (bmi == null) {
-            synchronized (this) {
-                bmi = bmpSingleton.bmInfos.get(cl);
-                if (bmi == null) {
-                    bmi = new BeanManagerInfo();
-                    bmpSingleton.bmInfos.put(cl, bmi);
-                }
-            }
-        }
-        return bmi;
-    }
-
     public static <T> Releasable<T> inject(final Class<T> clazz) {
         try {
-            final BeanManager beanManager = getInstance().getBeanManager();
+            final BeanManager beanManager = CDI.current().getBeanManager();
             if (beanManager == null) {
                 return null;
             }
@@ -358,10 +272,8 @@ public class BValExtension implements Ex
         return null;
     }
 
-    private static class BeanManagerInfo {
-        private BeanManager loadTimeBm = null;
-        private BeanManager finalBm = null;
-        private Boolean cdi = null;
+    public static BeanManager getBeanManager() {
+        return CDI.current().getBeanManager();
     }
 
     public static class Releasable<T> {

Modified: bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java
URL: http://svn.apache.org/viewvc/bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java?rev=1631103&r1=1631102&r2=1631103&view=diff
==============================================================================
--- bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java
(original)
+++ bval/branches/bval-11/bval-jsr/src/main/java/org/apache/bval/jsr/DefaultConstraintValidatorFactory.java
Sat Oct 11 19:31:34 2014
@@ -47,7 +47,7 @@ public class DefaultConstraintValidatorF
             synchronized (this) {
                 if (useCdi == null) {
                     try {
-                        useCdi = BValExtension.getInstance() != null && BValExtension.getInstance().getBeanManager()
!= null;
+                        useCdi = BValExtension.getBeanManager() != null;
                     } catch (final NoClassDefFoundError error) {
                         useCdi = false;
                     } catch (final Exception e) {
@@ -65,8 +65,9 @@ public class DefaultConstraintValidatorF
                     final BValExtension.Releasable<T> instance = BValExtension.inject(constraintClass);
                     if (instance != null) {
                         releasables.add(instance);
+                        return instance.getInstance();
                     }
-                    return instance.getInstance();
+                    throw new IllegalStateException("Can't create " + constraintClass.getName());
                 } catch (final Exception e) {
                     return constraintClass.newInstance();
                 } catch (final NoClassDefFoundError error) {



Mime
View raw message