[jboss-cvs] JBossAS SVN: r58323 - in projects/microcontainer/trunk/aop-mc-int/src: main/org/jboss/aop/microcontainer/beans main/org/jboss/aop/microcontainer/integration resources/tests/org/jboss/test/microcontainer/test tests/org/jboss/test/microcontainer/support tests/org/jboss/test/microcontainer/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 13 19:42:28 EST 2006


Author: kabir.khan at jboss.com
Date: 2006-11-13 19:42:17 -0500 (Mon, 13 Nov 2006)
New Revision: 58323

Added:
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.xml
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.properties
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.xml
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/BeanNoDefaultCtorUsingParam.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.java
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.java
Modified:
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/IntroductionBinding.java
   projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java
Log:
[JBAOP-307] Solve NPE where mc instantiates a bean w/ ctor injection and the proxied class has no default ctors, and tries to use the params in its ctor by overriding all ctors in the proxy

Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/IntroductionBinding.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/IntroductionBinding.java	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/beans/IntroductionBinding.java	2006-11-14 00:42:17 UTC (rev 58323)
@@ -43,6 +43,16 @@
    
    protected List<String> interfaces;
 
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
    /**
     * Get the classes.
     * 

Modified: projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/main/org/jboss/aop/microcontainer/integration/AOPConstructorJoinpoint.java	2006-11-14 00:42:17 UTC (rev 58323)
@@ -50,6 +50,7 @@
    AOPProxyFactory proxyFactory = new GeneratedAOPProxyFactory();
 
    MetaDataContext metaDataContext;
+   
    /**
     * Create a new AOPConstructorJoinpoint.
     *
@@ -70,9 +71,8 @@
          return super.dispatch();
       }
       ContainerCache cache = ContainerCache.initialise(manager, clazz, metaDataContext);
-      Object target = createTarget(cache);
-
       AOPProxyFactoryParameters params = new AOPProxyFactoryParameters();
+      Object target = createTarget(cache, params);
 
       params.setProxiedClass(target.getClass());
       params.setMetaDataContext(metaDataContext);
@@ -82,12 +82,13 @@
       return proxyFactory.createAdvisedProxy(params);
    }
 
-   private Object createTarget(ContainerCache cache) throws Throwable
+   private Object createTarget(ContainerCache cache, AOPProxyFactoryParameters params) throws Throwable
    {
       Advisor advisor = cache.getAdvisor();
       if (advisor != null)
       {
          org.jboss.aop.ConstructorInfo aopinfo = findAopConstructorInfo(advisor);
+         
          Interceptor[] interceptors = (aopinfo != null) ? aopinfo.getInterceptors() : null;
 
          if (interceptors != null)
@@ -96,6 +97,30 @@
             inv.setArguments(getArguments());
             return inv.invokeNext();
          }
+         
+         if (getConstructorInfo().getParameterTypes().length > 0)
+         {
+            Constructor constructor = null;
+            if (aopinfo == null)
+            {
+               //Fall back to using the class;
+               Class clazz = advisor.getClazz();
+               Constructor[] ctors = clazz.getConstructors();
+               for (Constructor ctor : ctors)
+               {
+                  if (matchConstructor(ctor))
+                  {
+                     constructor = ctor;
+                     break;
+                  }
+               }
+            }
+            else
+            {
+               constructor = aopinfo.getConstructor();
+            }
+            params.setCtor(constructor.getParameterTypes(), getArguments());
+         }
       }
 
       return super.dispatch();
@@ -103,31 +128,39 @@
 
    private org.jboss.aop.ConstructorInfo findAopConstructorInfo(Advisor advisor)
    {
-      TypeInfo[] params = constructorInfo.getParameterTypes();
       org.jboss.aop.ConstructorInfo[] infos = advisor.getConstructorInfos();
       for (int i = 0 ; i < infos.length ; i++)
       {
-         Constructor ctor = infos[i].getConstructor();
-         Class[] ctorParams = ctor.getParameterTypes();
-         if (params.length == ctorParams.length)
+         if (matchConstructor(infos[i].getConstructor()))
          {
-            boolean match = true;
-            for (int p = 0 ; p < params.length ; p++)
+            return infos[i];
+         }
+      }
+      return null;
+   }
+   
+   private boolean matchConstructor(Constructor ctor)
+   {
+      TypeInfo[] params = constructorInfo.getParameterTypes();
+      Class[] ctorParams = ctor.getParameterTypes();
+      if (params.length == ctorParams.length)
+      {
+         boolean match = true;
+         for (int p = 0 ; p < params.length ; p++)
+         {
+            if (!params[p].getName().equals(ctorParams[p].getName()))
             {
-               if (!params[p].getName().equals(ctorParams[p].getName()))
-               {
-                  match = false;
-                  break;
-               }
+               match = false;
+               break;
             }
+         }
 
-            if (match)
-            {
-               return infos[i];
-            }
+         if (match)
+         {
+            return true;
          }
       }
-      return null;
+      return false;
    }
 
 }

Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.xml	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.xml	2006-11-14 00:42:17 UTC (rev 58323)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+      <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+   </bean>
+
+   <aop:aspect xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="InterceptedAdvice"
+               class="org.jboss.test.microcontainer.support.CalledInterceptor"
+               pointcut="execution(* org.jboss.test.microcontainer.support.BeanNoDefaultCtorUsingParam->*(..))">
+   </aop:aspect>
+
+   <bean name="Bean" class="org.jboss.test.microcontainer.support.BeanNoDefaultCtorUsingParam">
+      <constructor>
+         <parameter>Kabir was here</parameter>
+      </constructor>
+   </bean>
+</deployment>

Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.properties
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.properties	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.properties	2006-11-14 00:42:17 UTC (rev 58323)
@@ -0,0 +1 @@
+test.Permission.1=javax.management.MBeanPermission, *#*, getMBeanInfo,invoke,registerMBean
\ No newline at end of file

Added: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.xml	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.xml	2006-11-14 00:42:17 UTC (rev 58323)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+   <bean name="MBeanServer" class="java.lang.Object">
+      <constructor factoryClass="javax.management.MBeanServerFactory" factoryMethod="createMBeanServer"/>
+   </bean>
+
+   <bean name="Repository" class="org.jboss.metadata.plugins.repository.basic.BasicMetaDataRepository"/>
+
+   <bean name="AspectManager" class="org.jboss.aop.AspectManager">
+      <constructor factoryClass="org.jboss.aop.AspectManager" factoryMethod="instance"/>
+   </bean>
+
+   <aop:lifecycle xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="JMXAdvice"
+               class="org.jboss.aop.microcontainer.aspects.jmx.JMXIntroduction"
+               classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX"
+               pointcut="execution(* @org.jboss.aop.microcontainer.aspects.jmx.JMX->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))">
+      <property name="mbeanServer"><inject bean="MBeanServer"/></property>
+   </aop:lifecycle>
+
+   <aop:lifecycle xmlns:aop="urn:jboss:aop-beans:1.0"
+               name="JndiAdvice"
+               class="org.jboss.test.microcontainer.support.CalledInterceptor"
+               classes="org.jboss.test.microcontainer.support.SimpleBeanImpl"
+               pointcut="execution(* org.jboss.test.microcontainer.support.SimpleBeanImpl->$implements{org.jboss.kernel.spi.dependency.KernelControllerContextAware}(..))">
+   </aop:lifecycle>
+
+   <bean name="Bean" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="", exposedInterface=org.jboss.test.microcontainer.support.SimpleBean.class)</annotation>
+   </bean>
+</deployment>

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/BeanNoDefaultCtorUsingParam.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/BeanNoDefaultCtorUsingParam.java	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/support/BeanNoDefaultCtorUsingParam.java	2006-11-14 00:42:17 UTC (rev 58323)
@@ -0,0 +1,43 @@
+/*
+* 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.test.microcontainer.support;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanNoDefaultCtorUsingParam
+{
+   int length;
+   
+   public BeanNoDefaultCtorUsingParam(String s)
+   {
+      length = s.length();
+   }
+   
+   public int getLength()
+   {
+      return length;
+   }
+   
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.java	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/BeanNoDefaultCtorUsingParamTestCase.java	2006-11-14 00:42:17 UTC (rev 58323)
@@ -0,0 +1,54 @@
+/*
+* 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.test.microcontainer.test;
+
+import org.jboss.aop.microcontainer.junit.AOPMicrocontainerTest;
+import org.jboss.test.microcontainer.support.BeanNoDefaultCtorUsingParam;
+import org.jboss.test.microcontainer.support.CalledInterceptor;
+
+import junit.framework.Test;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanNoDefaultCtorUsingParamTestCase extends AOPMicrocontainerTest
+{
+   public static Test suite()
+   {
+      return suite(BeanNoDefaultCtorUsingParamTestCase.class);
+   }
+   
+   public BeanNoDefaultCtorUsingParamTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testIntercepted()
+   {
+      BeanNoDefaultCtorUsingParam bean = (BeanNoDefaultCtorUsingParam) getBean("Bean");
+      CalledInterceptor.intercepted = false;
+      assertEquals(14, bean.getLength());
+      assertTrue("Should have invoked the CalledInterceptor", CalledInterceptor.intercepted);
+   }
+}

Added: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.java	2006-11-14 00:37:46 UTC (rev 58322)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/MultipleLifecycleTestCase.java	2006-11-14 00:42:17 UTC (rev 58323)
@@ -0,0 +1,58 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., 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.test.microcontainer.test;
+
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+
+import org.jboss.aop.microcontainer.junit.AOPMicrocontainerTest;
+
+public class MultipleLifecycleTestCase extends AOPMicrocontainerTest
+{
+   public static Test suite()
+   {
+      return suite(MultipleLifecycleTestCase.class);
+   }
+   
+   public MultipleLifecycleTestCase(String name)
+   {
+      super(name);
+   }
+   
+   
+   public void testBean() throws Exception
+   {
+      MBeanServer server = (MBeanServer) getBean("MBeanServer");
+      assertNotNull(server);
+
+      ObjectName name = new ObjectName("test:name='Bean'");
+      MBeanInfo info = server.getMBeanInfo(name);
+      assertNotNull(info);
+      MBeanOperationInfo[] ops = info.getOperations();
+      assertEquals(1, ops.length);
+      assertEquals("someMethod", ops[0].getName());
+   }
+}




More information about the jboss-cvs-commits mailing list