[seam-commits] Seam SVN: r11878 - in modules/envconfig/trunk: src/main/java/org/jboss/seam/envconfig/extension and 1 other directory.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Wed Dec 23 16:42:36 EST 2009


Author: dan.j.allen
Date: 2009-12-23 16:42:36 -0500 (Wed, 23 Dec 2009)
New Revision: 11878

Modified:
   modules/envconfig/trunk/pom.xml
   modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
   modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
Log:
honor overwrite flag
switch to slf4j


Modified: modules/envconfig/trunk/pom.xml
===================================================================
--- modules/envconfig/trunk/pom.xml	2009-12-23 21:12:45 UTC (rev 11877)
+++ modules/envconfig/trunk/pom.xml	2009-12-23 21:42:36 UTC (rev 11878)
@@ -73,6 +73,11 @@
          <scope>provided</scope>
          <version>3.1.0</version>
       </dependency>
+      <dependency>
+         <groupId>org.slf4j</groupId>
+         <artifactId>slf4j-api</artifactId>
+         <scope>provided</scope>
+      </dependency>
    </dependencies>
 
    <build>

Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java	2009-12-23 21:12:45 UTC (rev 11877)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/EnvironmentBindingExtension.java	2009-12-23 21:42:36 UTC (rev 11878)
@@ -19,21 +19,23 @@
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.logging.Logger;
 
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.Extension;
 import javax.enterprise.inject.spi.ProcessBean;
+
 import org.jboss.seam.envconfig.EnvironmentBinding;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Matt Corey
  */
 public class EnvironmentBindingExtension implements Extension
 {
-   private Logger log = Logger.getLogger(getClass().getName());
+   private Logger log = LoggerFactory.getLogger(getClass().getName());
 
    private Set<Bean> envBeans = new HashSet<Bean>();
    private BeanManager beanManager;

Modified: modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java
===================================================================
--- modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java	2009-12-23 21:12:45 UTC (rev 11877)
+++ modules/envconfig/trunk/src/main/java/org/jboss/seam/envconfig/extension/JndiBinder.java	2009-12-23 21:42:36 UTC (rev 11878)
@@ -18,7 +18,6 @@
 
 import java.lang.reflect.Field;
 import java.util.Set;
-import java.util.logging.Logger;
 
 import javax.annotation.PostConstruct;
 import javax.ejb.Startup;
@@ -29,14 +28,17 @@
 import javax.inject.Singleton;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+
 import org.jboss.seam.envconfig.Bind;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Matt Corey
  */
 public @Singleton @Startup class JndiBinder
 {
-   private Logger log = Logger.getLogger(getClass().getName());
+   private Logger log = LoggerFactory.getLogger(JndiBinder.class);
 
    @Inject
    private EnvironmentBindingExtension bindingExtension;
@@ -46,7 +48,7 @@
    {
       Set<Bean> envBeans = bindingExtension.getEnvBeans();
 
-      log.info("Processing EnvironmentBinding Classes:  " + envBeans);
+      log.debug("Processing EnvironmentBinding Classes:  " + envBeans);
 
       Context appContext = bindingExtension.getBeanManager().getContext(ApplicationScoped.class);
       for (Bean bean : envBeans)
@@ -60,20 +62,22 @@
          {
             if (field.isAnnotationPresent(Bind.class))
             {
-               log.info("Processing Binding field " + beanClass.getName() + "." + field.getName());
+               log.debug("Processing Binding field " + beanClass.getName() + "." + field.getName());
 
                field.setAccessible(true);
 
-               String jndi = field.getAnnotation(Bind.class).jndiAddress();
+               Bind ann = field.getAnnotation(Bind.class);
+               String jndi = ann.jndiAddress();
+               boolean overwrite = ann.overwrite();
                Object val = field.get(beanInstance);
 
-               bindValue(jndi, val);
+               bindValue(jndi, val, overwrite);
             }
          }
       }
    }
 
-   private void bindValue(String nameSuffix, Object value) throws NamingException
+   private void bindValue(String nameSuffix, Object value, boolean overwrite) throws NamingException
    {
       InitialContext ic = new InitialContext();
 
@@ -87,7 +91,18 @@
          }
       }
       nameToBind.append(nameSuffix);
-      log.info("Bound " + nameToBind + " to " + value);
-      ic.rebind(nameToBind.toString(), value);
+      String name = nameToBind.toString();
+      
+      if (!overwrite) {
+         try {
+            ic.lookup(name);
+            log.debug("JNDI name " + name + " already bound and overwrite is disabled");
+            return;
+         }
+         catch (NamingException e) {
+         }
+      }
+      log.debug("Binding " + name + " to " + value);
+      ic.rebind(name, value);
    }
 }



More information about the seam-commits mailing list