[jboss-cvs] JBossAS SVN: r94468 - in projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface: deployers and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Oct 7 12:19:01 EDT 2009


Author: jaikiran
Date: 2009-10-07 12:18:59 -0400 (Wed, 07 Oct 2009)
New Revision: 94468

Modified:
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java
   projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java
Log:
EJBTHREE-1727 Better handling of javassist ClassPool and other minor implementation changes to the no-interface view impl

Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java	2009-10-07 15:33:48 UTC (rev 94467)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/NoInterfaceEJBViewFactoryBase.java	2009-10-07 16:18:59 UTC (rev 94468)
@@ -32,20 +32,17 @@
 import javassist.CtField;
 import javassist.CtMethod;
 import javassist.CtNewMethod;
+import javassist.LoaderClassPath;
 import javassist.Modifier;
 
 import org.jboss.logging.Logger;
 
 /**
- * NoInterfaceEJBViewCreator
+ * NoInterfaceEJBViewFactoryBase
  *
  * Creates a no-interface view for a EJB as per the EJB3.1 spec (section 3.4.4)
  *
- * TODO:
- * 1) Needs to be tested more for i) Classloaders ii) Security Manager
- * 2) Though not related here, we need to have support for @LocalBean (and corresponding xml element) through JBMETA
- *
- *
+ * @see NoInterfaceViewFactory
  * @author Jaikiran Pai
  * @version $Revision: $
  */
@@ -86,27 +83,23 @@
       {
          logger.trace("Creating nointerface view for beanClass: " + beanClass + " with container " + invocationHandler);
       }
-      //TODO: Validation as per section 4.9.8 of EJB 3.1 PR spec needs to be implemented.
-      // Instead of accepting a bean class, maybe we should accept the JBossSessionBeanMetadata.
-      // The metadata is required to carry out validations on the bean to ensure that section 4.9.8
-      // of the EJB 3.1 PR spec. We could create the metadata ourselves, from the bean class, here, but
-      // that would be duplication of efforts since the metadata is surely going to created at some place else too
 
-      ClassPool pool = ClassPool.getDefault();
+      // Create a ClassPool and add the classpath using the classloader of the beanClass, so 
+      // that it uses the correct jar while looking up the class
+      ClassPool pool = new ClassPool();
+      pool.appendClassPath(new LoaderClassPath(beanClass.getClassLoader()));
+      
       CtClass beanCtClass = pool.get(beanClass.getName());
 
-      // Create a sub-class (proxy) for the bean class
-      // TODO: This should be a unique name. Should not clash with any of the classnames in
-      // the user application or with any of already created proxy names
-      // Right now lets append _NoInterfaceProxy to the bean class name
+      // Create a sub-class (proxy) for the bean class. A unique name will be used for the subclass
       CtClass proxyCtClass = pool.makeClass(beanClass.getName() + "_NoInterfaceProxy$" + getNextUniqueNumber(),
             beanCtClass);
 
-      // We need to maintain a reference of the container in the proxy, so that we can
+      // We need to maintain a reference of the invocationHandler in the proxy, so that we can
       // forward the method calls to invocationHandler.invoke. Create a new field in the sub-class (proxy)
-      CtField containerField = CtField.make("private java.lang.reflect.InvocationHandler invocationHandler;",
+      CtField invocationHandlerField = CtField.make("private java.lang.reflect.InvocationHandler invocationHandler;",
             proxyCtClass);
-      proxyCtClass.addField(containerField);
+      proxyCtClass.addField(invocationHandlerField);
 
       // get all public methods from the bean class
       Set<CtMethod> beanPublicMethods = getAllPublicNonStaticNonFinalMethods(beanCtClass);
@@ -148,7 +141,7 @@
       // We are almost done (except for setting the container field in the proxy)
       // Let's first create a java.lang.Class (i.e. load) out of the javassist class
       // using the classloader of the bean
-      Class<?> proxyClass = proxyCtClass.toClass(beanClass.getClassLoader());
+      Class<?> proxyClass = proxyCtClass.toClass(beanClass.getClassLoader(), beanClass.getProtectionDomain());
       // time to set the container field through normal java reflection
       Object proxyInstance = proxyClass.newInstance();
       Field containerInProxy = proxyClass.getDeclaredField("invocationHandler");
@@ -160,7 +153,7 @@
 
    }
 
