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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 8 05:04:25 EST 2008


Author: wolfc
Date: 2008-01-08 05:04:25 -0500 (Tue, 08 Jan 2008)
New Revision: 68671

Added:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/DirectContainer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/package.html
   projects/ejb3/trunk/interceptors/src/main/resources/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectBean.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectMethodInterceptor.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/DirectTestCase.java
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/lang/ClassHelper.java
   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/ManagedObjectContainer.java
   projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java
   projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml
Log:
Added direct container

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-08 06:20:33 UTC (rev 68670)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -29,7 +29,6 @@
 import javax.interceptor.AroundInvoke;
 import javax.interceptor.Interceptors;
 
-import org.jboss.aop.Advised;
 import org.jboss.aop.Advisor;
 import org.jboss.aop.InstanceAdvisor;
 import org.jboss.aop.advice.Interceptor;
@@ -97,7 +96,8 @@
                {
                   // FIXME: do not create perse, we might already have done that
                   Object interceptor = interceptorClass.newInstance();
-                  Advisor interceptorAdvisor = ((Advised) interceptor)._getAdvisor();
+                  //Advisor interceptorAdvisor = ((Advised) interceptor)._getAdvisor();
+                  Advisor interceptorAdvisor = advisor.getManager().getAdvisor(interceptorClass);
                   for(Method method : ClassHelper.getAllMethods(interceptorClass))
                   {
                      /* EJB 3 12.7 footnote 57: no lifecycle callbacks on business method interceptors

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,120 @@
+/*
+ * 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.container;
+
+import java.lang.reflect.Method;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.ClassAdvisor;
+import org.jboss.aop.Domain;
+import org.jboss.aop.DomainDefinition;
+import org.jboss.aop.MethodInfo;
+import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.interceptors.lang.ClassHelper;
+import org.jboss.ejb3.interceptors.proxy.aop.ManagedObjectContainer;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public abstract class AbstractContainer<T>
+{
+   private static final Logger log = Logger.getLogger(AbstractContainer.class);
+   
+   private ManagedObjectContainer advisor;
+   
+   public AbstractContainer(String name, Domain domain, Class<? extends T> beanClass)
+   {
+      assert name != null : "name is null";
+      assert domain != null : "domain is null";
+      assert beanClass != null : "beanClass is null";
+      
+      this.advisor = new ManagedObjectContainer(name, domain, beanClass);
+   }
+   
+   public AbstractContainer(String name, String domainName, Class<? extends T> beanClass)
+   {
+      this(name, getDomain(domainName), beanClass);
+   }
+   
+   protected final ClassAdvisor getAdvisor()
+   {
+      return advisor;
+   }
+   
+   /*
+    * 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;
+   }
+   
+   /**
+    * Call a method upon a target object with all interceptors in place.
+    * 
+    * @param target     the target to invoke upon
+    * @param method     the method to invoke
+    * @param arguments  arguments to the method
+    * @return           return value of the method
+    * @throws Throwable if anything goes wrong
+    */
+   public Object invoke(Object target, Method method, Object arguments[]) throws Throwable
+   {
+      long methodHash = MethodHashing.calculateHash(method);
+      MethodInfo info = advisor.getMethodInfo(methodHash);
+      if(info == null)
+         throw new IllegalArgumentException("method " + method + " is not under advisement by " + this);
+      MethodInvocation invocation = new MethodInvocation(info, info.getInterceptors());
+      invocation.setArguments(arguments);
+      invocation.setTargetObject(target);
+      return invocation.invokeNext();
+   }
+   
+   /**
+    * A convenient, but unchecked and slow method to call a method upon a target.
+    * 
+    * (Slow method)
+    * 
+    * @param <R>        the return type
+    * @param target     the target to invoke upon
+    * @param methodName the method name to invoke
+    * @param args       the arguments to the method
+    * @return           the return value
+    * @throws Throwable if anything goes wrong
+    */
+   @SuppressWarnings("unchecked")
+   public <R> R invoke(Object target, String methodName, Object ... args) throws Throwable
+   {
+      Method method = ClassHelper.getMethod(target.getClass(), methodName);
+      return (R) invoke(target, method, args);
+   }
+}


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

Copied: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/DirectContainer.java (from rev 68670, projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/DirectContainer.java)
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/DirectContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/DirectContainer.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,125 @@
+/*
+ * 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.direct;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
+import org.jboss.aop.ClassAdvisor;
+import org.jboss.aop.Domain;
+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.container.AbstractContainer;
+import org.jboss.logging.Logger;
+
+/**
+ * The direct container invokes interceptors directly on an instance.
+ * 
+ * It's useful in an environment where we don't want to fiddle with the
+ * classloader and still have control on how instances are called.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DirectContainer<T> extends AbstractContainer<T>
+{
+   private static final Logger log = Logger.getLogger(DirectContainer.class);
+   
+   public DirectContainer(String name, Domain domain, Class<? extends T> beanClass)
+   {
+      super(name, domain, beanClass);
+   }
+   
+   public DirectContainer(String name, String domainName, Class<? extends T> beanClass)
+   {
+      super(name, domainName, beanClass);
+   }
+   
+   public T construct() throws SecurityException, NoSuchMethodException
+   {
+      return construct(null, null);
+   }
+   
+   @SuppressWarnings("unchecked")
+   public T construct(Object initargs[], Class<?> parameterTypes[]) throws SecurityException, NoSuchMethodException
+   {
+      ClassAdvisor advisor = getAdvisor();
+      Constructor<T> constructor = advisor.getClazz().getConstructor(parameterTypes);
+      int idx = advisor.getConstructorIndex(constructor);
+      assert idx != -1 : "can't find constructor in the advisor";
+      try
+      {
+         T targetObject = (T) advisor.invokeNew(initargs, idx);
+         
+         Interceptor interceptors[] = advisor.getConstructionInfos()[idx].getInterceptors();
+         ConstructionInvocation invocation = new ConstructionInvocation(interceptors, constructor, initargs);
+         invocation.setAdvisor(advisor);
+         invocation.setTargetObject(targetObject);
+         invocation.invokeNext();
+         
+         if(targetObject instanceof IndirectContainer)
+            ((IndirectContainer<T>) targetObject).setDirectContainer(this);
+         
+         return targetObject;
+      }
+      catch(Throwable t)
+      {
+         // TODO: disect
+         if(t instanceof RuntimeException)
+            throw (RuntimeException) t;
+         throw new RuntimeException(t);
+      }
+   }
+   
+   /**
+    * Do not call, for use in indirect container implementations.
+    * @return
+    */
+   public Class<?> getBeanClass()
+   {
+      return getAdvisor().getClazz();
+   }
+   
+   // FIXME: copy of ProxyContainer.invoke
+   public Object invokeIndirect(Object target, Method method, Object arguments[]) throws Throwable
+   {
+      long methodHash = MethodHashing.calculateHash(method);
+      MethodInfo info = getAdvisor().getMethodInfo(methodHash);
+      if(info == null)
+         throw new IllegalArgumentException("method " + method + " is not under advisement by " + this);
+      MethodInvocation invocation = new MethodInvocation(info, info.getInterceptors())
+      {
+         @Override
+         public Object invokeTarget() throws Throwable
+         {
+            // TODO: invoke the real target in special modus
+            return null;
+         }
+      };
+      invocation.setArguments(arguments);
+      invocation.setTargetObject(target);
+      return invocation.invokeNext();
+   }
+}

