[jboss-cvs] JBossAS SVN: r72671 - in projects/ejb3/trunk/core/src: test/java/org/jboss/ejb3/test/bank and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 24 08:21:26 EDT 2008


Author: alex.loubyansky at jboss.com
Date: 2008-04-24 08:21:26 -0400 (Thu, 24 Apr 2008)
New Revision: 72671

Added:
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21Base.java
Modified:
   projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DescriptorHandler.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/Bank.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/FirstInterceptor.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/SecondInterceptor.java
   projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java
Log:
EJBTHREE-1307

Modified: projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DescriptorHandler.java
===================================================================
--- projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DescriptorHandler.java	2008-04-24 11:14:25 UTC (rev 72670)
+++ projects/ejb3/trunk/core/src/main/java/org/jboss/ejb3/Ejb3DescriptorHandler.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -925,54 +925,50 @@
     */
    private void addEjb21Annotations(EJBContainer container, boolean isStateful) throws Exception
    {
-      Class<?>[] interfaces = ejbClass.getInterfaces();
-      for (Class<?> beanInterface : interfaces)
+      if(javax.ejb.SessionBean.class.isAssignableFrom(ejbClass))
       {
-         if (beanInterface.equals(javax.ejb.SessionBean.class))
-         {
-            MethodMetaData method = new MethodMetaData();
-            method.setEjbName(container.getEjbName());
+         MethodMetaData method = new MethodMetaData();
+         method.setEjbName(container.getEjbName());
 
-            Annotation annotation;
-            Class<? extends Annotation> annotationClass;
-            // EJB3 4.6.2: The class may implement the ejbCreate method(s).
-            // EJB3 4.6.4: The method must be declared as public.
-            if(hasPublicMethod(ejbClass, "ejbCreate"))
+         Annotation annotation;
+         Class<? extends Annotation> annotationClass;
+         // EJB3 4.6.2: The class may implement the ejbCreate method(s).
+         // EJB3 4.6.4: The method must be declared as public.
+         if(hasPublicMethod(ejbClass, "ejbCreate"))
+         {
+            if(isStateful)
             {
-               if(isStateful)
-               {
-                  annotation = new InitImpl();
-               }
-               else
-               {
-                  annotation = new PostConstructImpl();
-               }
-               annotationClass = annotation.annotationType();
-               method.setMethodName("ejbCreate");
-               addAnnotations(annotationClass, annotation, container, method);
+               annotation = new InitImpl();
             }
-
-            annotation = new PostActivateImpl();
-            annotationClass = javax.ejb.PostActivate.class;
-            method.setMethodName("ejbActivate");
+            else
+            {
+               annotation = new PostConstructImpl();
+            }
+            annotationClass = annotation.annotationType();
+            method.setMethodName("ejbCreate");
             addAnnotations(annotationClass, annotation, container, method);
+         }
 
-            annotation = new PrePassivateImpl();
-            annotationClass = javax.ejb.PrePassivate.class;
-            method.setMethodName("ejbPassivate");
-            addAnnotations(annotationClass, annotation, container, method);
+         annotation = new PostActivateImpl();
+         annotationClass = javax.ejb.PostActivate.class;
+         method.setMethodName("ejbActivate");
+         addAnnotations(annotationClass, annotation, container, method);
 
-            annotation = new PreDestroyImpl();
-            annotationClass = javax.annotation.PreDestroy.class;
-            method.setMethodName("ejbRemove");
-            addAnnotations(annotationClass, annotation, container, method);
+         annotation = new PrePassivateImpl();
+         annotationClass = javax.ejb.PrePassivate.class;
+         method.setMethodName("ejbPassivate");
+         addAnnotations(annotationClass, annotation, container, method);
+
+         annotation = new PreDestroyImpl();
+         annotationClass = javax.annotation.PreDestroy.class;
+         method.setMethodName("ejbRemove");
+         addAnnotations(annotationClass, annotation, container, method);
             
-            annotation = new ResourceImpl();
-            annotationClass = Resource.class;
-            method.setMethodName("setSessionContext");
-            // TODO: set param?
-            addAnnotations(annotationClass, annotation, container, method);
-         }
+         annotation = new ResourceImpl();
+         annotationClass = Resource.class;
+         method.setMethodName("setSessionContext");
+         // TODO: set param?
+         addAnnotations(annotationClass, annotation, container, method);
       }
    }
 

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/Bank.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/Bank.java	2008-04-24 11:14:25 UTC (rev 72670)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/Bank.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -45,7 +45,9 @@
    public String retrieveCustomerId() throws RemoteException;
    
    public String interceptCustomerId(String customerId) throws RemoteException;
