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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 3 09:13:55 EDT 2007


Author: wolfc
Date: 2007-09-03 09:13:55 -0400 (Mon, 03 Sep 2007)
New Revision: 65009

Added:
   trunk/ejb3/src/main/org/jboss/ejb3/kernel/
   trunk/ejb3/src/main/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java
Modified:
   trunk/ejb3/src/main/org/jboss/ejb3/MCDependencyPolicy.java
   trunk/ejb3/src/main/org/jboss/injection/AbstractHandler.java
   trunk/ejb3/src/main/org/jboss/injection/EJBHandler.java
   trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml
Log:
EJBTHREE-1042: depend on JNDI name

Modified: trunk/ejb3/src/main/org/jboss/ejb3/MCDependencyPolicy.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/MCDependencyPolicy.java	2007-09-03 12:21:05 UTC (rev 65008)
+++ trunk/ejb3/src/main/org/jboss/ejb3/MCDependencyPolicy.java	2007-09-03 13:13:55 UTC (rev 65009)
@@ -30,6 +30,7 @@
 import org.jboss.beans.metadata.spi.SupplyMetaData;
 import org.jboss.ejb3.dependency.EjbLinkDemandMetaData;
 import org.jboss.ejb3.javaee.JavaEEComponent;
+import org.jboss.ejb3.kernel.JNDIKernelRegistryPlugin;
 
 /**
  * dependency registry for Microcontainer
@@ -116,6 +117,14 @@
          dependencies.add(new EjbLinkDemandMetaData(component, ejbLink));
    }
    
+   public void addJNDIName(String name)
+   {
+      assert name != null : "name is null";
+      assert name.length() > 0 : "name is empty";
+      
+      addDependency(JNDIKernelRegistryPlugin.JNDI_DEPENDENCY_PREFIX + name);
+   }
+   
    public Set<DemandMetaData> getDependencies()
    {
       return dependencies;

Added: trunk/ejb3/src/main/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java	                        (rev 0)
+++ trunk/ejb3/src/main/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java	2007-09-03 13:13:55 UTC (rev 65009)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.kernel;
+
+import java.util.Hashtable;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+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;
+
+/**
+ * A kernel registry plugin which checks for JNDI names.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author <a href="mailto:ajustin at redhat.com">Ales Justin</a>
+ * @version $Revision: $
+ */
+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 = new InitialContext(environment);
+   }
+   
+   public void destroy() throws NamingException
+   {
+      log.debug("Destroying JNDIKernelRegistryPlugin");
+      if(context != null)
+         context.close();
+      context = null;
+   }
+   
+   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("getEntry(" + name + ")");
+      
+      try
+      {
+         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;
+      }
+      catch(NameNotFoundException e)
+      {
+         return null;
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public void setEnvironment(Hashtable<?, ?> env)
+   {
+      if(context != null)
+         throw new IllegalStateException("context already initialized");
+      this.environment = env;
+   }
+}


Property changes on: trunk/ejb3/src/main/org/jboss/ejb3/kernel/JNDIKernelRegistryPlugin.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: trunk/ejb3/src/main/org/jboss/injection/AbstractHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/injection/AbstractHandler.java	2007-09-03 12:21:05 UTC (rev 65008)
+++ trunk/ejb3/src/main/org/jboss/injection/AbstractHandler.java	2007-09-03 13:13:55 UTC (rev 65009)
@@ -69,4 +69,9 @@
       
       ((JBoss5DependencyPolicy) container.getDependencyPolicy()).addDependency(link, businessIntf);
    }
+   
+   protected void addJNDIDependency(InjectionContainer container, String jndiName)
+   {
+      ((JBoss5DependencyPolicy) container.getDependencyPolicy()).addJNDIName(jndiName);
+   }
 }

Modified: trunk/ejb3/src/main/org/jboss/injection/EJBHandler.java
===================================================================
--- trunk/ejb3/src/main/org/jboss/injection/EJBHandler.java	2007-09-03 12:21:05 UTC (rev 65008)
+++ trunk/ejb3/src/main/org/jboss/injection/EJBHandler.java	2007-09-03 13:13:55 UTC (rev 65009)
@@ -124,14 +124,21 @@
             return;
          }
 
-         ejbRefDependency(link, container, refClass, errorType, encName);
+         ejbRefDependency(mappedName, link, container, refClass, errorType, encName);
       }
    }
 
-   protected void ejbRefDependency(String link, InjectionContainer container, Class refClass, String errorType, String encName)
+   protected void ejbRefDependency(String mappedName, String link, InjectionContainer container, Class refClass, String errorType, String encName)
    {
+      if(mappedName != null && mappedName.length() == 0) mappedName = null;
       if (refClass != null && (refClass.equals(Object.class) || refClass.equals(void.class))) refClass = null;
 
+      if(mappedName != null)
+      {
+         addJNDIDependency(container, mappedName);
+         return;
+      }
+      
       if (refClass != null)
       {
          if (link != null && !link.trim().equals(""))
@@ -284,7 +291,7 @@
       if (isIgnoreDependency(container, ejb))
          log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
       else
-         ejbRefDependency(ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName);
+         ejbRefDependency(ejb.mappedName(), ejb.beanName(), container, ejb.beanInterface(), "@EJB", encName);
    }
 
    public void handleMethodAnnotations(Method method, InjectionContainer container, Map<AccessibleObject, Injector> injectors)
@@ -304,7 +311,7 @@
                if (isIgnoreDependency(container, ref))
                   log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
                else
-                  ejbRefDependency(ref.beanName(), container, method.getParameterTypes()[0], "@EJB", encName);
+                  ejbRefDependency(ref.mappedName(), ref.beanName(), container, method.getParameterTypes()[0], "@EJB", encName);
             }
          }
 
@@ -325,7 +332,7 @@
                if (isIgnoreDependency(container, ref))
                   log.debug("IGNORING <ejb-ref> DEPENDENCY: " + encName);
                else
-                  ejbRefDependency(ref.beanName(), container, field.getType(), "@EJB", encName);
+                  ejbRefDependency(ref.mappedName(), ref.beanName(), container, field.getType(), "@EJB", encName);
             }
             ejbRefEncInjector(ref.mappedName(), encName, field.getType(), ref.beanName(), "@EJB", container);
          }

Modified: trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml
===================================================================
--- trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml	2007-09-03 12:21:05 UTC (rev 65008)
+++ trunk/ejb3/src/resources/META-INF/ejb3-deployers-beans.xml	2007-09-03 13:13:55 UTC (rev 65009)
@@ -139,4 +139,6 @@
       <depends>AspectLibrary</depends>
       <depends>AppClientScanningDeployer</depends>
    </bean>
+   
+   <bean name="JNDIKernelRegistryPlugin" class="org.jboss.ejb3.kernel.JNDIKernelRegistryPlugin"/>
 </deployment>




More information about the jboss-cvs-commits mailing list