Copied: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java (from rev 68670, projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/interceptors/direct/IndirectContainer.java)
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,35 @@
+/*
+ * 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.direct;
+
+
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface IndirectContainer<T>
+{
+   void setDirectContainer(DirectContainer<T> container);
+}

Modified: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java	2008-01-08 06:20:33 UTC (rev 68670)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/lang/ClassHelper.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -50,6 +50,36 @@
    }
    
    /**
+    * Returns the method with the specified method name.
+    * 
+    * (Slow method)
+    * 
+    * @param methodName
+    * @return
+    * @throws NoSuchMethodException 
+    */
+   public static Method getMethod(Class<?> cls, String methodName) throws NoSuchMethodException
+   {
+      if(cls == null)
+         throw new NoSuchMethodException(methodName);
+      Method methods[] = cls.getDeclaredMethods();
+      for(Method method : methods)
+      {
+         if(method.getName().equals(methodName))
+            return method;
+         // TODO: shall we continue search for ambiguous match?
+      }
+      try
+      {
+         return getMethod(cls.getSuperclass(), methodName);
+      }
+      catch(NoSuchMethodException e)
+      {
+         throw new NoSuchMethodException("No method named " + methodName + " in " + cls + " (or super classes)");
+      }
+   }
+   
+   /**
     * Find all methods starting with the most general super class.
     * (See 12.4.1 bullet 4)
     * 

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/package.html
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/package.html	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/package.html	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,18 @@
+<html>
+	<body>
+		<h3>EJB 3 Interceptors</h3>
+		<h4>Level 1: Instrumented</h4>
+		This creates instrumented classes. Any call to an instrumented class
+		is intercepted. This includes calls which a bean makes to itself.
+		<h4>Level 2: Container instrumentation</h4>
+		With container instrumentation the user had to maintain control
+		of how objects are constructed and invoked. All invocations going
+		through the container are intercepted. 
+		<h5>Direct container</h5>
+		Call an object through the container 'directly'.
+		<h5>Proxy container</h5>
+		Call an object through a proxy which directs it to the container.
+		<h4>Level 3: Indirect container instrumentation</h4>
+		TODO
+	</body>
+</html>
\ No newline at end of file

Modified: 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	2008-01-08 06:20:33 UTC (rev 68670)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/ProxyContainer.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -27,17 +27,12 @@
 import java.lang.reflect.Proxy;
 import java.util.Arrays;
 
-import org.jboss.aop.Advisor;
-import org.jboss.aop.AspectManager;
+import org.jboss.aop.ClassAdvisor;
 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.ejb3.interceptors.container.AbstractContainer;
 import org.jboss.logging.Logger;
 
 /**
@@ -49,12 +44,10 @@
  * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
  * @version $Revision: $
  */
