[jboss-cvs] JBossAS SVN: r58301 - projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 13 11:52:48 EST 2006


Author: kabir.khan at jboss.com
Date: 2006-11-13 11:52:45 -0500 (Mon, 13 Nov 2006)
New Revision: 58301

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java
Log:
Make ContainerProxyFactory more flexible wrt several introductions with the same interface

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java	2006-11-13 15:48:36 UTC (rev 58300)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java	2006-11-13 16:52:45 UTC (rev 58301)
@@ -92,6 +92,8 @@
    /** True if we are proxying a class already woven by jboss aop, false otherwise */
    private boolean isAdvised;
    
+   private CtConstructor defaultCtor;
+   
    public static Class getProxyClass(Class clazz, AspectManager manager) throws Exception
    {
       ContainerProxyCacheKey key = new ContainerProxyCacheKey(clazz);
@@ -364,14 +366,14 @@
          superCall.append(");");
          superCall.append("_proxy_initialised = true;");
          
-         CtConstructor ctor = CtNewConstructor.make(EMPTY_CTCLASS_ARRAY, EMPTY_CTCLASS_ARRAY, "{" + superCall.toString() + "}", proxy);
-         proxy.addConstructor(ctor);
+         defaultCtor = CtNewConstructor.make(EMPTY_CTCLASS_ARRAY, EMPTY_CTCLASS_ARRAY, "{" + superCall.toString() + "}", proxy);
+         proxy.addConstructor(defaultCtor);
       }
       else
       {
-         CtConstructor ctor = CtNewConstructor.defaultConstructor(proxy);
-         ctor.setBody("{_proxy_initialised = true;}");
-         proxy.addConstructor(ctor);
+         defaultCtor = CtNewConstructor.defaultConstructor(proxy);
+         defaultCtor.setBody("{_proxy_initialised = true;}");
+         proxy.addConstructor(defaultCtor);
       }
    }
 
@@ -421,8 +423,7 @@
          }
          if (mixes.size() > 0)
          {
-            CtConstructor con = CtNewConstructor.defaultConstructor(proxy);
-            con.insertAfter("mixins = new Object[" + mixes.size() + "];");
+            defaultCtor.insertAfter("mixins = new Object[" + mixes.size() + "];");
             for (int i = 0; i < mixes.size(); i++)
             {
                //If using a constructor and passing "this" as the parameters, the proxy gets used. The delegate (instance wrapped by proxy) is not 
@@ -430,11 +431,10 @@
                InterfaceIntroduction.Mixin mixin = (InterfaceIntroduction.Mixin) mixes.get(i);
                String initializer = (mixin.getConstruction() == null) ? ("new " + mixin.getClassName() + "()") : mixin.getConstruction();
                String code = "mixins[" + i + "] = " + initializer + ";";
-               con.insertAfter(code);
+               defaultCtor.insertAfter(code);
                setDelegateMethod.insertAfter("{if (org.jboss.aop.proxy.container.Delegate.class.isAssignableFrom(mixins[" + i + "].getClass())) " +
                      "((org.jboss.aop.proxy.container.Delegate)mixins[" + i + "]).setDelegate($1);}");
             }
-            proxy.addConstructor(con);
          }
          
          createMixins(addedMethods, mixes, addedInterfaces, implementedInterfaces);
@@ -453,14 +453,6 @@
     */
    private void getIntroductionInterfaces(InterfaceIntroduction intro, HashMap intfs, HashMap mixins, ArrayList mixes, int idx)
    {
-      if (intro.getInterfaces() != null)
-      {
-         for (int i = 0; i < intro.getInterfaces().length; i++)
-         {
-            if (intfs.containsKey(intro.getInterfaces()[i]) || mixins.containsKey(intro.getInterfaces()[i])) throw new RuntimeException("cannot have an IntroductionInterface that introduces same interfaces");
-            intfs.put(intro.getInterfaces()[i], new Integer(idx));
-         }
-      }
       Iterator it = intro.getMixins().iterator();
       while (it.hasNext())
       {
@@ -468,10 +460,32 @@
          mixes.add(mixin);
          for (int i = 0; i < mixin.getInterfaces().length; i++)
          {
-            if (intfs.containsKey(mixin.getInterfaces()[i]) || mixins.containsKey(mixin.getInterfaces()[i])) throw new RuntimeException("cannot have an IntroductionInterface that introduces same interfaces");
+            if (intfs.containsKey(mixin.getInterfaces()[i]))
+            {
+               intfs.remove(mixin.getInterfaces()[i]);
+               
+            }
+            if (mixins.containsKey(mixin.getInterfaces()[i]))
+            {
+               throw new RuntimeException("cannot have an IntroductionInterface that introduces several mixins with the same interfaces " + mixin.getInterfaces()[i]);
+            }
             mixins.put(mixin.getInterfaces()[i], new Integer(idx));
          }
       }
+      if (intro.getInterfaces() != null)
+      {
+         for (int i = 0; i < intro.getInterfaces().length; i++)
+         {
+            if (intfs.containsKey(intro.getInterfaces()[i]) || mixins.containsKey(intro.getInterfaces()[i])) 
+            {
+               //Do nothing
+            }
+            else
+            {
+               intfs.put(intro.getInterfaces()[i], new Integer(idx));
+            }
+         }
+      }
    }
 
    private void createMixins(HashSet addedMethods, ArrayList mixes, HashSet addedInterfaces, Set implementedInterfaces) throws Exception




More information about the jboss-cvs-commits mailing list