[jboss-cvs] JBossAS SVN: r86515 - in projects/ejb3/trunk: core/src/main/java/org/jboss/ejb3/kernel and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 31 04:49:39 EDT 2009


Author: jaikiran
Date: 2009-03-31 04:49:39 -0400 (Tue, 31 Mar 2009)
New Revision: 86515

Added:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/LazyJNDIKernelRegistryEntry.java
Modified:
   projects/ejb3/trunk/as-int/pom.xml
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java
   projects/ejb3/trunk/ejb3/pom.xml
   projects/ejb3/trunk/plugin/pom.xml
Log:
EJBTHREE-1798 JNDIKernelRegistryPlugin will now return a lazy kernel entry

Modified: projects/ejb3/trunk/as-int/pom.xml
===================================================================
--- projects/ejb3/trunk/as-int/pom.xml	2009-03-31 06:38:48 UTC (rev 86514)
+++ projects/ejb3/trunk/as-int/pom.xml	2009-03-31 08:49:39 UTC (rev 86515)
@@ -29,7 +29,7 @@
     into the AS
     
      -->
-    <version.org.jboss.ejb3_jboss.ejb3>1.1.3</version.org.jboss.ejb3_jboss.ejb3>
+    <version.org.jboss.ejb3_jboss.ejb3>1.1.4-SNAPSHOT</version.org.jboss.ejb3_jboss.ejb3>
     <version.org.jboss.ejb3_mc.int>1.0.0</version.org.jboss.ejb3_mc.int>
   
   </properties>

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java	2009-03-31 06:38:48 UTC (rev 86514)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java	2009-03-31 08:49:39 UTC (rev 86515)
@@ -24,11 +24,9 @@
 import java.util.Hashtable;
 
 import javax.naming.Context;
-import javax.naming.NameNotFoundException;
 import javax.naming.NamingException;
 
 import org.jboss.ejb3.InitialContextFactory;
-import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
 import org.jboss.kernel.spi.registry.KernelRegistryEntry;
 import org.jboss.kernel.spi.registry.KernelRegistryPlugin;
 import org.jboss.logging.Logger;