-public class ProxyContainer
+public class ProxyContainer<T> extends AbstractContainer<T>
 {
    private static final Logger log = Logger.getLogger(ProxyContainer.class);
    
-   private Advisor advisor;
-   
    private class ProxyInvocationHandler implements InvocationHandler
    {
       private Object target;
@@ -72,18 +65,14 @@
       }
    }
    
-   public ProxyContainer(String name, Domain domain, Class<?> beanClass)
+   public ProxyContainer(String name, Domain domain, Class<? extends T> beanClass)
    {
-      assert domain != null : "domain is null";
-      assert beanClass != null : "beanClass is null";
-      
-      ManagedObjectContainer delegate = new ManagedObjectContainer(name, domain, beanClass);
-      this.advisor = delegate;
+      super(name, domain, beanClass);
    }
    
-   public ProxyContainer(String name, String domainName, Class<?> beanClass)
+   public ProxyContainer(String name, String domainName, Class<? extends T> beanClass)
    {
-      this(name, getDomain(domainName), beanClass);
+      super(name, domainName, beanClass);
    }
    
    @SuppressWarnings("unchecked")
@@ -92,6 +81,7 @@
       // assert interfaces contains I
       Object args[] = null;
       int idx = 0; // TODO: find default constructor
+      ClassAdvisor advisor = getAdvisor();
       // ClassAdvisor
       ConstructionInfo constructionInfo = advisor.getConstructionInfos()[idx];
       Interceptor[] cInterceptors = constructionInfo.getInterceptors();