-   
+
+   public boolean hasSessionContext() throws RemoteException;
+
    public void testResource() throws Exception;
    
    public void remove();
@@ -53,7 +55,7 @@
    public String isInitialized();
    
    public String isActivated();
-   
+
    public void testTransactionTimeout();
    
    public String getTransactionState();

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean.java	2008-04-24 11:14:25 UTC (rev 72670)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -27,13 +27,10 @@
 import javax.annotation.Resource;
 import javax.ejb.EJBException;
 import javax.ejb.Init;
-import javax.ejb.Remove;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import javax.sql.DataSource;
-import javax.transaction.UserTransaction;
 
-import org.jboss.logging.Logger;
 import org.jboss.ejb3.Container;
 
 /**
@@ -43,8 +40,6 @@
  */
 public class BankBean implements Bank, Serializable, javax.ejb.SessionSynchronization
 {
-   private static final Logger log = Logger.getLogger(BankBean.class);
-
    transient public DataSource customerDb;
 
    static final String ID = Container.ENC_CTX_NAME + "/env/org.jboss.ejb3.test.bank/id";
@@ -63,7 +58,6 @@
    
    private String transactionState = "failed";
    private String rollbackState;
-   private boolean beforeCalled = false;
 
    public String getId()
    {
@@ -152,6 +146,11 @@
       }
    }
    
