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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 10 09:38:18 EST 2008


Author: wolfc
Date: 2008-01-10 09:38:17 -0500 (Thu, 10 Jan 2008)
New Revision: 68820

Added:
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactoryRef.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/DefaultInterceptorFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerInterceptorFactory.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/InterceptorFactoryRefImpl.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/container/AbstractContainer.java
   projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/DirectContainer.java
Log:
Redirect creation of interceptors back to the container

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactory.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -0,0 +1,42 @@
+/*
+ * 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;
+
+import org.jboss.aop.Advisor;
+
+
+/**
+ * Creates instances of interceptors and thus forming a life cycle
+ * callback of the interceptor.
+ * 
+ * Currently it's not possible to have have interceptors on interceptors,
+ * so it's impossible to perform an action in the 'post construct' of
+ * the interceptor itself.
+ * To counter this you can use an interceptor factory.
+ * 
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface InterceptorFactory
+{
+   Object create(Advisor advisor, Class<?> interceptorClass) throws InstantiationException, IllegalAccessException;
+}


Property changes on: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactory.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/InterceptorFactoryRef.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactoryRef.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactoryRef.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -0,0 +1,48 @@
+/*
+ * 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;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.jboss.ejb3.interceptors.aop.DefaultInterceptorFactory;
+
+/**
+ * Specify an interceptor factory to instantiate interceptors with.
+ * 
+ * Currently it's not allowed to have have interceptors on interceptors,
+ * so it's impossible to perform an action in the 'post construct' of
+ * the interceptor itself.
+ * To counter this you can specify an interceptor factory to use.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at Documented
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(ElementType.TYPE)
+public @interface InterceptorFactoryRef {
+   Class<? extends InterceptorFactory> value() default DefaultInterceptorFactory.class;
+}


Property changes on: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/InterceptorFactoryRef.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/aop/DefaultInterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/DefaultInterceptorFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/DefaultInterceptorFactory.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -0,0 +1,41 @@
+/*
+ * 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.aop;
+
+import org.jboss.aop.Advisor;
+import org.jboss.ejb3.interceptors.InterceptorFactory;
+
+
+/**
+ * The default interceptor factory just creates a new instance
+ * of the interceptor class.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class DefaultInterceptorFactory implements InterceptorFactory
+{
+   public Object create(Advisor advisor, Class<?> interceptorClass) throws InstantiationException, IllegalAccessException
+   {
+      return interceptorClass.newInstance();
+   }
+}


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

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-10 14:32:25 UTC (rev 68819)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/aop/InterceptorsFactory.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -36,6 +36,8 @@
 import org.jboss.aop.advice.Interceptor;
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
+import org.jboss.ejb3.interceptors.InterceptorFactory;
+import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
 import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisor;
 import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisorHelper;
 import org.jboss.ejb3.interceptors.lang.ClassHelper;
@@ -61,6 +63,11 @@
          
          // TODO: the whole interceptor advisor & annotation stuff is butt ugly
          
+         InterceptorFactoryRef interceptorFactoryRef = (InterceptorFactoryRef) advisor.resolveAnnotation(InterceptorFactoryRef.class);
+         if(interceptorFactoryRef == null)
+            throw new IllegalStateException("No InterceptorFactory specified on " + advisor.getName());
+         InterceptorFactory interceptorFactory = interceptorFactoryRef.value().newInstance();
+         
          Interceptors interceptorsAnnotation = (Interceptors) advisor.resolveAnnotation(Interceptors.class);
          assert interceptorsAnnotation != null : "interceptors annotation not found"; // FIXME: not correct, bean can be without interceptors
          Map<Class<?>, Object> interceptors = new HashMap<Class<?>, Object>();
@@ -72,7 +79,7 @@
             Object interceptor = interceptors.get(interceptorClass);
             if(interceptor == null)
             {
-               interceptor = interceptorClass.newInstance();
+               interceptor = interceptorFactory.create(advisor, interceptorClass);
                interceptors.put(interceptorClass, interceptor);
             }
             //Advisor interceptorAdvisor = ((Advised) interceptor)._getAdvisor();
@@ -111,7 +118,7 @@
                   Object interceptor = interceptors.get(interceptorClass);
                   if(interceptor == null)
                   {
-                     interceptor = interceptorClass.newInstance();
+                     interceptor = interceptorFactory.create(advisor, interceptorClass);
                      interceptors.put(interceptorClass, interceptor);
                   }
                   //Advisor interceptorAdvisor = ((Advised) interceptor)._getAdvisor();

Modified: 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	2008-01-10 14:32:25 UTC (rev 68819)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/AbstractContainer.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -24,6 +24,7 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
 
+import org.jboss.aop.Advisor;
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.ClassAdvisor;
 import org.jboss.aop.Domain;
@@ -33,6 +34,7 @@
 import org.jboss.aop.joinpoint.ConstructionInvocation;
 import org.jboss.aop.joinpoint.MethodInvocation;
 import org.jboss.aop.util.MethodHashing;
+import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
 import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisor;
 import org.jboss.ejb3.interceptors.annotation.AnnotationAdvisorSupport;
 import org.jboss.ejb3.interceptors.lang.ClassHelper;
@@ -98,6 +100,11 @@
       }
    }
    
+   protected Object createInterceptor(Class<?> interceptorClass) throws InstantiationException, IllegalAccessException
+   {
+      return interceptorClass.newInstance();
+   }
+   
    /**
     * Finalize construction of the abstract container by setting the advisor.
     * 
@@ -116,6 +123,7 @@
       // Decouple setting the advisor and initializing it, so interceptors
       // can get it.
       this.advisor = new ManagedObjectAdvisor<T, C>((C) this, name, domain);
+      advisor.getAnnotations().addClassAnnotation(InterceptorFactoryRef.class, new InterceptorFactoryRefImpl(ContainerInterceptorFactory.class));
       advisor.initialize(beanClass);
    }
    
@@ -131,6 +139,12 @@
       return getAdvisor().getClazz();
    }
    
+   @SuppressWarnings("unchecked")
+   public static <C extends AbstractContainer<?, ?>> C getContainer(Advisor advisor)
+   {
+      return (C) ((ManagedObjectAdvisor) advisor).getContainer();
+   }
+   
    /*
     * TODO: this should not be here, it's an AspectManager helper function.
     */

