[jboss-cvs] JBossAS SVN: r68676 - projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 8 08:34:02 EST 2008
Author: wolfc
Date: 2008-01-08 08:34:01 -0500 (Tue, 08 Jan 2008)
New Revision: 68676
Added:
projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java
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/IndirectContainer.java
Log:
Added AbstractDirectContainer
Copied: projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java (from rev 68675, 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/AbstractDirectContainer.java (rev 0)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/AbstractDirectContainer.java 2008-01-08 13:34:01 UTC (rev 68676)
@@ -0,0 +1,124 @@
+/*
+ * 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 abstract class AbstractDirectContainer<T, C extends AbstractDirectContainer<T, C>> extends AbstractContainer<T, C>
+{
+ private static final Logger log = Logger.getLogger(AbstractDirectContainer.class);
+
+ protected AbstractDirectContainer(String name, Domain domain, Class<? extends T> beanClass)
+ {
+ super(name, domain, beanClass);
+ }
+
+ protected AbstractDirectContainer(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, C>) 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();
+ }
+
+ 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();
+ }
+}
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-08 13:11:13 UTC (rev 68675)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/DirectContainer.java 2008-01-08 13:34:01 UTC (rev 68676)
@@ -21,17 +21,7 @@
*/
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;
/**
@@ -43,7 +33,7 @@
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
* @version $Revision: $
*/
-public class DirectContainer<T> extends AbstractContainer<T, DirectContainer<T>>
+public class DirectContainer<T> extends AbstractDirectContainer<T, DirectContainer<T>>
{
private static final Logger log = Logger.getLogger(DirectContainer.class);
@@ -56,69 +46,4 @@
{
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();
- }
-
- 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();
- }
}
Modified: 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/direct/IndirectContainer.java 2008-01-08 13:11:13 UTC (rev 68675)
+++ projects/ejb3/trunk/interceptors/src/main/java/org/jboss/ejb3/interceptors/direct/IndirectContainer.java 2008-01-08 13:34:01 UTC (rev 68676)
@@ -21,15 +21,13 @@
*/
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>
+public interface IndirectContainer<T, C extends AbstractDirectContainer<T, C>>
{
- void setDirectContainer(DirectContainer<T> container);
+ void setDirectContainer(AbstractDirectContainer<T, C> container);
}
More information about the jboss-cvs-commits
mailing list