-   protected <T> CtMethod overridePublicMethod(InvocationHandler container, Class<T> beanClass,
+   private <T> CtMethod overridePublicMethod(InvocationHandler container, Class<T> beanClass,
          CtMethod publicMethodOnBean, CtMethod publicMethodOnProxy) throws Exception
    {
       publicMethodOnProxy.setBody("{"
@@ -186,7 +179,7 @@
     * @return
     * @throws Exception
     */
-   protected Set<CtMethod> getAllPublicNonStaticNonFinalMethods(CtClass ctClass) throws Exception
+   private Set<CtMethod> getAllPublicNonStaticNonFinalMethods(CtClass ctClass) throws Exception
    {
       CtMethod[] allMethods = ctClass.getMethods();
       Set<CtMethod> publicMethods = new HashSet<CtMethod>();
@@ -215,7 +208,7 @@
     * @return
     * @throws Exception
     */
-   protected boolean shouldMethodBeSkipped(CtClass beanCtClass, CtMethod ctMethod) throws Exception
+   private boolean shouldMethodBeSkipped(CtClass beanCtClass, CtMethod ctMethod) throws Exception
    {
 
       //      List<CtMethod> declaredMethods = Arrays.asList(beanCtClass.getDeclaredMethods());
@@ -279,7 +272,7 @@
     *
     * @return
     */
-   protected long getNextUniqueNumber()
+   private long getNextUniqueNumber()
    {
       synchronized (nextUniqueNumberLock)
       {

Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java	2009-10-07 15:33:48 UTC (rev 94467)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/deployers/EJB3NoInterfaceDeployer.java	2009-10-07 16:18:59 UTC (rev 94468)
@@ -31,6 +31,7 @@
 import javax.ejb.LocalBean;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
+import javax.naming.InitialContext;
 
 import org.jboss.beans.metadata.api.model.FromContext;
 import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
@@ -43,6 +44,7 @@
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.ejb3.nointerface.mc.NoInterfaceViewJNDIBinder;
 import org.jboss.logging.Logger;
+import org.jboss.metadata.ear.jboss.JBossAppMetaData;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeansMetaData;
 import org.jboss.metadata.ejb.jboss.JBossMetaData;
@@ -50,6 +52,9 @@
 
 /**
  * EJB3NoInterfaceDeployer
+ * 
+ * Deployer responsible for processing EJB3 deployments with a no-interface view.
+ * @see #deploy(DeploymentUnit) for the deployment unit processing details.
  *
  * @author Jaikiran Pai
  * @version $Revision: $
@@ -68,14 +73,23 @@
    public EJB3NoInterfaceDeployer()
    {
       setStage(DeploymentStages.REAL);
-      addInput(JBossMetaData.class);
-
+      setInput(JBossMetaData.class);
+      // we deploy MC beans
       addOutput(BeanMetaData.class);
 
    }
 
    /**
-    * Deploy the deployment unit
+    * Process the deployment unit and deploy appropriate MC beans (see details below)
+    * if it corresponds to a no-interface view deployment.
+    * 
+    * If any beans in the unit are eligible for no-interface view, then internally this method
+    * creates a {@link NoInterfaceViewJNDIBinder} MC bean for the no-interface view.
+    * 
+    * The {@link NoInterfaceViewJNDIBinder}, thus created, will be dependent on the {@link ControllerState#DESCRIBED}
+    * state of the container (endpoint) MC bean. This way, we ensure that this {@link NoInterfaceViewJNDIBinder}
+    * will be deployed only after the corresponding container MC bean moves to {@link ControllerState#DESCRIBED}
+    * state.
     */
    public void deploy(DeploymentUnit unit) throws DeploymentException
    {
@@ -101,7 +115,7 @@
             {
                logger.trace("Found bean of type session: " + bean.getEjbClass() + " in unit " + unit.getName());
             }
-            // Create view for each bean
+            // Process for no-interface view
             deploy(unit, (JBossSessionBeanMetaData) bean);
          }
       }
@@ -112,11 +126,15 @@
     * Creates a {@link NoInterfaceViewJNDIBinder} MC bean for the no-interface view represented by the
     * <code>sessionBeanMetaData</code>. The {@link NoInterfaceViewJNDIBinder} is created only
     * if the bean is eligible for a no-interface view as defined by the EJB3.1 spec
+    * 
+    * The {@link NoInterfaceViewJNDIBinder}, thus created, will be dependent on the {@link ControllerState#DESCRIBED}
+    * state of the container (endpoint) MC bean. This way, we ensure that this {@link NoInterfaceViewJNDIBinder}
+    * will be deployed only after the corresponding container MC bean moves to {@link ControllerState#DESCRIBED}
+    * state.
     *
-    *
-    * @param unit
-    * @param sessionBeanMetaData
-    * @throws DeploymentException
+    * @param unit Deployment unit
+    * @param sessionBeanMetaData Session bean metadata
+    * @throws DeploymentException If any exceptions are encountered during processing of the deployment unit
     */
    private void deploy(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetaData) throws DeploymentException
    {
@@ -124,7 +142,10 @@
       {
          if (!isEligibleForNoInterfaceView(unit, sessionBeanMetaData))
          {
-            logger.debug("Bean " + sessionBeanMetaData.getEjbClass() + " is not eligible for no-interface view");
+            if (logger.isTraceEnabled())
+            {
+               logger.trace("Bean class " + sessionBeanMetaData.getEjbClass() + " is not eligible for no-interface view");
+            }
             return;
          }
          Class<?> beanClass = Class.forName(sessionBeanMetaData.getEjbClass(), false, unit.getClassLoader());
@@ -145,16 +166,16 @@
 
          }
 
-         // The no-interface view needs to be a MC bean so that it can "depend" on the KernelControllerContext
-         // of the container. The NoInterfaceViewJNDIBinder is the MC which will have this dependency
-         NoInterfaceViewJNDIBinder noInterfaceViewJNDIBinder = NoInterfaceViewJNDIBinder.getNoInterfaceViewJndiBinder(beanClass,
+         // Create the NoInterfaceViewJNDIBinder (MC bean) and add a dependency on the DESCRIBED
+         // state of the container (endpoint) MC bean
+         NoInterfaceViewJNDIBinder noInterfaceViewJNDIBinder = NoInterfaceViewJNDIBinder.getNoInterfaceViewJndiBinder(new InitialContext(), beanClass,
                sessionBeanMetaData);
-         String noInterfaceViewMCBeanName = sessionBeanMetaData.getEjbName() + "@" + ((Object) noInterfaceViewJNDIBinder).toString();
+         String noInterfaceViewMCBeanName = unit.getName() + "$" + sessionBeanMetaData.getEjbName();
          BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(noInterfaceViewMCBeanName, noInterfaceViewJNDIBinder.getClass()
                .getName());
          builder.setConstructorValue(noInterfaceViewJNDIBinder);
 
-         //ValueMetaData inject = builder.createInject(containerMCBeanName, null, null, ControllerState.DESCRIBED);
+         // add dependency
          AbstractInjectionValueMetaData injectMetaData = new AbstractInjectionValueMetaData(containerMCBeanName);
          injectMetaData.setDependentState(ControllerState.DESCRIBED);
          injectMetaData.setFromContext(FromContext.CONTEXT);
@@ -166,7 +187,7 @@
          // Add this as an attachment
          unit.addAttachment(BeanMetaData.class + ":" + noInterfaceViewMCBeanName, builder.getBeanMetaData());
          
-         logger.debug("MC bean for container " + containerMCBeanName + " has been created and added to the deployment unit " + unit);
+         logger.debug("No-interface JNDI binder for container " + containerMCBeanName + " has been created and added to the deployment unit " + unit);
 
       }
       catch (Throwable t)
@@ -178,6 +199,7 @@
 
    /**
     * Undeploy
+    * 
     * @param unit
     * @param deployment
     */
@@ -194,7 +216,7 @@
     * @param sessionBeanMetadata
     * @return
     */
-   protected boolean isEligibleForNoInterfaceView(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetadata)
+   private boolean isEligibleForNoInterfaceView(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetadata)
          throws Exception
    {
 
@@ -271,9 +293,9 @@
     * @param beanClass
     * @return Returns true if the bean implements any interface(s) other than {@link Serializable}
     *           or {@link Externalizable} or anything from javax.ejb.* packages.
-    * @throws DeploymentException
+    * 
     */
-   protected boolean doesBeanImplementAnyInterfaces(Class<?> beanClass) throws DeploymentException
+   private boolean doesBeanImplementAnyInterfaces(Class<?> beanClass)
    {
       Class<?>[] interfaces = beanClass.getInterfaces();
       if (interfaces.length == 0)
@@ -371,6 +393,6 @@
     */
    private boolean isEar(DeploymentUnit unit)
    {
-      return unit.getSimpleName().endsWith(".ear");
+      return unit.getSimpleName().endsWith(".ear") || unit.getAttachment(JBossAppMetaData.class) != null;
    }
 }

Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java	2009-10-07 15:33:48 UTC (rev 94467)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/NoInterfaceViewJNDIBinder.java	2009-10-07 16:18:59 UTC (rev 94468)
@@ -21,6 +21,9 @@
  */
 package org.jboss.ejb3.nointerface.mc;
 
+import javax.naming.Context;
+import javax.naming.NamingException;
+
 import org.jboss.beans.metadata.api.annotations.Inject;
 import org.jboss.beans.metadata.api.annotations.Start;
 import org.jboss.beans.metadata.api.annotations.Stop;
@@ -71,12 +74,35 @@
     */
    protected JBossSessionBeanMetaData sessionBeanMetadata;
 
-   public static NoInterfaceViewJNDIBinder getNoInterfaceViewJndiBinder(Class<?> beanClass,
+   /**
+    * JNDI naming context
+    */
+   protected Context jndiCtx;
+
+   /**
+    * Suffix to be added to the ejb-name to form the jndi name of no-interface view
+    * 
+    * TODO: Until the no-interface jndi-name comes from metadata, we need to hardcode the jndi-name
+    * 
+    */
+   protected static final String NO_INTERFACE_JNDI_SUFFIX = "/no-interface";
+
+   /**
+    * Returns an appropriate instance of {@link NoInterfaceViewJNDIBinder} based on the 
+    * <code>sessionBeanMetadata</code>
+    * 
+    * @param ctx JNDI naming context into which this {@link NoInterfaceViewJNDIBinder} will be
+    *           responsible for binding/unbinding objects
+    * @param beanClass Bean class
+    * @param sessionBeanMetadata Session bean metadata of the bean class
+    * @return 
+    */
+   public static NoInterfaceViewJNDIBinder getNoInterfaceViewJndiBinder(Context ctx, Class<?> beanClass,
          JBossSessionBeanMetaData sessionBeanMetadata)
    {
       return sessionBeanMetadata.isStateful()
-            ? new StatefulNoInterfaceJNDIBinder(beanClass, sessionBeanMetadata)
-            : new StatelessNoInterfaceJNDIBinder(beanClass, sessionBeanMetadata);
+            ? new StatefulNoInterfaceJNDIBinder(ctx, beanClass, sessionBeanMetadata)
+            : new StatelessNoInterfaceJNDIBinder(ctx, beanClass, sessionBeanMetadata);
    }
 
    /**
@@ -85,8 +111,9 @@
     * @param beanClass
     * @param sessionBeanMetadata
     */
-   protected NoInterfaceViewJNDIBinder(Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
+   protected NoInterfaceViewJNDIBinder(Context ctx, Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
    {
+      this.jndiCtx = ctx;
       this.beanClass = beanClass;
       this.sessionBeanMetadata = sessionBeanMetadata;
 
@@ -95,11 +122,18 @@
    /**
     * Bind the no-interface view 
     * 
-    * @throws Exception
+    * @throws NamingException If any exception while binding to JNDI
     */
-   public abstract void bindNoInterfaceView() throws Exception;
+   public abstract void bindNoInterfaceView() throws NamingException;
 
    /**
+    * Unbind the no-interface view
+    * 
+    * @throws NamingException If any exception while unbinding from JNDI
+    */
+   public abstract void unbindNoInterfaceView() throws NamingException;
+
+   /**
     * Will be called when the dependencies of this {@link NoInterfaceViewJNDIBinder} are
     * resolved and this MC bean reaches the START state.
     *
@@ -123,11 +157,19 @@
       this.bindNoInterfaceView();
    }
 
+   /**
+    * Does any relevant cleanup
+    *  
+    * @throws Exception
+    */
    @Stop
    public void onStop() throws Exception
    {
-
-      //TODO need to unbind
+      if (logger.isTraceEnabled())
+      {
+         logger.trace("Unbinding no-interface view from JNDI, for endpoint " + this.endpointContext);
+      }
+      this.unbindNoInterfaceView();
    }
 
    /**

Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java	2009-10-07 15:33:48 UTC (rev 94467)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatefulNoInterfaceJNDIBinder.java	2009-10-07 16:18:59 UTC (rev 94468)
@@ -21,8 +21,8 @@
  */
 package org.jboss.ejb3.nointerface.mc;
 
-import javax.naming.InitialContext;
-import javax.naming.Name;
+import javax.naming.Context;
+import javax.naming.NamingException;
 import javax.naming.RefAddr;
 import javax.naming.Reference;
 import javax.naming.StringRefAddr;
@@ -33,7 +33,6 @@
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.util.naming.NonSerializableFactory;
-import org.jnp.interfaces.NamingParser;
 
 /**
  * StatefulNoInterfaceJNDIBinder
@@ -51,15 +50,22 @@
     * Logger
     */
    private static Logger logger = Logger.getLogger(StatefulNoInterfaceJNDIBinder.class);
-
+   
    /**
+    * Suffix to be added to the ejb-name to form the jndi name of no-interface stateful proxyfactory
+    * 
+    * 
+    */
+   private static final String NO_INTERFACE_STATEFUL_PROXY_FACTORY_JNDI_NAME_SUFFIX = "/no-interface-stateful-proxyfactory";
+   
+   /**
     * Constructor
     * @param beanClass The bean class
     * @param sessionBeanMetadata Metadata of the bean
     */
-   protected StatefulNoInterfaceJNDIBinder(Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
+   protected StatefulNoInterfaceJNDIBinder(Context ctx, Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
    {
-      super(beanClass, sessionBeanMetadata);
+      super(ctx, beanClass, sessionBeanMetadata);
 
    }
 
@@ -77,7 +83,7 @@
     *
     */
    @Override
-   public void bindNoInterfaceView() throws Exception
+   public void bindNoInterfaceView() throws NamingException
    {
       logger.debug("Binding no-interface view statefulproxyfactory and the objectfactory for bean " + this.beanClass);
 
@@ -87,12 +93,9 @@
             this.beanClass, this.endpointContext);
 
       // TODO - Needs to be a proper jndi name for the factory
-      String statefulProxyFactoryJndiName = sessionBeanMetadata.getEjbName() + "/no-interface-stateful-proxyfactory";
+      String statefulProxyFactoryJndiName = sessionBeanMetadata.getEjbName() + NO_INTERFACE_STATEFUL_PROXY_FACTORY_JNDI_NAME_SUFFIX;
       // Bind the proxy factory to jndi
-      // Bind a reference to nonserializable using NonSerializableFactory as the ObjectFactory
-      NamingParser namingParser = new NamingParser();
-      Name jndiName = namingParser.parse(statefulProxyFactoryJndiName);
-      NonSerializableFactory.rebind(jndiName, statefulNoInterfaceViewFactory, true);
+      NonSerializableFactory.rebind(this.jndiCtx, statefulProxyFactoryJndiName, statefulNoInterfaceViewFactory, true);
 
       // Create an Reference which will hold the jndi-name of the statefulproxyfactory which will
       // be responsible for creating the no-interface view for the stateful bean upon lookup
@@ -107,13 +110,24 @@
 
       // TODO: Again, the jndi-names for the no-interface view are a mess now. They need to come from
       // the metadata. Let's just go ahead temporarily
-      String noInterfaceJndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
-      // TODO : This is not right - i guess there is some way to get hold of the initial context
-      // for a given deployment. Need to look more into this
-      new InitialContext().bind(noInterfaceJndiName, reference);
-
+      String noInterfaceJndiName = sessionBeanMetadata.getEjbName() + NO_INTERFACE_JNDI_SUFFIX;
+      this.jndiCtx.bind(noInterfaceJndiName, reference);
       logger.info("Bound the no-interface view for bean " + beanClass + " to jndi at " + noInterfaceJndiName);
 
    }
 
+   /**
+    * Unbind the {@link MCAwareStatefulNoInterfaceViewFactory} and the {@link StatefulNoInterfaceViewObjectFactory}
+    * from the jndi
+    * 
+    * @see org.jboss.ejb3.nointerface.mc.NoInterfaceViewJNDIBinder#unbindNoInterfaceView()
+    */
+   @Override
+   public void unbindNoInterfaceView() throws NamingException
+   {
+      this.jndiCtx.unbind(this.sessionBeanMetadata.getEjbName() + NO_INTERFACE_JNDI_SUFFIX);
+      this.jndiCtx.unbind(this.sessionBeanMetadata.getEjbName() + NO_INTERFACE_STATEFUL_PROXY_FACTORY_JNDI_NAME_SUFFIX);
+      
+   }
+
 }

Modified: projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java
===================================================================
--- projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java	2009-10-07 15:33:48 UTC (rev 94467)
+++ projects/ejb3/trunk/nointerface/src/main/java/org/jboss/ejb3/nointerface/mc/StatelessNoInterfaceJNDIBinder.java	2009-10-07 16:18:59 UTC (rev 94468)
@@ -23,7 +23,8 @@
 
 import java.lang.reflect.InvocationHandler;
 
-import javax.naming.Name;
+import javax.naming.Context;
+import javax.naming.NamingException;
 
 import org.jboss.ejb3.nointerface.NoInterfaceEJBViewFactoryBase;
 import org.jboss.ejb3.nointerface.NoInterfaceViewFactory;
@@ -31,7 +32,6 @@
 import org.jboss.logging.Logger;
 import org.jboss.metadata.ejb.jboss.JBossSessionBeanMetaData;
 import org.jboss.util.naming.NonSerializableFactory;
-import org.jnp.interfaces.NamingParser;
 
 /**
  * StatelessNoInterfaceJNDIBinder
@@ -49,10 +49,17 @@
     * Logger
     */
    private static Logger logger = Logger.getLogger(StatelessNoInterfaceJNDIBinder.class);
-
-   protected StatelessNoInterfaceJNDIBinder(Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
+   
+   /**
+    * Constructor
+    * 
+    * @param ctx
+    * @param beanClass
+    * @param sessionBeanMetadata
+    */
+   protected StatelessNoInterfaceJNDIBinder(Context ctx, Class<?> beanClass, JBossSessionBeanMetaData sessionBeanMetadata)
    {
-      super(beanClass, sessionBeanMetadata);
+      super(ctx, beanClass, sessionBeanMetadata);
    }
 
    /**
@@ -62,27 +69,42 @@
     * @see NoInterfaceEJBViewFactoryBase#createView(java.lang.reflect.InvocationHandler, Class)
     */
    @Override
-   public void bindNoInterfaceView() throws Exception
+   public void bindNoInterfaceView() throws NamingException
    {
-      logger.debug("Creating no-interface view for bean " + this.beanClass);
-
       // Create the view from the factory and bind to jndi
       NoInterfaceViewFactory noInterfaceViewCreator = new NoInterfaceEJBViewFactoryBase();
 
       InvocationHandler invocationHandler = new MCAwareNoInterfaceViewInvocationHandler(this.endpointContext, null);
 
-      Object noInterfaceView = noInterfaceViewCreator.createView(invocationHandler, beanClass);
+      Object noInterfaceView;
+      try
+      {
+         noInterfaceView = noInterfaceViewCreator.createView(invocationHandler, beanClass);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Could not create no-interface view for bean class: " + beanClass, e);
+      }
       // bind
       // TODO: Again, the jndi-names for the no-interface view are a mess now. They need to come from
       // the metadata. Let's just go ahead temporarily
-      String noInterfaceJndiName = sessionBeanMetadata.getEjbName() + "/no-interface";
-      // Bind a reference to nonserializable using NonSerializableFactory as the ObjectFactory
-      NamingParser namingParser = new NamingParser();
-      Name jndiName = namingParser.parse(noInterfaceJndiName);
-      NonSerializableFactory.rebind(jndiName, noInterfaceView, true);
+      String noInterfaceJndiName = sessionBeanMetadata.getEjbName() + NO_INTERFACE_JNDI_SUFFIX;
+      NonSerializableFactory.rebind(this.jndiCtx, noInterfaceJndiName, noInterfaceView, true);
 
       logger.info("Bound the no-interface view for bean " + beanClass + " to jndi at " + noInterfaceJndiName);
 
    }
 
+   /**
+    * Unbinds the no-interface view proxy from the JNDI
+    * 
+    * @see org.jboss.ejb3.nointerface.mc.NoInterfaceViewJNDIBinder#unbindNoInterfaceView()
+    */
+   @Override
+   public void unbindNoInterfaceView() throws NamingException
+   {
+      this.jndiCtx.unbind(this.sessionBeanMetadata.getEjbName() + NO_INTERFACE_JNDI_SUFFIX);
+      
+   }
+
 }




More information about the jboss-cvs-commits mailing list