@@ -113,27 +103,4 @@
       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();
-   }
 }

Modified: 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	2008-01-08 06:20:33 UTC (rev 68670)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/proxy/aop/ManagedObjectContainer.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -33,6 +33,7 @@
 import org.jboss.aop.introduction.AnnotationIntroduction;
 import org.jboss.aop.joinpoint.Joinpoint;
 import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.ejb3.interceptors.ManagedObject;
 import org.jboss.logging.Logger;
 
 /**
@@ -51,6 +52,9 @@
    {
       super(name, manager);
       assert beanClass != null : "beanClass is null";
+      
+      annotations.addClassAnnotation(ManagedObject.class, new Object());
+      
       // Poking starts here
       attachClass(beanClass);
       
@@ -59,6 +63,7 @@
 
    private void deployAnnotationIntroduction(AnnotationIntroduction introduction)
    {
+      log.debug("deploy annotation introduction " + introduction);
       // Poke introductions into the overrides
       deployAnnotationOverride(introduction);
    }

Added: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectBean.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectBean.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectBean.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,76 @@
+/*
+ * 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.direct;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptors;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * The direct bean has one class interceptor: DirectInterceptor
+ * 
+ * On the intercepter method there is a business method interceptor: DirectMethodInterceptor
+ * 
+ * And it has bean method interceptors: aroundInvoke
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Interceptors(DirectInterceptor.class)
+public class DirectBean
+{
+   private static final Logger log = Logger.getLogger(DirectBean.class);
+   
+   public static int constructors = 0, aroundInvokes = 0;
+   
+   public DirectBean()
+   {
+      log.debug("DirectBean");
+      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(DirectMethodInterceptor.class)
+   public void intercept()
+   {
+      log.debug("intercept");
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectBean.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/direct/DirectInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectInterceptor.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,69 @@
+/*
+ * 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.direct;
+
+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 DirectInterceptor
+{
+   private static final Logger log = Logger.getLogger(DirectInterceptor.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);
+      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();
+   }
+   
+   @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/direct/DirectInterceptor.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/direct/DirectMethodInterceptor.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectMethodInterceptor.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectMethodInterceptor.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,56 @@
+/*
+ * 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.direct;
+
+import javax.annotation.PostConstruct;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+import org.jboss.logging.Logger;
+
+/**
+ * To be put on a method.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DirectMethodInterceptor
+{
+   private static final Logger log = Logger.getLogger(DirectMethodInterceptor.class);
+   
+   public static int postConstructs = 0, aroundInvokes = 0;
+   
+   @PostConstruct
+   public void postConstruct(InvocationContext ctx) throws Exception
+   {
+      log.info("postConstruct");
+      postConstructs++;
+   }
+   
+   @AroundInvoke
+   public Object aroundInvoke(InvocationContext ctx) throws Exception
+   {
+      log.info("aroundInvoke");
+      aroundInvokes++;
+      return ctx.proceed();
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/DirectMethodInterceptor.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/direct/unit/DirectTestCase.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/DirectTestCase.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/direct/unit/DirectTestCase.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -0,0 +1,89 @@
+/*
+ * 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.direct.unit;
+
+import java.net.URL;
+import java.util.Arrays;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectManager;
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.direct.DirectContainer;
+import org.jboss.ejb3.test.interceptors.direct.DirectBean;
+import org.jboss.ejb3.test.interceptors.direct.DirectInterceptor;
+import org.jboss.ejb3.test.interceptors.direct.DirectMethodInterceptor;
+import org.jboss.logging.Logger;
+
+/**
+ * Test direct container advisement.
+ * 
+ * There is no special class loader needed, because all invocations
+ * are routed through the direct container.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DirectTestCase extends TestCase
+{
+   private static final Logger log = Logger.getLogger(DirectTestCase.class);
+   
+   public void test() throws Throwable
+   {
+      AspectManager.verbose = true;
+      
+      // Bootstrap AOP
+      // FIXME: use the right jboss-aop.xml
+      URL url = Thread.currentThread().getContextClassLoader().getResource("proxy/jboss-aop.xml");
+      log.info("deploying AOP from " + url);
+      AspectXmlLoader.deployXML(url);
+      
+      assertEquals(0, DirectInterceptor.postConstructs);
+      
+      DirectContainer<DirectBean> container = new DirectContainer<DirectBean>("DirectBean", "InterceptorContainer", DirectBean.class);
+      
+      DirectBean bean = container.construct();
+      
+      assertEquals("DirectInterceptor postConstruct must have been called once", 1, DirectInterceptor.postConstructs);
+      
+      System.out.println(bean.getClass() + " " + bean.getClass().getClassLoader());
+      System.out.println("  " + Arrays.toString(bean.getClass().getInterfaces()));
+      String result = container.invoke(bean, "sayHi", "Test");
+      System.out.println(result);
+      
+      assertEquals("sayHi didn't invoke DirectInterceptor.aroundInvoke once", 1, DirectInterceptor.aroundInvokes);
+      assertEquals("sayHi didn't invoke DirectBean.aroundInvoke once", 1, DirectBean.aroundInvokes);
+      
+      container.invoke(bean, "intercept");
+      assertEquals("intercept didn't invoke DirectMethodInterceptor.aroundInvoke", 1, DirectMethodInterceptor.aroundInvokes);
+      container.invoke(bean, "intercept");
+      assertEquals("intercept didn't invoke DirectMethodInterceptor.aroundInvoke", 2, DirectMethodInterceptor.aroundInvokes);
+      
+      assertEquals("intercept didn't invoke DirectInterceptor.aroundInvoke", 3, DirectInterceptor.aroundInvokes);
+      assertEquals("DirectInterceptor postConstruct must have been called once", 1, DirectInterceptor.postConstructs);
+      // 12.7 footnote 57
+      assertEquals("DirectMethodInterceptor.postConstruct must not have been called", 0, DirectMethodInterceptor.postConstructs);
+      
+      //((Destructable) bean)._preDestroy();
+      bean = null;
+   }
+}


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

Modified: 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	2008-01-08 06:20:33 UTC (rev 68670)
+++ projects/ejb3/trunk/interceptors/src/test/java/org/jboss/ejb3/test/interceptors/proxy/unit/ProxyTestCase.java	2008-01-08 10:04:25 UTC (rev 68671)
@@ -53,7 +53,7 @@
 
       Thread.currentThread().setContextClassLoader(MyInterface.class.getClassLoader());
       
-      ProxyContainer container = new ProxyContainer("ProxyTestCase", "InterceptorContainer", ProxiedBean.class);
+      ProxyContainer<ProxiedBean> container = new ProxyContainer<ProxiedBean>("ProxyTestCase", "InterceptorContainer", ProxiedBean.class);
       
       assertEquals(0, ProxiedInterceptor.postConstructs);
       

Modified: projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml
===================================================================
--- projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml	2008-01-08 06:20:33 UTC (rev 68670)
+++ projects/ejb3/trunk/interceptors/src/test/resources/log4j.xml	2008-01-08 10:04:25 UTC (rev 68671)
@@ -103,7 +103,7 @@
   -->
 
   <category name="org.jboss.aop">
-    <priority value="INFO"/>
+    <priority value="ALL"/>
   </category>
   
   <category name="org.jboss">
@@ -118,7 +118,7 @@
     <priority value="WARN"/>
   </category>
   
-  <category name="org.jboss.ejb3.test.interceptors.proxy">
+  <category name="org.jboss.ejb3.test.interceptors">
     <priority value="ALL"/>
   </category>
   




More information about the jboss-cvs-commits mailing list