Added: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerInterceptorFactory.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerInterceptorFactory.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerInterceptorFactory.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -0,0 +1,40 @@
+/*
+ * 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 org.jboss.aop.Advisor;
+import org.jboss.ejb3.interceptors.InterceptorFactory;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ContainerInterceptorFactory implements InterceptorFactory
+{
+   public Object create(Advisor advisor, Class<?> interceptorClass) throws InstantiationException, IllegalAccessException
+   {
+      AbstractContainer<?, ?> container = AbstractContainer.getContainer(advisor);
+      return container.createInterceptor(interceptorClass);
+   }
+}


Property changes on: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/ContainerInterceptorFactory.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/container/InterceptorFactoryRefImpl.java
===================================================================
--- projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/InterceptorFactoryRefImpl.java	                        (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/container/InterceptorFactoryRefImpl.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -0,0 +1,54 @@
+/*
+ * 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.annotation.Annotation;
+
+import org.jboss.ejb3.interceptors.InterceptorFactory;
+import org.jboss.ejb3.interceptors.InterceptorFactoryRef;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorFactoryRefImpl implements InterceptorFactoryRef
+{
+   private Class<? extends InterceptorFactory> interceptorFactoryClass;
+
+   public InterceptorFactoryRefImpl(Class<? extends InterceptorFactory> interceptorFactoryClass)
+   {
+      assert interceptorFactoryClass != null : "interceptorFactoryClass is null";
+      this.interceptorFactoryClass = interceptorFactoryClass;
+   }
+   
+   public Class<? extends InterceptorFactory> value()
+   {
+      return interceptorFactoryClass;
+   }
+
+   public Class<? extends Annotation> annotationType()
+   {
+      return InterceptorFactoryRef.class;
+   }
+}


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

Modified: 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/DirectContainer.java	2008-01-10 14:32:25 UTC (rev 68819)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/DirectContainer.java	2008-01-10 14:38:17 UTC (rev 68820)
@@ -21,9 +21,7 @@
  */
 package org.jboss.ejb3.interceptors.direct;
 
-import org.jboss.aop.Advisor;
 import org.jboss.aop.Domain;
-import org.jboss.ejb3.interceptors.container.ManagedObjectAdvisor;
 import org.jboss.logging.Logger;
 
 /**
@@ -49,9 +47,11 @@
       super(name, domainName, beanClass);
    }
    
+   /*
    @SuppressWarnings("unchecked")
    public static <C extends DirectContainer<?>> C getContainer(Advisor advisor)
    {
       return (C) ((ManagedObjectAdvisor<?, DirectContainer<C>>) advisor).getContainer();
    }
+   */
 }




More information about the jboss-cvs-commits mailing list