[jboss-cvs] JBossAS SVN: r86178 - in projects/ejb3/trunk: sis and 23 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Mar 22 05:14:16 EDT 2009
Author: wolfc
Date: 2009-03-22 05:14:15 -0400 (Sun, 22 Mar 2009)
New Revision: 86178
Added:
projects/ejb3/trunk/sis/
projects/ejb3/trunk/sis/.classpath
projects/ejb3/trunk/sis/.project
projects/ejb3/trunk/sis/.settings/
projects/ejb3/trunk/sis/.settings/org.eclipse.jdt.core.prefs
projects/ejb3/trunk/sis/.settings/org.maven.ide.eclipse.prefs
projects/ejb3/trunk/sis/pom.xml
projects/ejb3/trunk/sis/src/
projects/ejb3/trunk/sis/src/main/
projects/ejb3/trunk/sis/src/main/java/
projects/ejb3/trunk/sis/src/main/java/org/
projects/ejb3/trunk/sis/src/main/java/org/jboss/
projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/
projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/
projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/Interceptor.java
projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/InterceptorAssembly.java
projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/NoopInterceptor.java
projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/reflect/
projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/reflect/InterceptorInvocationHandler.java
projects/ejb3/trunk/sis/src/test/
projects/ejb3/trunk/sis/src/test/java/
projects/ejb3/trunk/sis/src/test/java/org/
projects/ejb3/trunk/sis/src/test/java/org/jboss/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/BouncingInterceptor.java
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/unit/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/unit/InterceptorAssemblyTestCase.java
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/common/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/common/RegisteringInterceptor.java
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/ChangingParamsInterceptor.java
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/Greeter.java
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/unit/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/unit/ChangingParamsTestCase.java
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/simple/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/simple/unit/
projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/simple/unit/SimpleTestCase.java
Log:
EJBTHREE-1785: initial setup
Property changes on: projects/ejb3/trunk/sis
___________________________________________________________________
Name: svn:ignore
+ target
eclipse-target
Added: projects/ejb3/trunk/sis/.classpath
===================================================================
--- projects/ejb3/trunk/sis/.classpath (rev 0)
+++ projects/ejb3/trunk/sis/.classpath 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="eclipse-target/classes" path="src/main/java"/>
+ <classpathentry kind="src" output="eclipse-target/tests-classes" path="src/test/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.5.0_15"/>
+ <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="eclipse-target/classes"/>
+</classpath>
Added: projects/ejb3/trunk/sis/.project
===================================================================
--- projects/ejb3/trunk/sis/.project (rev 0)
+++ projects/ejb3/trunk/sis/.project 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,18 @@
+<projectDescription>
+ <name>jboss-ejb3-sis</name>
+ <comment>The JBoss EJB 3 Simple Interceptor System is a lightweight interceptor
+ mechanism which only depends on the JDK and EJB 3 API.</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Added: projects/ejb3/trunk/sis/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/ejb3/trunk/sis/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ projects/ejb3/trunk/sis/.settings/org.eclipse.jdt.core.prefs 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,5 @@
+#Sun Mar 22 09:05:18 CET 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
Added: projects/ejb3/trunk/sis/.settings/org.maven.ide.eclipse.prefs
===================================================================
--- projects/ejb3/trunk/sis/.settings/org.maven.ide.eclipse.prefs (rev 0)
+++ projects/ejb3/trunk/sis/.settings/org.maven.ide.eclipse.prefs 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,8 @@
+#Sun Mar 22 09:38:58 CET 2009
+activeProfiles=eclipse
+eclipse.preferences.version=1
+fullBuildGoals=
+includeModules=false
+resolveWorkspaceProjects=false
+resourceFilterGoals=
+version=1
Added: projects/ejb3/trunk/sis/pom.xml
===================================================================
--- projects/ejb3/trunk/sis/pom.xml (rev 0)
+++ projects/ejb3/trunk/sis/pom.xml 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,38 @@
+<!--
+ vi:ts=2:sw=2:expandtab
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-build</artifactId>
+ <version>1.0.1</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-ejb3-sis</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>JBoss EJB 3.0 Simple Interceptor System</name>
+ <url>http://www.jboss.org</url>
+ <description>
+ The JBoss EJB 3 Simple Interceptor System is a lightweight interceptor
+ mechanism which only depends on the JDK and EJB 3 API.
+ </description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.javaee</groupId>
+ <artifactId>jboss-ejb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Copied: projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/Interceptor.java (from rev 86173, projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/Interceptor.java)
===================================================================
--- projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/Interceptor.java (rev 0)
+++ projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/Interceptor.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * An interface for an around-invoke class interceptor build for speed.
+ *
+ * Instead of scanning @AroundInvoke to see which methods needs to
+ * be invoked, implement this interface.
+ *
+ * Note that the interceptor itself must be made thread safe.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Interceptor
+{
+ Object invoke(InvocationContext context) throws Exception;
+}
Property changes on: projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/Interceptor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/InterceptorAssembly.java
===================================================================
--- projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/InterceptorAssembly.java (rev 0)
+++ projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/InterceptorAssembly.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorAssembly implements Interceptor
+{
+ private Interceptor[] interceptors;
+
+ public InterceptorAssembly(Interceptor interceptors[])
+ {
+ assert interceptors != null : "interceptors = null";
+ this.interceptors = interceptors;
+ }
+
+ public Object invoke(final InvocationContext context) throws Exception
+ {
+ InvocationContext current = new InvocationContext() {
+ private int currentInterceptor = 0;
+
+ public Map<String, Object> getContextData()
+ {
+ return context.getContextData();
+ }
+
+ public Method getMethod()
+ {
+ return context.getMethod();
+ }
+
+ public Object[] getParameters()
+ {
+ return context.getParameters();
+ }
+
+ public Object getTarget()
+ {
+ return context.getTarget();
+ }
+
+ public Object proceed() throws Exception
+ {
+ if(currentInterceptor < interceptors.length)
+ {
+ try
+ {
+ return interceptors[currentInterceptor++].invoke(this);
+ }
+ finally
+ {
+ // so that interceptors like clustering can reinvoke down the chain
+ currentInterceptor--;
+ }
+ }
+ return context.proceed();
+ }
+
+ public void setParameters(Object[] params)
+ {
+ context.setParameters(params);
+ }
+ };
+ return current.proceed();
+ }
+}
Copied: projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/NoopInterceptor.java (from rev 86173, projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/NoopInterceptor.java)
===================================================================
--- projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/NoopInterceptor.java (rev 0)
+++ projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/NoopInterceptor.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis;
+
+import javax.interceptor.InvocationContext;
+
+/**
+ * The most basic interceptor.
+ *
+ * If you're expecting magic, look somewhere else.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class NoopInterceptor implements Interceptor
+{
+ public Object invoke(InvocationContext context) throws Exception
+ {
+ return context.proceed();
+ }
+}
Property changes on: projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/NoopInterceptor.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/reflect/InterceptorInvocationHandler.java (from rev 86173, projects/ejb3/trunk/remoting2/src/test/java/org/jboss/ejb3/remoting2/test/clientinterceptor/InterceptorInvocationHandler.java)
===================================================================
--- projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/reflect/InterceptorInvocationHandler.java (rev 0)
+++ projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/reflect/InterceptorInvocationHandler.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.reflect;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.sis.Interceptor;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorInvocationHandler implements InvocationHandler
+{
+ private InvocationHandler handler;
+ private Interceptor interceptor;
+
+ public InterceptorInvocationHandler(InvocationHandler handler, Interceptor interceptor)
+ {
+ assert handler != null : "handler is null";
+ assert interceptor != null : "interceptor is null";
+
+ this.handler = handler;
+ this.interceptor = interceptor;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable
+ {
+ final Map<String, Object> contextData = new HashMap<String, Object>();
+ InvocationContext context = new InvocationContext() {
+ private Object[] parameters = args;
+
+ public Map<String, Object> getContextData()
+ {
+ return contextData;
+ }
+
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ public Object[] getParameters()
+ {
+ return args;
+ }
+
+ public Object getTarget()
+ {
+ return proxy;
+ }
+
+ public Object proceed() throws Exception
+ {
+ try
+ {
+ return handler.invoke(proxy, method, parameters);
+ }
+ catch(Error e)
+ {
+ throw e;
+ }
+ catch(RuntimeException e)
+ {
+ throw e;
+ }
+ catch(Exception e)
+ {
+ throw e;
+ }
+ catch(Throwable t)
+ {
+ // should not happen
+ throw new RuntimeException(t);
+ }
+ }
+
+ public void setParameters(Object[] params)
+ {
+ this.parameters = params;
+ }
+ };
+ return interceptor.invoke(context);
+ }
+}
Property changes on: projects/ejb3/trunk/sis/src/main/java/org/jboss/ejb3/sis/reflect/InterceptorInvocationHandler.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added: projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/BouncingInterceptor.java
===================================================================
--- projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/BouncingInterceptor.java (rev 0)
+++ projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/BouncingInterceptor.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.test.assembly;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.sis.Interceptor;
+
+/**
+ * This is a bad example of an interceptor. The exception should have been a defined exception.
+ *
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class BouncingInterceptor implements Interceptor
+{
+ public Object invoke(InvocationContext context) throws Exception
+ {
+ Object r = null;
+ while(r == null)
+ {
+ try
+ {
+ r = context.proceed();
+ }
+ catch(Exception e)
+ {
+ // ignore, do a bounce
+ }
+ }
+ return r;
+ }
+}
Added: projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/unit/InterceptorAssemblyTestCase.java
===================================================================
--- projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/unit/InterceptorAssemblyTestCase.java (rev 0)
+++ projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/assembly/unit/InterceptorAssemblyTestCase.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.test.assembly.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.jboss.ejb3.sis.Interceptor;
+import org.jboss.ejb3.sis.InterceptorAssembly;
+import org.jboss.ejb3.sis.NoopInterceptor;
+import org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler;
+import org.jboss.ejb3.sis.test.assembly.BouncingInterceptor;
+import org.jboss.ejb3.sis.test.common.RegisteringInterceptor;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class InterceptorAssemblyTestCase
+{
+ @Test
+ public void test1() throws Throwable
+ {
+ InvocationHandler handler = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return "nothing";
+ }
+ };
+ Interceptor interceptors[] = { new NoopInterceptor() };
+ Interceptor interceptor = new InterceptorAssembly(interceptors);
+ handler = new InterceptorInvocationHandler(handler, interceptor);
+ Object proxy = null;
+ Method method = Object.class.getDeclaredMethod("toString");
+ Object args[] = null;
+ String result = (String) handler.invoke(proxy, method, args);
+ assertEquals("nothing", result);
+ }
+
+ @Test
+ public void test2() throws Throwable
+ {
+ InvocationHandler handler = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return "nothing";
+ }
+ };
+ Interceptor interceptors[] = { new RegisteringInterceptor("A"), new RegisteringInterceptor("B") };
+ Interceptor interceptor = new InterceptorAssembly(interceptors);
+ handler = new InterceptorInvocationHandler(handler, interceptor);
+ Object proxy = null;
+ Method method = Object.class.getDeclaredMethod("toString");
+ Object args[] = null;
+ String result = (String) handler.invoke(proxy, method, args);
+ assertEquals("ABnothing", result);
+ }
+
+ @Test
+ public void testBounce() throws Throwable
+ {
+ InvocationHandler handler = new InvocationHandler() {
+ int numInvokes = 0;
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ numInvokes++;
+ if(numInvokes < 2)
+ throw new Exception("Again!");
+ return "nothing" + numInvokes;
+ }
+ };
+ Interceptor interceptors[] = { new RegisteringInterceptor("A"), new BouncingInterceptor(), new RegisteringInterceptor("B") };
+ Interceptor interceptor = new InterceptorAssembly(interceptors);
+ handler = new InterceptorInvocationHandler(handler, interceptor);
+ Object proxy = null;
+ Method method = Object.class.getDeclaredMethod("toString");
+ Object args[] = null;
+ String result = (String) handler.invoke(proxy, method, args);
+ assertEquals("ABnothing2", result);
+ }
+}
Added: projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/common/RegisteringInterceptor.java
===================================================================
--- projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/common/RegisteringInterceptor.java (rev 0)
+++ projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/common/RegisteringInterceptor.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,45 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.test.common;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.sis.Interceptor;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class RegisteringInterceptor implements Interceptor
+{
+ private String name;
+
+ public RegisteringInterceptor(String name)
+ {
+ this.name = name;
+ }
+
+ public Object invoke(InvocationContext context) throws Exception
+ {
+ return name + context.proceed();
+ }
+}
Added: projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/ChangingParamsInterceptor.java
===================================================================
--- projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/ChangingParamsInterceptor.java (rev 0)
+++ projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/ChangingParamsInterceptor.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.test.parameters;
+
+import javax.interceptor.InvocationContext;
+
+import org.jboss.ejb3.sis.Interceptor;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ChangingParamsInterceptor implements Interceptor
+{
+ public Object invoke(InvocationContext context) throws Exception
+ {
+ // just to get some coverage
+ assert context.getContextData() != null;
+ assert context.getMethod().getName().equals("sayHi");
+ assert context.getTarget() != null;
+
+ Object params[] = context.getParameters();
+ Object newParams[] = { "*" + params[0].toString() + "*" };
+ context.setParameters(newParams);
+ return context.proceed();
+ }
+}
Added: projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/Greeter.java
===================================================================
--- projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/Greeter.java (rev 0)
+++ projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/Greeter.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.test.parameters;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Greeter
+{
+ String sayHi(String name);
+}
Added: projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/unit/ChangingParamsTestCase.java
===================================================================
--- projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/unit/ChangingParamsTestCase.java (rev 0)
+++ projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/parameters/unit/ChangingParamsTestCase.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.test.parameters.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.jboss.ejb3.sis.Interceptor;
+import org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler;
+import org.jboss.ejb3.sis.test.parameters.ChangingParamsInterceptor;
+import org.jboss.ejb3.sis.test.parameters.Greeter;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class ChangingParamsTestCase
+{
+ @Test
+ public void test1() throws Throwable
+ {
+ InvocationHandler handler = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return "Hi " + args[0];
+ }
+ };
+ Interceptor interceptor = new ChangingParamsInterceptor();
+ handler = new InterceptorInvocationHandler(handler, interceptor);
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ Class<?> interfaces[] = { Greeter.class };
+ Greeter greeter = (Greeter) Proxy.newProxyInstance(loader, interfaces, handler);
+ String result = greeter.sayHi("Fizz");
+ assertEquals("Hi *Fizz*", result);
+ }
+}
Added: projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/simple/unit/SimpleTestCase.java
===================================================================
--- projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/simple/unit/SimpleTestCase.java (rev 0)
+++ projects/ejb3/trunk/sis/src/test/java/org/jboss/ejb3/sis/test/simple/unit/SimpleTestCase.java 2009-03-22 09:14:15 UTC (rev 86178)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.sis.test.simple.unit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.jboss.ejb3.sis.Interceptor;
+import org.jboss.ejb3.sis.NoopInterceptor;
+import org.jboss.ejb3.sis.reflect.InterceptorInvocationHandler;
+import org.junit.Test;
+
+/**
+ * @author <a href="mailto:cdewolf at redhat.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class SimpleTestCase
+{
+ @Test
+ public void test1() throws Throwable
+ {
+ InvocationHandler handler = new InvocationHandler() {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ return "nothing";
+ }
+ };
+ Interceptor interceptor = new NoopInterceptor();
+ handler = new InterceptorInvocationHandler(handler, interceptor);
+ Object proxy = null;
+ Method method = Object.class.getDeclaredMethod("toString");
+ Object args[] = null;
+ String result = (String) handler.invoke(proxy, method, args);
+ assertEquals("nothing", result);
+ }
+}
More information about the jboss-cvs-commits
mailing list