+   public boolean hasSessionContext()
+   {
+      return false;
+   }
+   
    public void afterBegin() throws EJBException, RemoteException
    {
       rollbackState = transactionState;
@@ -159,7 +158,6 @@
 
    public void beforeCompletion() throws EJBException, RemoteException
    {
-      beforeCalled = true;
    }
 
    public void afterCompletion(boolean committed) throws EJBException, RemoteException

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21.java	2008-04-24 11:14:25 UTC (rev 72670)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -24,22 +24,16 @@
 import java.rmi.*;
 import java.sql.Connection;
 
-import javax.naming.*;
 import javax.ejb.Init;
-import javax.ejb.SessionContext;
 import javax.sql.DataSource;
 
-import org.jboss.logging.Logger;
-
 /**
  * @see <related>
  * @author $Author$
  * @version $Revision$
  */
-public class BankBean21 implements javax.ejb.SessionBean
+public class BankBean21 extends BankBean21Base
 {
-   private static final Logger log = Logger.getLogger(BankBean21.class);
-   
    public DataSource customerDb;
    
    static final String ID = "java:comp/env/id";
@@ -52,10 +46,6 @@
 
    static long nextCustomerId = System.currentTimeMillis();
    
-   String initialized = "";
-   
-   private String activated = "";
-
    public String getId()
    {
       return id;
@@ -92,10 +82,9 @@
       Connection connection = customerDb.getConnection();
       connection.close();
    }
-   
+
    public void remove()
-   {
-      
+   {      
    }
    
    @Init
@@ -108,41 +97,6 @@
    {
       initialized += "YES";
    }
-   
-   public String isInitialized()
-   {
-      return initialized;
-   }
-   
-   public String isActivated()
-   {
-      return activated;
-   }
-   
-   public void ejbCreate()
-   {
-      activated += "_CREATED";
-   }
-   
-   public void ejbActivate()
-   {
-      activated += "_ACTIVATED";
-   }
-   
-   public void ejbPassivate()
-   {
-      
-   }
-   
-   public void ejbRemove()
-   {
-      
-   }
-   
-   public void setSessionContext(SessionContext context)
-   {
-      
-   }
 }
 
 /*

Added: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21Base.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21Base.java	                        (rev 0)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/BankBean21Base.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.bank;
+
+import java.rmi.RemoteException;
+
+import javax.ejb.SessionContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author $Author: alex at jboss.com $
+ * @version $Revision: 61136 $
+ */
+public class BankBean21Base implements javax.ejb.SessionBean
+{
+   protected static final Logger log = Logger.getLogger(BankBean21Base.class);
+   protected String initialized = "";
+   private String activated = "";
+   protected SessionContext ctx;
+
+   public BankBean21Base()
+   {
+      super();
+   }
+   
+   public String isInitialized()
+   {
+      return initialized;
+   }
+
+   public String isActivated()
+   {
+      return activated;
+   }
+
+   public boolean hasSessionContext() throws RemoteException
+   {
+      return ctx != null;
+   }
+
+   public void ejbCreate()
+   {
+      activated += "_CREATED";
+   }
+
+   public void ejbActivate()
+   {
+      activated += "_ACTIVATED";
+   }
+
+   public void ejbPassivate()
+   {
+   }
+
+   public void ejbRemove()
+   {
+   }
+
+   public void setSessionContext(SessionContext context)
+   {
+      this.ctx = context;
+   }
+}
\ No newline at end of file

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/FirstInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/FirstInterceptor.java	2008-04-24 11:14:25 UTC (rev 72670)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/FirstInterceptor.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -23,25 +23,19 @@
 
 import javax.interceptor.InvocationContext;
 
-import org.jboss.logging.Logger;
-
 /**
  * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
  * @version $Revision$
  */
-public class FirstInterceptor {
-   
-   private static final Logger log = Logger
-   .getLogger(FirstInterceptor.class);
-
+public class FirstInterceptor
+{
    public Object oneMethod(InvocationContext ctx) throws Exception
    {
-      String concat = "";
+      Object result = ctx.proceed();
       if (ctx.getMethod().getName().equals("interceptCustomerId"))
       {
-         concat = "_FirstInterceptor";
+         result = result + "_FirstInterceptor";
       }
-      Object result = ctx.proceed() + concat;
       return result;
    }
 }

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/SecondInterceptor.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/SecondInterceptor.java	2008-04-24 11:14:25 UTC (rev 72670)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/SecondInterceptor.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -23,25 +23,19 @@
 
 import javax.interceptor.InvocationContext;
 
-import org.jboss.logging.Logger;
-
 /**
  * @author <a href="mailto:kabir.khan at jboss.org">Kabir Khan</a>
  * @version $Revision$
  */
-public class SecondInterceptor {
-   
-   private static final Logger log = Logger
-   .getLogger(SecondInterceptor.class);
-
+public class SecondInterceptor
+{
    public Object twoMethod(InvocationContext ctx) throws Exception
    {
-      String concat = "";
+      Object result = ctx.proceed();
       if (ctx.getMethod().getName().equals("interceptCustomerId"))
       {
-         concat = "_SecondInterceptor";
+         result = result + "_SecondInterceptor";
       }
-      Object result = ctx.proceed() + concat;
       return result;
    }
 }

Modified: projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java
===================================================================
--- projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java	2008-04-24 11:14:25 UTC (rev 72670)
+++ projects/ejb3/trunk/core/src/test/java/org/jboss/ejb3/test/bank/unit/BankDeploymentDescriptorTestCase.java	2008-04-24 12:21:26 UTC (rev 72671)
@@ -161,8 +161,6 @@
       sc.setSimple(new SimplePrincipal("rolefail"), "password".toCharArray());
       sc.login();
       
-      String customerId = "CustomerId";
-      String greeting;
       Teller teller = (Teller) jndiContext.lookup(Teller.JNDI_NAME);
       assertNotNull(teller);
       
@@ -402,6 +400,14 @@
       }
    }
 
+   public void testSessionContextForEjb21() throws Exception
+   {
+      InitialContext jndiContext = new InitialContext();
+      Bank bank = (Bank) jndiContext.lookup(Bank.JNDI_NAME + "21");
+      assertNotNull(bank);
+      assertTrue("setSessionContext(ctx) should have been invoked", bank.hasSessionContext());
+   }
+
    public static Test suite() throws Exception
    {
       ClientKernelAbstraction kernel = KernelAbstractionFactory.getClientInstance();




More information about the jboss-cvs-commits mailing list