[jboss-cvs] JBossAS SVN: r68647 - in projects/ejb3/trunk/interceptors/src: main/java/org/jboss/ejb3/interceptors/aop and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jan 7 03:48:32 EST 2008


Author: wolfc
Date: 2008-01-07 03:48:32 -0500 (Mon, 07 Jan 2008)
New Revision: 68647

Added:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/aop/
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/aop/ManagedObjectContainer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/package.html
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/MyInterface.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedBean.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java
   projects/ejb3/trunk/interceptors/src/test/resources/proxy/
   projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml
Modified:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorSequencer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml
Log:
First working proxy container

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java	2008-01-07 05:11:39 UTC (rev 68646)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/AbstractInterceptorFactory.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -46,7 +46,7 @@
 
    public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
    {
-      throw new IllegalStateException("Per joinpoint scope not supported");
+      throw new IllegalStateException("Per joinpoint scope not supported on " + this);
    }
 
    public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp)

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java	2008-01-07 05:11:39 UTC (rev 68646)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InjectInterceptorsFactory.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -109,6 +109,13 @@
       }
    }
    
+   @Override
+   public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
+   {
+      log.warn("WEIRDNESS IN AOP: advisor " + advisor);
+      return new InterceptorSequencer(new Interceptor[0]);
+   }
+   
    private static final boolean isExcludeClassInterceptors(Advisor advisor, Method method)
    {
       return advisor.hasAnnotation(method, ExcludeClassInterceptors.class);

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorSequencer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorSequencer.java	2008-01-07 05:11:39 UTC (rev 68646)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorSequencer.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -77,4 +77,10 @@
    {
       return invoke(invocation);
    }
+   
+   @Override
+   public String toString()
+   {
+      return super.toString() + "[interceptors=" + Arrays.toString(interceptors) + "]";
+   }
 }

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java	2008-01-07 05:11:39 UTC (rev 68646)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -63,10 +63,11 @@
          for(Class<?> interceptorClass : interceptorsAnnotation.value())
          {
             Object interceptor = interceptorClass.newInstance();
-            Advisor interceptorAdvisor = ((Advised) interceptor)._getAdvisor();
+            //Advisor interceptorAdvisor = ((Advised) interceptor)._getAdvisor();
+            Advisor interceptorAdvisor = advisor.getManager().getAdvisor(interceptorClass);
             log.debug("  interceptorAdvisor = " + interceptorAdvisor.getName());
-            InstanceAdvisor interceptorInstanceAdvisor = ((Advised) interceptor)._getInstanceAdvisor();
-            log.debug("  interceptorInstanceAdvisor = " + interceptorInstanceAdvisor.getClass().getName());
+//            InstanceAdvisor interceptorInstanceAdvisor = ((Advised) interceptor)._getInstanceAdvisor();
+//            log.debug("  interceptorInstanceAdvisor = " + interceptorInstanceAdvisor.getClass().getName());
             // TODO: should be only non-overriden methods (EJB 3 12.4.1 last bullet)
             for(Method method : ClassHelper.getAllMethods(interceptorClass))
             {

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java	2008-01-07 05:11:39 UTC (rev 68646)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InvocationContextInterceptor.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -1,6 +1,7 @@
 package org.jboss.ejb3.interceptors.aop;
 
 import java.lang.reflect.Method;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -165,7 +166,7 @@
       
       public String toString()
       {
-         return invocation.toString();
+         return "[target=" + getTarget() + ", method=" + method + ", parameters=" + Arrays.toString(params) + ", contextData=" + contextData + "]";
       }
    }
 }

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.interceptors.proxy;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.ConstructionInfo;
+import org.jboss.aop.Domain;
+import org.jboss.aop.DomainDefinition;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.ConstructionInvocation;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.interceptors.proxy.aop.ManagedObjectContainer;
+import org.jboss.logging.Logger;
+
+/**
+ * An interceptor proxy container.
+ * 
+ * Decouple AOP from EJB3, so Advisor methods are hidden and the
+ * Advisor life-cycle is controlled.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ProxyContainer
+{
+   private static final Logger log = Logger.getLogger(ProxyContainer.class);
+   
+   private Advisor advisor;
+   
+   private class ProxyInvocationHandler implements InvocationHandler
+   {
+      private Object target;
+      
+      public ProxyInvocationHandler(Object target)
+      {
+         assert target != null : "target is null";
+         
+         this.target = target;
+      }
+      
+      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+      {
+         return ProxyContainer.this.invoke(target, method, args);
+      }
+   }
+   
+   public ProxyContainer(String name, Domain domain, Class<?> beanClass)
+   {
+      assert domain != null : "domain is null";
+      assert beanClass != null : "beanClass is null";
+      
+      ManagedObjectContainer delegate = new ManagedObjectContainer(name, domain, beanClass);
+      this.advisor = delegate;
+   }
+   
+   public ProxyContainer(String name, String domainName, Class<?> beanClass)
+   {
+      this(name, getDomain(domainName), beanClass);
+   }
+   
+   @SuppressWarnings("unchecked")
+   public <I> I constructProxy(Class<?> interfaces[]) throws Throwable
+   {
+      // assert interfaces contains I
+      Object args[] = null;
+      int idx = 0; // TODO: find default constructor
+      // ClassAdvisor
+      ConstructionInfo constructionInfo = advisor.getConstructionInfos()[idx];
+      Interceptor[] cInterceptors = constructionInfo.getInterceptors();
+      if (cInterceptors == null) cInterceptors = new Interceptor[0];
+      log.debug("constructor interceptors " + Arrays.toString(cInterceptors));
+      Constructor<?> constructor = advisor.getConstructors()[idx];
+      ConstructionInvocation invocation = new ConstructionInvocation(cInterceptors, constructor);
+      
+      invocation.setAdvisor(advisor);
+      invocation.setArguments(args);
+      // First we create the instance
+      Object instance = constructor.newInstance();
+      invocation.setTargetObject(instance);
+      // then we do (construction) interception
+      invocation.invokeNext();
+      
+      ClassLoader loader = Thread.currentThread().getContextClassLoader();
+      //Class<?> interfaces[] = { intf };
+      Object proxy = Proxy.newProxyInstance(loader, interfaces, new ProxyInvocationHandler(instance));
+      return (I) proxy;
+   }
+   
+   /*
+    * TODO: this should not be here, it's an AspectManager helper function.
+    */
+   private static final Domain getDomain(String domainName)
+   {
+      DomainDefinition domainDefinition = AspectManager.instance().getContainer(domainName);
+      if(domainDefinition == null)
+         throw new IllegalArgumentException("Domain definition '" + domainName + "' can not be found");
+      
+      final Domain domain = (Domain) domainDefinition.getManager();
+      return domain;
+   }
+   
+   protected Object invoke(Object target, Method method, Object arguments[]) throws Throwable
+   {
+      long methodHash = MethodHashing.calculateHash(method);
+      MethodInfo info = advisor.getMethodInfo(methodHash);
+      MethodInvocation invocation = new MethodInvocation(info, info.getInterceptors());
+      invocation.setArguments(arguments);
+      invocation.setTargetObject(target);
+      return invocation.invokeNext();
+   }
+}


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

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/aop/ManagedObjectContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/aop/ManagedObjectContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/aop/ManagedObjectContainer.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.interceptors.proxy.aop;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.ClassAdvisor;
+import org.jboss.aop.Domain;
+import org.jboss.aop.InstanceAdvisor;
+import org.jboss.aop.InstanceAdvisorDelegate;
+import org.jboss.aop.advice.AspectDefinition;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ManagedObjectContainer extends ClassAdvisor implements InstanceAdvisor
+{
+   private static final Logger log = Logger.getLogger(ManagedObjectContainer.class);
+   
+   private InstanceAdvisorDelegate instanceAdvisorDelegate;
+   
+   public ManagedObjectContainer(String name, AspectManager manager, Class<?> beanClass)
+   {
+      super(name, manager);
+      assert beanClass != null : "beanClass is null";
+      // Poking starts here
+      attachClass(beanClass);
+      
+      this.instanceAdvisorDelegate = new InstanceAdvisorDelegate(this, this);
+   }
+
+   public void appendInterceptor(Interceptor interceptor)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public void appendInterceptor(int index, Interceptor interceptor)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public void appendInterceptorStack(String stackName)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public Domain getDomain()
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public Object getInstance()
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public Interceptor[] getInterceptors()
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public Interceptor[] getInterceptors(Interceptor[] baseChain)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public SimpleMetaData getMetaData()
+   {
+      return instanceAdvisorDelegate.getMetaData();
+   }
+
+   public Object getPerInstanceAspect(String aspectName)
+   {
+      // TODO: is this correct?
+      return instanceAdvisorDelegate.getPerInstanceAspect(aspectName);
+   }
+
+   public Object getPerInstanceAspect(AspectDefinition def)
+   {
+      return instanceAdvisorDelegate.getPerInstanceAspect(def);
+   }
+
+   public Object getPerInstanceJoinpointAspect(Joinpoint joinpoint, AspectDefinition def)
+   {
+      return instanceAdvisorDelegate.getPerInstanceJoinpointAspect(joinpoint, def);
+   }
+
+   public boolean hasInterceptors()
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public void insertInterceptor(Interceptor interceptor)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public void insertInterceptor(int index, Interceptor interceptor)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public void insertInterceptorStack(String stackName)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public void removeInterceptor(String name)
+   {
+      throw new RuntimeException("NYI");
+   }
+
+   public void removeInterceptorStack(String name)
+   {
+      throw new RuntimeException("NYI");
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/aop/ManagedObjectContainer.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/package.html
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/package.html	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/package.html	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,7 @@
+<html>
+	<body>
+		Interceptors by proxy are not the same as interceptors on a POJO. With POJO Interceptors
+		any call to the object is intercepted. With proxy interceptors only calls through the proxy
+		are intercepted.
+	</body>
+</html>
\ No newline at end of file

Modified: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicInterceptor.java	2008-01-07 05:11:39 UTC (rev 68646)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/basic/BasicInterceptor.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -52,6 +52,8 @@
    public void postConstruct(InvocationContext ctx) throws Exception
    {
       log.debug("postConstruct " + ctx);
+      if(ctx.getTarget() == null)
+         throw new IllegalStateException("target is null");
       try { ctx.getMethod(); throw new Exception("should not come here"); } catch(IllegalStateException e) { }
       postConstructs++;
       ctx.proceed();

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/MyInterface.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/MyInterface.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/MyInterface.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.interceptors.proxy;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface MyInterface
+{
+   String sayHi(String name);
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/MyInterface.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedBean.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedBean.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.interceptors.proxy;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.interceptors.ManagedObject;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Interceptors(ProxiedInterceptor.class)
+ at ManagedObject
+public class ProxiedBean implements MyInterface
+{
+   private static final Logger log = Logger.getLogger(ProxiedBean.class);
+   
+   public static int constructors = 0, aroundInvokes = 0;
+   
+   public ProxiedBean()
+   {
+      log.debug("ProxiedBean");
+      constructors++;
+   }
+   
+   @AroundInvoke
+   Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      log.debug("aroundInvoke " + ctx);
+      if(ctx.getTarget() != this)
+         throw new IllegalStateException("target is not this");
+      if(ctx.getMethod().getDeclaringClass() != getClass())
+         throw new IllegalStateException("method " + ctx.getMethod() + " not of this class (" + ctx.getMethod().getDeclaringClass() + " != " +  getClass() + ")");
+      aroundInvokes++;
+      return ctx.proceed();
+   }
+   
+   public String sayHi(String name)
+   {
+      log.debug("sayHi");
+      return "Hi " + name;
+   }
+   /*
+   @Interceptors(BasicMethodInterceptor.class)
+   public void intercept()
+   {
+      log.debug("intercept");
+   }
+   */
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedBean.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedInterceptor.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.interceptors.proxy;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * A basic interceptor, does nothing useful.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ProxiedInterceptor
+{
+   private static final Logger log = Logger.getLogger(ProxiedInterceptor.class);
+   
+   public static int preDestroys = 0, postConstructs = 0, aroundInvokes = 0;
+   
+   @PreDestroy
+   public void preDestroy(InvocationContext ctx) throws Exception
+   {
+      log.debug("preDestroy " + ctx);
+      preDestroys++;
+      ctx.proceed();
+   }
+   
+   @PostConstruct
+   public void postConstruct(InvocationContext ctx) throws Exception
+   {
+      log.debug("postConstruct " + ctx);
+      try { ctx.getMethod(); throw new Exception("should not come here"); } catch(IllegalStateException e) { }
+      postConstructs++;
+      ctx.proceed();
+   }
+   
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      log.debug("aroundInvoke " + ctx);
+      aroundInvokes++;
+      return ctx.proceed();
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/ProxiedInterceptor.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, 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.interceptors.proxy.unit;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.proxy.ProxyContainer;
+import org.jboss.ejb3.test.interceptors.proxy.MyInterface;
+import org.jboss.ejb3.test.interceptors.proxy.ProxiedBean;
+import org.jboss.ejb3.test.interceptors.proxy.ProxiedInterceptor;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ProxyTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(ProxyTestCase.class);
+
+   public void test1() throws Throwable
+   {
+      //AspectManager.verbose = true;
+      
+      // Bootstrap AOP
+      URL url = Thread.currentThread().getContextClassLoader().getResource("proxy/jboss-aop.xml");
+      log.info("deploying AOP from " + url);
+      AspectXmlLoader.deployXML(url);
+
+      Thread.currentThread().setContextClassLoader(MyInterface.class.getClassLoader());
+      
+      ProxyContainer container = new ProxyContainer("ProxyTestCase", "InterceptorContainer", ProxiedBean.class);
+      
+      assertEquals(0, ProxiedInterceptor.postConstructs);
+      
+      Class<?> interfaces[] = { MyInterface.class };
+      MyInterface proxy = container.constructProxy(interfaces);
+      
+      assertEquals("ProxiedInterceptor postConstruct must have been called once", 1, ProxiedInterceptor.postConstructs);
+      
+      String result = proxy.sayHi("Me");
+      assertEquals("Hi Me", result);
+      
+      assertEquals("sayHi didn't invoke ProxiedInterceptor.aroundInvoke once", 1, ProxiedInterceptor.aroundInvokes);
+      assertEquals("sayHi didn't invoke ProxiedBean.aroundInvoke once", 1, ProxiedBean.aroundInvokes);
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml	2008-01-07 05:11:39 UTC (rev 68646)
+++ projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml	2008-01-07 08:48:32 UTC (rev 68647)
@@ -103,17 +103,25 @@
   -->
 
   <category name="org.jboss.aop">
-    <priority value="ALL"/>
+    <priority value="INFO"/>
   </category>
   
   <category name="org.jboss">
-    <priority value="ALL"/>
+    <priority value="INFO"/>
   </category>
   
   <category name="org.jboss.ejb3.interceptors.aop.DomainClassLoader">
     <priority value="INFO"/>
   </category>
   
+  <category name="org.jboss.ejb3.test">
+    <priority value="WARN"/>
+  </category>
+  
+  <category name="org.jboss.ejb3.test.interceptors.proxy">
+    <priority value="ALL"/>
+  </category>
+  
   <!-- ======================= -->
   <!-- Setup the Root category -->
   <!-- ======================= -->

Added: projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml	2008-01-07 08:48:32 UTC (rev 68647)
@@ -0,0 +1,118 @@
+<aop>
+	<aspect name="AroundInvokeInterceptor" class="org.jboss.ejb3.interceptors.aop.AroundInvokeInterceptor" scope="PER_INSTANCE"/>
+	<aspect name="InjectInterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory" scope="PER_JOINPOINT"/>
+	<aspect name="InterceptorsFactory" factory="org.jboss.ejb3.interceptors.aop.InterceptorsFactory" scope="PER_INSTANCE"/>
+	<aspect name="InterceptorsInterceptor" class="org.jboss.ejb3.interceptors.aop.InterceptorsInterceptor" scope="PER_INSTANCE"/>
+	<aspect name="InvocationContextInterceptor" class="org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor" scope="PER_VM"/>
+	<aspect name="PostConstructInterceptor" class="org.jboss.ejb3.interceptors.aop.PostConstructInterceptor" scope="PER_INSTANCE"/>
+	
+	<!-- Create AOP interceptors out of spec interceptors -->
+	<aspect name="ClassInterceptors" factory="org.jboss.ejb3.interceptors.aop.InjectInterceptorsFactory" scope="PER_INSTANCE">
+		<attribute name="interceptors" value="class"/>
+	</aspect>
+	<aspect name="DefaultInterceptors" factory="org.jboss.ejb3.interceptors.aop.DefaultInterceptorsFactory" scope="PER_INSTANCE"/>
+	
+	<!-- TODO: deprecated -->
+	<interceptor name="BootstrapInterceptor" class="org.jboss.ejb3.interceptors.aop.BootstrapInterceptor" scope="PER_VM"/>
+	
+	<!-- test only -->
+	<interceptor name="LoggingInterceptor" class="org.jboss.ejb3.test.interceptors.common.aop.LoggingInterceptor" scope="PER_VM"/>
+	
+	<!-- TODO: this is actually the bootstrap container -->
+	<domain name="InterceptorContainer">
+		<pointcut name="beanAroundInvokeCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.interceptor.AroundInvoke(..))"/>
+		<pointcut name="beanPostConstructCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.interceptor.PostConstruct(..))"/>
+		<pointcut name="beanPreDestroyCallbackMethods" expr="execution(* @org.jboss.ejb3.interceptors.ManagedObject->@javax.interceptor.PreDestroy(..))"/>
+		
+		<pointcut name="beanLifecycleCallbackMethods" expr="beanAroundInvokeCallbackMethods OR beanPostConstructCallbackMethods OR beanPreDestroyCallbackMethods"/>
+		
+		<!-- Does the class define class interceptors or business method interceptors -->
+		<!-- TODO: or we have defaultInterceptors -->
+		<!-- No longer support, must be set explitcitly 
+		<annotation-introduction expr="has(@javax.interceptor.Interceptors->new(..)) OR has(* *->@javax.interceptor.Interceptors(..))">
+			@org.jboss.ejb3.interceptors.ManagedObject
+		</annotation-introduction>
+		-->
+		
+		<!-- Prepare for dynamic AOP -->
+		<!-- TODO: optimize, we only need managed objects (and interceptors!) to be aspectized -->
+		<!-- prepare expr="all(*) AND has(@org.jboss.ejb3.interceptors.ManagedObject->new(..))"/ -->
+		<prepare expr="all(*)"/>
+		
+		<!-- Make sure we can _preDestroy -->
+		<introduction expr="constructor(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
+			<interfaces>org.jboss.ejb3.interceptors.aop.Destructable</interfaces>
+		</introduction>
+		
+		<!-- Why does this not work? -->
+		<!-- 
+		<bind pointcut="execution(@javax.interceptor.Interceptors->new(..))">
+			<interceptor-ref name="LoggingInterceptor"/>
+			<interceptor-ref name="BootstrapInterceptor"/>
+		</bind>
+		-->
+		
+		<!-- This one does work -->
+		<!-- Setup AOP interceptors based on spec interceptors -->
+		<bind pointcut="construction(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
+			<!-- interceptor-ref name="LoggingInterceptor"/ -->
+			<!-- TODO: we don't need invocation context here -->
+			<!-- TODO: we do until we've seperated the post constructs -->
+			<around name="setup" aspect="InvocationContextInterceptor"/>
+			<around name="invoke" aspect="InterceptorsFactory"/>
+		</bind>
+		
+		<!-- Lifecycle Event Callbacks (EJB 3 12.4) -->
+		
+		<bind pointcut="construction(@org.jboss.ejb3.interceptors.ManagedObject->new(..))">
+			<interceptor-ref name="LoggingInterceptor"/>
+			<around name="setup" aspect="InvocationContextInterceptor"/>
+			<around name="postConstruct" aspect="InjectInterceptorsFactory"/>
+		</bind>
+		
+		<!-- TODO: Junk
+		<bind pointcut="execution(* *->@javax.interceptor.Interceptors(..))">
+			<interceptor-ref name="LoggingInterceptor"/>
+			<around name="setup" aspect="InvocationContextInterceptor"/>
+			<around name="invoke" aspect="AroundInvokeInterceptor"/>
+		</bind>
+		-->
+		
+		<!-- Make sure we an invocation context   -->
+		<!-- 
+		<bind pointcut="execution(* *->@javax.interceptor.Interceptors(..))">
+			<around name="setup" aspect="InvocationContextInterceptor"/>
+			<around name="fillMethod" aspect="InvocationContextInterceptor"/>
+		</bind>
+		-->
+		
+		<bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..))">
+			<around name="setup" aspect="InvocationContextInterceptor"/>
+			<around name="fillMethod" aspect="InvocationContextInterceptor"/>
+		</bind>
+		
+		<!-- The bootstrap interceptor container doesn't do default interceptors
+		<bind pointcut="!execution(* *->@javax.interceptor.ExcludeDefaultInterceptors(..)) AND !execution(* @javax.interceptor.ExcludeDefaultInterceptors(..))">
+			<around name="invokeDefaultInterceptors" aspect="InterceptorsInterceptor"/>
+		</bind>
+		-->
+		
+		<!-- TODO: Deprecated, use InjectInterceptorsFactory
+		<bind pointcut="!execution(* *->@javax.interceptor.ExcludeClassInterceptors(..))">
+			<around name="invokeClassInterceptors" aspect="InterceptorsInterceptor"/>
+		</bind>
+		-->
+		
+		<!-- 
+		<bind pointcut="execution(* *->*(..)) AND has(* *->@javax.interceptor.Interceptors(..))">
+			<around name="invokeBusinessMethodInterceptors" aspect="InterceptorsInterceptor"/>
+		</bind>
+		-->
+		
+		<bind pointcut="execution(* @org.jboss.ejb3.interceptors.ManagedObject->*(..)) AND !beanLifecycleCallbackMethods">
+			<around name="setup" aspect="InvocationContextInterceptor"/>
+			<around name="fillMethod" aspect="InvocationContextInterceptor"/>
+			<around name="aroundInvoke" aspect="InjectInterceptorsFactory"/>
+		</bind>
+	</domain>
+</aop>
\ No newline at end of file


Property changes on: projects/ejb3/trunk/interceptors/src/test/resources/proxy/jboss-aop.xml
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native




More information about the jboss-cvs-commits mailing list