@@ -43,82 +41,62 @@
 public class JNDIKernelRegistryPlugin implements KernelRegistryPlugin
 {
    private static final Logger log = Logger.getLogger(JNDIKernelRegistryPlugin.class);
-   
+
    public static final String JNDI_DEPENDENCY_PREFIX = "jndi:";
-   
+
    private Context context;
+
    private Hashtable<?, ?> environment;
-   
+
    public JNDIKernelRegistryPlugin()
    {
    }
-   
+
    public JNDIKernelRegistryPlugin(Hashtable environment)
    {
       this.environment = environment;
    }
-   
+
    public void create() throws NamingException
    {
       log.debug("Creating JNDIKernelRegistryPlugin");
       this.context = InitialContextFactory.getInitialContext(environment);
    }
-   
+
    public void destroy() throws NamingException
    {
       log.debug("Destroying JNDIKernelRegistryPlugin");
-      if(context != null)
+      if (context != null)
          context.close();
       context = null;
    }
-   
+
+   /**
+    * @see KernelRegistryPlugin#getEntry(Object)
+    */
    public KernelRegistryEntry getEntry(Object name)
    {
-      assert name != null : "name is null";
-      
-      String s = String.valueOf(name);
-      if(!s.startsWith(JNDI_DEPENDENCY_PREFIX))
-         return null;
-      
-      if(log.isTraceEnabled())
-         log.trace("get entry for " + name);
-      
-      try
+      if (name == null)
       {
-         Object target = context.lookup(s.substring(JNDI_DEPENDENCY_PREFIX.length()));
-         if(log.isTraceEnabled())
-            log.trace("found: " + target);
-         // target could be null, but if the entry exists continue.
-         return new AbstractKernelRegistryEntry(name, target);
-//         NamingEnumeration<NameClassPair> e = context.list(s.substring(JNDI_DEPENDENCY_PREFIX.length()));
-//         if(e.hasMore())
-//         {
-//            Object target = e.next(); 
-//            // target could be null, but if the entry exists continue.
-//            return new AbstractKernelRegistryEntry(name, target);
-//         }
-//         return null;
+         // as per the KernelRegistryPlugin interface, we should throw
+         // IllegalArgumentException when name is null
+         throw new IllegalArgumentException("Name cannot be null");
       }
-      catch(NameNotFoundException e)
-      {
-         log.trace("not found");
+
+      String s = String.valueOf(name);
+      if (!s.startsWith(JNDI_DEPENDENCY_PREFIX))
          return null;
-      }
-      catch (NamingException e)
-      {
-         log.trace("entry can't be resolved", e);
-         throw new RuntimeException(e);
-      }
-      catch(RuntimeException e)
-      {
-         log.trace("entry can't be resolved", e);
-         throw e;
-      }
+
+      if (log.isTraceEnabled())
+         log.trace("get entry for " + name);
+
+      String jndiName = s.substring(JNDI_DEPENDENCY_PREFIX.length());
+      return new LazyJNDIKernelRegistryEntry(this.context, jndiName);
    }
 
    public void setEnvironment(Hashtable<?, ?> env)
    {
-      if(context != null)
+      if (context != null)
          throw new IllegalStateException("context already initialized");
       this.environment = env;
    }

Added: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/LazyJNDIKernelRegistryEntry.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/LazyJNDIKernelRegistryEntry.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/kernel/LazyJNDIKernelRegistryEntry.java	2009-03-31 08:49:39 UTC (rev 86515)
@@ -0,0 +1,79 @@
+/**
+ * 
+ */
+package org.jboss.ejb3.kernel;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
+import org.jboss.kernel.spi.registry.KernelRegistryEntry;
+
+/**
+ * LazyKernelRegistryEntry
+ * 
+ * An implementation of {@link KernelRegistryEntry} which returns objects
+ * from JNDI, for the given entry name, lazily.
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class LazyJNDIKernelRegistryEntry extends AbstractKernelRegistryEntry
+{
+
+   /**
+    * JNDI context
+    */
+   private Context ctx;
+
+   /**
+    * Constructor 
+    * 
+    * @param ctx JNDI context
+    * @param name The entry name
+    */
+   public LazyJNDIKernelRegistryEntry(Context ctx, String name)
+   {
+      super(name);
+      this.ctx = ctx;
+   }
+
+   /**
+    * @see KernelRegistryEntry#getTarget()
+    */
+   @Override
+   public Object getTarget()
+   {
+
+      assert name instanceof String : "Cannot determine target for object of type " + this.getName()
+            + " - expected String";
+      Object boundObject;
+      try
+      {
+         boundObject = this.ctx.lookup((String) this.getName());
+         if (log.isTraceEnabled())
+         {
+            log.trace("Found KernelRegistryEntry with name " + this.getName() + " in jndi");
+         }
+         return boundObject;
+      }
+      catch (NameNotFoundException nnfe)
+      {
+         // TODO: do we really need to take care of NameNotFoundException and return null?
+         // Or do we treat it as just another exception? The getTarget() API doesn't specify
+         // what the expected behaviour is, if target is not found
+         if (log.isTraceEnabled())
+         {
+            log.trace("Target for KernelRegistryEntry with name " + this.getName() + " not found in jndi");
+         }
+         return null;
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException("Could not obtain target from KernelRegistryEntry for name " + this.getName(), e);
+      }
+
+   }
+
+}

Modified: projects/ejb3/trunk/ejb3/pom.xml
===================================================================
--- projects/ejb3/trunk/ejb3/pom.xml	2009-03-31 06:38:48 UTC (rev 86514)
+++ projects/ejb3/trunk/ejb3/pom.xml	2009-03-31 08:49:39 UTC (rev 86515)
@@ -34,7 +34,7 @@
     into the AS
     
      -->
-    <version.org.jboss.ejb3_core>1.1.3</version.org.jboss.ejb3_core>
+    <version.org.jboss.ejb3_core>1.1.4-SNAPSHOT</version.org.jboss.ejb3_core>
     <version.org.jboss.ejb3_deployers>1.0.0</version.org.jboss.ejb3_deployers>
   
   </properties>

Modified: projects/ejb3/trunk/plugin/pom.xml
===================================================================
--- projects/ejb3/trunk/plugin/pom.xml	2009-03-31 06:38:48 UTC (rev 86514)
+++ projects/ejb3/trunk/plugin/pom.xml	2009-03-31 08:49:39 UTC (rev 86515)
@@ -63,7 +63,7 @@
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-as-int</artifactId>
-      <version>1.1.3</version>
+      <version>1.1.4-SNAPSHOT</version>
       <optional>true</optional>
       <exclusions>
       	<exclusion>
@@ -85,7 +85,7 @@
       <groupId>org.jboss.ejb3</groupId>
       <artifactId>jboss-ejb3-core</artifactId>
       <classifier>client</classifier>
-      <version>1.1.3</version>
+      <version>1.1.4-SNAPSHOT</version>
       <optional>true</optional>
     </dependency>
 




More information about the jboss-cvs-commits mailing list