[webbeans-commits] Webbeans SVN: r927 - in ri/trunk/webbeans-ri/src: main/java/org/jboss/webbeans/resource and 1 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Jan 13 18:33:11 EST 2009


Author: pete.muir at jboss.org
Date: 2009-01-13 18:33:11 -0500 (Tue, 13 Jan 2009)
New Revision: 927

Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/DefaultNaming.java
   ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java
Log:
a sane implementation of MockNaming :-|

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java	2009-01-13 23:23:28 UTC (rev 926)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/AbstractProducerBean.java	2009-01-13 23:33:11 UTC (rev 927)
@@ -235,7 +235,7 @@
       {
          DependentContext.INSTANCE.setActive(true);
          T instance = produceInstance();
-         //checkReturnValue(instance);
+         checkReturnValue(instance);
          return instance;
       }
       finally

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/DefaultNaming.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/DefaultNaming.java	2009-01-13 23:23:28 UTC (rev 926)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/resource/DefaultNaming.java	2009-01-13 23:33:11 UTC (rev 927)
@@ -17,22 +17,16 @@
 
 package org.jboss.webbeans.resource;
 
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.webbeans.ExecutionException;
 
-import org.jboss.webbeans.resources.spi.Naming;
-
 /**
  * The default naming provider
  * 
  * @author Pete Muir
  */
-public class DefaultNaming implements Naming
+public class DefaultNaming extends AbstractNaming
 {
    private static final long serialVersionUID = 1L;
    // The initial lookup context
@@ -58,72 +52,9 @@
     * 
     * @return The initial context
     */
-   public InitialContext getInitialContext()
+   public InitialContext getContext()
    {
       return initialContext;
    }
 
-   /**
-    * Binds in item to JNDI
-    * 
-    * @param key The key to bind under
-    * @param value The value to bind
-    */
-   public void bind(String key, Object value)
-   {
-      try
-      {
-         List<String> parts = splitIntoContexts(key);
-         Context context = initialContext;
-         for (int i = 0; i < parts.size() - 1; i++)
-         {
-            context = (Context) context.lookup(parts.get(i));
-         }
-         context.bind(parts.get(parts.size() - 1), value);
-      }
-      catch (NamingException e)
-      {
-         throw new ExecutionException("Cannot bind " + value + " to " + key, e);
-      }
-   }
-
-   /**
-    * Lookup an item from JNDI
-    * 
-    * @param name The key
-    * @param expectedType The expected return type
-    * @return The found item
-    */
-   @SuppressWarnings("unchecked")
-   public <T> T lookup(String name, Class<? extends T> expectedType)
-   {
-      Object instance;
-      try
-      {
-         instance = initialContext.lookup(name);
-      }
-      catch (NamingException e)
-      {
-         throw new ExecutionException("Cannot lookup " + name, e);
-      }
-      try
-      {
-         return (T) instance;
-      }
-      catch (ClassCastException e)
-      {
-         throw new ExecutionException(instance + " not of expected type " + expectedType, e);
-      }
-   }
-   
-   private static List<String> splitIntoContexts(String key)
-   {
-      List<String> parts = new ArrayList<String>();
-      for (String part : key.split("/"))
-      {
-         parts.add(part);
-      }
-      return parts;
-   }
-
 }

Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java	2009-01-13 23:23:28 UTC (rev 926)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/mock/MockBootstrap.java	2009-01-13 23:33:11 UTC (rev 927)
@@ -23,25 +23,18 @@
 import org.jboss.webbeans.context.SessionContext;
 import org.jboss.webbeans.context.beanmap.SimpleBeanMap;
 import org.jboss.webbeans.ejb.spi.EjbResolver;
-import org.jboss.webbeans.resource.DefaultNaming;
+import org.jboss.webbeans.resource.AbstractNaming;
 import org.jboss.webbeans.resources.spi.Naming;
 import org.jboss.webbeans.resources.spi.ResourceLoader;
 
 public class MockBootstrap extends WebBeansBootstrap
 { 
    
-   public static class MockNaming implements Naming
+   public static class MockNaming extends AbstractNaming
    {
       
       private Context context;
       
-      private Naming delegate;
-      
-      public MockNaming()
-      {
-         this.delegate = new DefaultNaming();
-      }
-      
       public void setContext(Context context)
       {
          this.context = context;
@@ -56,7 +49,7 @@
       {
          if (context != null)
          {
-            delegate.bind(key, value);
+            super.bind(key, value);
          }
       }
 
@@ -67,7 +60,7 @@
             T instance = overrideLookup(name, expectedType);
             if (instance == null)
             {
-               instance = delegate.lookup(name, expectedType);
+               instance = super.lookup(name, expectedType);
             }
             return instance;
          }
@@ -83,7 +76,7 @@
          // JBoss Embedded EJB 3.1 doesn't seem to bind this!
          if (name.equals("java:comp/UserTransaction"))
          {
-            final TransactionManager tm = delegate.lookup("java:/TransactionManager", TransactionManager.class);
+            final TransactionManager tm = super.lookup("java:/TransactionManager", TransactionManager.class);
             return (T) new UserTransaction()
             {
 




More information about the weld-commits mailing list