[jboss-cvs] JBossAS SVN: r71959 - in projects/jboss-aspects/trunk: build and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Apr 10 12:43:25 EDT 2008


Author: adrian at jboss.org
Date: 2008-04-10 12:43:24 -0400 (Thu, 10 Apr 2008)
New Revision: 71959

Added:
   projects/jboss-aspects/trunk/transaction/
   projects/jboss-aspects/trunk/transaction/pom.xml
   projects/jboss-aspects/trunk/transaction/src/
   projects/jboss-aspects/trunk/transaction/src/main/
   projects/jboss-aspects/trunk/transaction/src/main/org/
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/ClientTxPropagationInterceptor.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionInjector.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionLocalAspect.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/Tx.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptor.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptorFactory.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxLocal.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPolicy.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPropagationInterceptor.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReader.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxType.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/QueuedTxLock.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptor.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptorFactory.java
   projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxSynchronized.java
Modified:
   projects/jboss-aspects/trunk/build/pom.xml
   projects/jboss-aspects/trunk/pom.xml
Log:
[JBAS-5393] - Move transaction aspects to jboss-aspects project

Modified: projects/jboss-aspects/trunk/build/pom.xml
===================================================================
--- projects/jboss-aspects/trunk/build/pom.xml	2008-04-10 16:39:45 UTC (rev 71958)
+++ projects/jboss-aspects/trunk/build/pom.xml	2008-04-10 16:43:24 UTC (rev 71959)
@@ -35,6 +35,7 @@
     <version.jboss.logging.spi>2.0.5.GA</version.jboss.logging.spi>
     <version.jboss.aop>2.0.0.CR8</version.jboss.aop>
     <version.jboss.security.spi>2.0.2.Beta5</version.jboss.security.spi>
+    <version.jboss.transaction.spi>5.0.0.Beta4</version.jboss.transaction.spi>
     <version.jbosssx.client>2.0.2.Beta5</version.jbosssx.client>
     <version.jboss.kernel>2.0.0.Beta11</version.jboss.kernel>
     <version.jboss.remoting>2.4.0.CR1</version.jboss.remoting>
@@ -220,6 +221,12 @@
         <artifactId>jboss-remoting</artifactId>
         <version>${version.jboss.remoting}</version>
       </dependency>    
+      
+      <dependency>
+        <groupId>org.jboss</groupId>
+        <artifactId>jboss-transaction-spi</artifactId>
+        <version>${version.jboss.transaction.spi}</version>
+      </dependency>   
     
       <!-- test dependencies -->
       <dependency>

Modified: projects/jboss-aspects/trunk/pom.xml
===================================================================
--- projects/jboss-aspects/trunk/pom.xml	2008-04-10 16:39:45 UTC (rev 71958)
+++ projects/jboss-aspects/trunk/pom.xml	2008-04-10 16:43:24 UTC (rev 71959)
@@ -24,6 +24,7 @@
     <module>build</module>
     <module>remoting</module>
     <module>security</module>
+    <module>transaction</module>
   </modules>
 
   <build>

Added: projects/jboss-aspects/trunk/transaction/pom.xml
===================================================================
--- projects/jboss-aspects/trunk/transaction/pom.xml	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/pom.xml	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,59 @@
+<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.aspects</groupId>
+    <artifactId>jboss-aspects-build</artifactId>
+    <version>1.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jboss-transaction-aspects</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss Transaction Aspects</name>
+  <url>http://www.jboss.org/jbossas/</url>
+  <description>JBoss Transaction Aspects</description>  
+  <build>
+    <resources>
+      <resource>
+        <directory>src/resources/main</directory>
+      </resource>
+    </resources>
+    <testResources>
+      <testResource>
+        <directory>src/resources/tests</directory>
+      </testResource>
+    </testResources>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <executions>
+          <execution>
+            <goals>
+              <goal>test-jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+      </plugin>   	   
+    </plugins>
+  </build>
+  <!-- Do not add version information here, use ../build/pom.xml instead -->
+  <dependencies>
+    <!-- Global dependencies -->
+    
+      <dependency>
+        <groupId>org.jboss.aop</groupId>
+        <artifactId>jboss-aop</artifactId>
+      </dependency> 
+
+      <dependency>
+        <groupId>org.jboss</groupId>
+        <artifactId>jboss-transaction-spi</artifactId>
+      </dependency>
+
+      
+    <!-- Test dependencies -->
+  </dependencies>
+</project>

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/ClientTxPropagationInterceptor.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/ClientTxPropagationInterceptor.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/ClientTxPropagationInterceptor.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,67 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.tm.TransactionPropagationContextFactory;
+import org.jboss.tm.TransactionPropagationContextUtil;
+
+import java.io.ObjectStreamException;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 37406 $
+ */
+public class ClientTxPropagationInterceptor implements Interceptor, java.io.Serializable
+{
+   private static final long serialVersionUID = 4536126296306191076L;
+
+   public static String TRANSACTION_PROPAGATION_CONTEXT = "TransactionPropagationContext";
+
+   public static final ClientTxPropagationInterceptor singleton = new ClientTxPropagationInterceptor();
+
+   public String getName()
+   {
+      return "ClientTxPropagationInterceptor";
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      TransactionPropagationContextFactory tpcFactory = TransactionPropagationContextUtil.getTPCFactoryClientSide();
+      if (tpcFactory != null)
+      {
+         Object tpc = tpcFactory.getTransactionPropagationContext();
+         if (tpc != null)
+         {
+            invocation.getMetaData().addMetaData(TRANSACTION_PROPAGATION_CONTEXT, TRANSACTION_PROPAGATION_CONTEXT, tpc);
+         }
+      }
+      return invocation.invokeNext();
+   }
+
+   Object readResolve() throws ObjectStreamException {
+      return singleton;
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/NullTransactionTimeoutConfigurationReader.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,14 @@
+package org.jboss.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * When we don't know where we are
+ */
+class NullTransactionTimeoutConfigurationReader implements TxTimeoutReader
+{
+   public int getTransactionTimeOut(TransactionManager tm)
+   {
+      return 0;
+   }
+}
\ No newline at end of file

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionInjector.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionInjector.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionInjector.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,46 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import org.jboss.aop.joinpoint.FieldReadInvocation;
+import org.jboss.aop.joinpoint.FieldWriteInvocation;
+import org.jboss.tm.TransactionManagerLocator;
+
+/**
+ * This aspect should be scoped PER_JOINPOINT
+ * It allows a field to be like a ThreadLocal
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 43966 $
+ */
+public class TransactionInjector
+{
+   public Object access(FieldReadInvocation invocation) throws Throwable
+   {
+      return TransactionManagerLocator.getInstance().locate();
+   }
+
+   public Object access(FieldWriteInvocation invocation) throws Throwable
+   {
+      throw new RuntimeException("It is illegal to set an injected Transaction field.");
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionLocalAspect.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionLocalAspect.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionLocalAspect.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,68 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import org.jboss.aop.joinpoint.FieldReadInvocation;
+import org.jboss.aop.joinpoint.FieldWriteInvocation;
+import org.jboss.tm.TransactionLocal;
+
+/**
+ * This aspect should be scoped PER_JOINPOINT
+ * It allows a field to have the value of itself pertain
+ * to the current transaction.
+ *
+ * The fields transactional and non-transactional value is always separate
+ * At tx commit, the transactional value the field had is wiped away.
+ * At tx commit, the transactional value does not correspond to the non-transactional value
+ *
+ * If you are within a transaction and you get the value of the field before setting it
+ * then the initial transational value will be set to the current non-transactional value
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 37406 $
+ */
+public class TransactionLocalAspect
+{
+   private TransactionLocal txLocal = new TransactionLocal();
+
+   public Object access(FieldReadInvocation invocation) throws Throwable
+   {
+      // Return non-Tx value
+      if (txLocal.getTransaction() == null) return invocation.invokeNext();
+
+      // just in case we have a primitive, we can't return null so set txLocal to be the current nonTx value
+      if (txLocal.get() == null)
+      {
+         txLocal.set(invocation.invokeNext());
+      }
+      return txLocal.get();
+   }
+
+   public Object access(FieldWriteInvocation invocation) throws Throwable
+   {
+      // Return non-Tx value
+      if (txLocal.getTransaction() == null) return invocation.invokeNext();
+
+      txLocal.set(invocation.getValue());
+      return null;
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TransactionTimeoutConfigurationReader.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,44 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+import org.jboss.tm.TransactionTimeoutConfiguration;
+
+/**
+ * For use with newer versions of JBoss supporting the TransactionTimeoutConfiguration interface
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+class TransactionTimeoutConfigurationReader implements TxTimeoutReader
+{
+   public int getTransactionTimeOut(TransactionManager tm) throws Exception
+   {
+      if (tm instanceof TransactionTimeoutConfiguration)
+      {
+         return ((TransactionTimeoutConfiguration)tm).getTransactionTimeout();
+      }
+      return 0;
+   }
+}
\ No newline at end of file

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/Tx.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/Tx.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/Tx.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,36 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 57757 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface Tx
+{
+   TxType value() default TxType.REQUIRED;
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptor.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptor.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptor.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,311 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
+
+/**
+ * This interceptor handles transactions for AOP
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @version $Revision: 57070 $
+ */
+public class TxInterceptor
+{
+   private static final Logger log = Logger.getLogger(TxInterceptor.class);
+   private static final TxTimeoutReader txTimeoutReader = TxTimeoutReaderFactory.getTxTimeoutReader();
+
+   public static class Never implements Interceptor
+   {
+      protected TransactionManager tm;
+      protected TxPolicy policy;
+      protected int timeout;
+      
+      public Never(TransactionManager tm, TxPolicy policy)
+      {
+         this(tm, policy, -1);
+      }
+
+      public Never(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         this.tm = tm;
+         this.policy = policy;
+         this.timeout = timeout;
+      }
+
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         if (tm.getTransaction() != null)
+         {
+            throw new IllegalStateException("Transaction present on server in Never call");
+         } // end of if ()
+         return policy.invokeInNoTx(invocation);
+      }
+
+      public String getName()
+      {
+         return this.getClass().getName();
+      }
+   }
+
+   public static class NotSupported implements Interceptor
+   {
+      protected TransactionManager tm;
+      protected TxPolicy policy;
+      protected int timeout;
+      
+      public NotSupported(TransactionManager tm, TxPolicy policy)
+      {
+         this(tm, policy, -1);
+      }
+
+      public NotSupported(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         this.tm = tm;
+         this.policy = policy;
+         this.timeout = timeout;
+      }
+
+      public Object invoke(Invocation invocation)
+              throws Throwable
+      {
+         Transaction tx = tm.getTransaction();
+         if (tx != null)
+         {
+            tm.suspend();
+            try
+            {
+               return policy.invokeInNoTx(invocation);
+            }
+            finally
+            {
+               tm.resume(tx);
+            }
+
+         }
+         else
+         {
+            return policy.invokeInNoTx(invocation);
+         }
+      }
+
+      public String getName()
+      {
+         return this.getClass().getName();
+      }
+   }
+
+   public static class Supports implements Interceptor
+   {
+      protected TransactionManager tm;
+      protected TxPolicy policy;
+      protected int timeout;
+      
+      public Supports(TransactionManager tm, TxPolicy policy)
+      {
+         this(tm, policy, -1);
+      }
+
+      public Supports(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         this.tm = tm;
+         this.policy = policy;
+         this.timeout = timeout;
+      }
+
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         if (tm.getTransaction() == null)
+         {
+            return policy.invokeInNoTx(invocation);
+         }
+         else
+         {
+            return policy.invokeInCallerTx(invocation, tm.getTransaction());
+         }
+      }
+
+      public String getName()
+      {
+         return this.getClass().getName();
+      }
+   }
+
+   public static class Required implements Interceptor
+   {
+      private static final Logger log = Logger.getLogger(Required.class);
+      
+      protected TransactionManager tm;
+      protected TxPolicy policy;
+      protected int timeout;
+      
+      public Required(TransactionManager tm, TxPolicy policy)
+      {
+         this(tm, policy, -1);
+      }
+
+      public Required(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         this.tm = tm;
+         this.policy = policy;
+         this.timeout = timeout;
+      }
+
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         int oldTimeout = txTimeoutReader.getTransactionTimeOut(tm);          
+
+         try 
+         {
+            if (timeout != -1 && tm != null)
+            {
+               tm.setTransactionTimeout(timeout);
+            }
+               
+            Transaction tx = tm.getTransaction();
+            
+            if (tx == null)
+            {
+               return policy.invokeInOurTx(invocation, tm);
+            }
+            else
+            {
+               return policy.invokeInCallerTx(invocation, tx);
+            }
+         }
+         finally
+         {
+            if (tm != null)
+            {
+               tm.setTransactionTimeout(oldTimeout);
+            }
+         }
+      }
+
+      public String getName()
+      {
+         return this.getClass().getName();
+      }
+   }
+
+   public static class RequiresNew implements Interceptor
+   {
+      protected TransactionManager tm;
+      protected TxPolicy policy;
+      protected int timeout;
+      
+      public RequiresNew(TransactionManager tm, TxPolicy policy)
+      {
+         this(tm, policy, -1);
+      }
+
+      public RequiresNew(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         this.tm = tm;
+         this.policy = policy;
+         this.timeout = timeout;
+      }
+
+      public String getName()
+      {
+         return this.getClass().getName();
+      }
+
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         int oldTimeout = txTimeoutReader.getTransactionTimeOut(tm);          
+
+         try 
+         {
+            if (timeout != -1 && tm != null)
+            {
+               tm.setTransactionTimeout(timeout);
+            }
+            
+            Transaction tx = tm.getTransaction();
+            if (tx != null)
+            {
+               tm.suspend();
+               try
+               {
+                  return policy.invokeInOurTx(invocation, tm);
+               }
+               finally
+               {
+                  tm.resume(tx);
+               }
+            }
+            else
+            {
+               return policy.invokeInOurTx(invocation, tm);
+            }
+         }
+         finally
+         {
+            if (tm != null)
+            {
+               tm.setTransactionTimeout(oldTimeout);
+            }
+         }
+      }
+   }
+
+   public static class Mandatory implements Interceptor
+   {
+      protected TransactionManager tm;
+      protected TxPolicy policy;
+      protected int timeout;
+      
+      public Mandatory(TransactionManager tm, TxPolicy policy)
+      {
+         this(tm, policy, -1);
+      }
+
+      public Mandatory(TransactionManager tm, TxPolicy policy, int timeout)
+      {
+         this.tm = tm;
+         this.policy = policy;
+         this.timeout = timeout;
+      }
+
+      public String getName()
+      {
+         return this.getClass().getName();
+      }
+
+      public Object invoke(Invocation invocation) throws Throwable
+      {
+         Transaction tx = tm.getTransaction();
+         if (tx == null)
+         {
+            policy.throwMandatory(invocation);
+         }
+         return policy.invokeInCallerTx(invocation, tx);
+      }
+
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptorFactory.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptorFactory.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxInterceptorFactory.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,153 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import org.jboss.aop.Advisor;
+import org.jboss.aop.InstanceAdvisor;
+import org.jboss.aop.joinpoint.ConstructorJoinpoint;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.joinpoint.MethodJoinpoint;
+import org.jboss.aop.joinpoint.FieldJoinpoint;
+import org.jboss.tm.TransactionManagerLocator;
+
+/**
+ *  This interceptor handles transactions for AOP 
+ *
+ *  @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ *  @version $Revision: 43966 $
+ */
+public class TxInterceptorFactory implements org.jboss.aop.advice.AspectFactory
+{
+   protected TxPolicy policy;
+   protected HashMap nameMap = new HashMap();
+
+   protected void initializePolicy()
+   {
+      policy = new TxPolicy();
+   }
+
+   public void initialize()
+   {
+      if (policy != null) return;
+      initializePolicy();
+      nameMap.put("NEVER", new TxInterceptor.Never(TransactionManagerLocator.getInstance().locate(), policy));
+      nameMap.put("NOTSUPPORTED", new TxInterceptor.NotSupported(TransactionManagerLocator.getInstance().locate(), policy));
+      nameMap.put("SUPPORTS", new TxInterceptor.Supports(TransactionManagerLocator.getInstance().locate(), policy));
+      nameMap.put("REQUIRED", new TxInterceptor.Required(TransactionManagerLocator.getInstance().locate(), policy));
+      nameMap.put("REQUIRESNEW", new TxInterceptor.RequiresNew(TransactionManagerLocator.getInstance().locate(), policy));
+      nameMap.put("MANDATORY", new TxInterceptor.Mandatory(TransactionManagerLocator.getInstance().locate(), policy));
+   }
+
+   protected String resolveTxType(Advisor advisor, Joinpoint jp)
+   {
+      if (jp instanceof ConstructorJoinpoint)
+      {
+         Constructor con = ((ConstructorJoinpoint)jp).getConstructor();
+         String txType = (String)advisor.getConstructorMetaData().getConstructorMetaData(con, "transaction", "trans-attribute");
+         if (txType != null) return txType;
+
+         txType = (String)advisor.getDefaultMetaData().getMetaData("transaction", "trans-attribute");
+         if (txType != null) return txType;
+
+         Tx tx = (Tx)advisor.resolveAnnotation(con, Tx.class);
+         if (tx == null)
+         {
+            tx = (Tx)advisor.resolveAnnotation(Tx.class);
+         }
+         if (tx == null) return "REQUIRED";
+         return tx.value().name();
+      }
+      else if (jp instanceof MethodJoinpoint)
+      {
+         Method con = ((MethodJoinpoint)jp).getMethod();
+         String txType = (String)advisor.getMethodMetaData().getMethodMetaData(con, "transaction", "trans-attribute");
+         if (txType != null) return txType;
+
+         txType = (String)advisor.getDefaultMetaData().getMetaData("transaction", "trans-attribute");
+         if (txType != null) return txType;
+
+         Tx tx = (Tx)advisor.resolveAnnotation(con, Tx.class);
+         if (tx == null)
+         {
+            tx = (Tx)advisor.resolveAnnotation(Tx.class);
+         }
+         if (tx == null) return "REQUIRED";
+         return tx.value().name();
+      }
+      else
+      {
+         Field con = ((FieldJoinpoint)jp).getField();
+         String txType = (String)advisor.getFieldMetaData().getFieldMetaData(con, "transaction", "trans-attribute");
+         if (txType != null) return txType;
+
+         txType = (String)advisor.getDefaultMetaData().getMetaData("transaction", "trans-attribute");
+         if (txType != null) return txType;
+
+         Tx tx = (Tx)advisor.resolveAnnotation(con, Tx.class);
+         if (tx == null)
+         {
+            tx = (Tx)advisor.resolveAnnotation(Tx.class);
+         }
+         if (tx == null) return "REQUIRED";
+         return tx.value().name();
+      }
+   }
+
+
+   public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
+   {
+      initialize();
+      String txType = resolveTxType(advisor, jp);
+      Object rtn = nameMap.get(txType.toUpperCase());
+      if (rtn == null) throw new RuntimeException("TX TYPE was null for: " + txType);
+      return rtn;
+   }
+
+   public Object createPerVM()
+   {
+      throw new IllegalStateException("Scope not allowed");
+   }
+
+   public Object createPerClass(Advisor advisor)
+   {
+      throw new IllegalStateException("Scope not allowed");
+   }
+
+   public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)
+   {
+      throw new IllegalStateException("Scope not allowed");
+   }
+
+   public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp)
+   {
+      throw new IllegalStateException("Scope not allowed");
+   }
+
+   public String getName()
+   {
+      return getClass().getName();
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxLocal.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxLocal.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxLocal.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,48 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+
+/**
+ * This is an aspect-oriented annotation and triggers certain behavior.
+ *
+ * It allows a field to have the value of itself pertain
+ * to the current transaction.
+ *
+ * The fields transactional and non-transactional value is always separate
+ * At tx commit, the transactional value the field had is wiped away.
+ * At tx commit, the transactional value does not correspond to the non-transactional value
+ *
+ * If you are within a transaction and you get the value of the field before setting it
+ * then the initial transational value will be set to the current non-transactional value
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 57757 $
+ */
+ at Target({ElementType.FIELD}) @Retention(RetentionPolicy.RUNTIME)
+public @interface TxLocal
+{
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxManagerTimeOutReader.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+import org.jboss.tm.TransactionTimeoutConfiguration;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TxManagerTimeOutReader implements TxTimeoutReader 
+{
+   public int getTransactionTimeOut(TransactionManager tm)
+   {
+      if (tm instanceof TransactionTimeoutConfiguration)
+      {
+         try
+         {
+            return ((TransactionTimeoutConfiguration)tm).getTransactionTimeout();
+         }
+         catch (Exception e)
+         {
+            throw new RuntimeException("Error retrieving transaction timeout", e);
+         }
+      }
+      return 0;
+   }
+}
\ No newline at end of file

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPolicy.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPolicy.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPolicy.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,264 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import java.util.ArrayList;
+import java.util.Random;
+import java.util.StringTokenizer;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
+import org.jboss.util.deadlock.ApplicationDeadlockException;
+
+
+/**
+ * TxSupport.java encapsulates the transaction handling possibilities
+ * from the ejb spec.  The Tx interceptors call the clientInvoke and
+ * serverInvoke methods on the subclass determined by the method's
+ * transaction support.
+ * <p/>
+ * <p/>
+ * Created: Sun Feb  2 23:25:09 2003
+ *
+ * @author <a href="mailto:d_jencks at users.sourceforge.net">David Jencks</a>
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ */
+
+public class TxPolicy
+{
+   protected final static Logger log = Logger.getLogger(TxPolicy.class);
+
+   public static int MAX_RETRIES = 5;
+   public static Random random = new Random();
+
+   public void throwMandatory(Invocation invocation)
+   {
+      throw new RuntimeException("Transaction is mandatory.");
+   }
+
+   public Object invokeInNoTx(Invocation invocation) throws Throwable
+   {
+      return invocation.invokeNext();
+   }
+
+   public Object invokeInOurTx(Invocation invocation, TransactionManager tm) throws Throwable
+   {
+      for (int i = 0; i < MAX_RETRIES; i++)
+      {
+         tm.begin();
+         Transaction tx = tm.getTransaction();
+         try
+         {
+            try
+            {
+               return invocation.invokeNext();
+            }
+            catch (Throwable t)
+            {
+               handleExceptionInOurTx(invocation, t, tx);
+            }
+            finally
+            {
+               endTransaction(tm, tx);
+            }
+         }
+         catch (Exception ex)
+         {
+            ApplicationDeadlockException deadlock = ApplicationDeadlockException.isADE(ex);
+            if (deadlock != null)
+            {
+               if (!deadlock.retryable() ||
+                   i + 1 >= MAX_RETRIES)
+               {
+                  throw deadlock;
+               }
+               log.warn(deadlock.getMessage() + " retrying " + (i + 1));
+
+               Thread.sleep(random.nextInt(1 + i), random.nextInt(1000));
+            }
+            else
+            {
+               throw ex;
+            }
+         }
+      }
+      throw new RuntimeException("UNREACHABLE");
+   }
+
+   public void handleExceptionInOurTx(Invocation invocation, Throwable t, Transaction tx)
+           throws Throwable
+   {
+      // if this is an ApplicationException, just rethrow it
+      rethrowApplicationException(invocation, t);
+      setRollbackOnly(tx);
+      throw t;
+   }
+
+   public Object invokeInCallerTx(Invocation invocation, Transaction tx) throws Throwable
+   {
+      try
+      {
+         return invocation.invokeNext();
+      }
+      catch (Throwable t)
+      {
+         handleInCallerTx(invocation, t, tx);
+      }
+      throw new RuntimeException("UNREACHABLE");
+   }
+
+   public void handleInCallerTx(Invocation invocation, Throwable t, Transaction tx)
+           throws Throwable
+   {
+      rethrowApplicationException(invocation, t);
+      setRollbackOnly(tx);
+      throw t;
+   }
+
+   /**
+    * The <code>endTransaction</code> method ends a transaction and
+    * translates any exceptions into
+    * TransactionRolledBack[Local]Exception or SystemException.
+    *
+    * @param invocation an <code>Invocation</code> value
+    * @param tm         a <code>TransactionManager</code> value
+    * @param tx         a <code>Transaction</code> value
+    * @throws javax.transaction.TransactionRolledbackException
+    *          if an error occurs
+    * @throws javax.transaction.SystemException
+    *          if an error occurs
+    */
+   public void endTransaction(TransactionManager tm, Transaction tx)
+   {
+      try
+      {
+         if (tx != tm.getTransaction())
+         {
+            throw new IllegalStateException("Wrong tx on thread: expected " + tx + ", actual " + tm.getTransaction());
+         }
+
+         if (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
+         {
+            tm.rollback();
+         }
+         else
+         {
+            // Commit tx
+            // This will happen if
+            // a) everything goes well
+            // b) app. exception was thrown
+            tm.commit();
+         }
+      }
+      catch (RollbackException e)
+      {
+         handleEndTransactionException(e);
+      }
+      catch (HeuristicMixedException e)
+      {
+         handleEndTransactionException(e);
+      }
+      catch (HeuristicRollbackException e)
+      {
+         handleEndTransactionException(e);
+      }
+      catch (SystemException e)
+      {
+         handleEndTransactionException(e);
+      }
+   }
+
+   public void handleEndTransactionException(Exception e)
+   {
+      throw new RuntimeException(e);
+   }
+
+   /**
+    * The <code>setRollbackOnly</code> method calls setRollbackOnly()
+    * on the invocation's transaction and logs any exceptions than may
+    * occur.
+    *
+    * @param invocation an <code>Invocation</code> value
+    */
+   public void setRollbackOnly(Transaction tx)
+   {
+      try
+      {
+         tx.setRollbackOnly();
+      }
+      catch (SystemException ex)
+      {
+         log.error("SystemException while setting transaction " +
+                   "for rollback only", ex);
+      }
+      catch (IllegalStateException ex)
+      {
+         log.error("IllegalStateException while setting transaction " +
+                   "for rollback only", ex);
+      }
+   }
+
+   /**
+    * The <code>rethrowApplicationException</code> method determines
+    * if the supplied Throwable is an application exception and
+    * rethrows it if it is.
+    *
+    * @param e a <code>Throwable</code> value
+    * @throws Exception if an error occurs
+    */
+   public void rethrowApplicationException(Invocation inv, Throwable e) throws Throwable
+   {
+      Object applicationExceptions = inv.getMetaData("transaction", "application-exceptions");
+      if (applicationExceptions == null) return;
+      Class[] applicationExceptionsList;
+      if (applicationExceptions instanceof String)
+      {
+         ArrayList tmpList = new ArrayList();
+         String aes = (String) applicationExceptions;
+         aes = aes.trim();
+         StringTokenizer tokenizer = new StringTokenizer(aes, ",");
+         while (tokenizer.hasMoreTokens())
+         {
+            String token = tokenizer.nextToken().trim();
+            Class excClass = Thread.currentThread().getContextClassLoader().loadClass(token);
+            tmpList.add(excClass);
+         }
+         applicationExceptionsList = (Class[]) tmpList.toArray(new Class[tmpList.size()]);
+      }
+      else
+      {
+         applicationExceptionsList = (Class[]) applicationExceptions;
+      }
+      for (int i = 0; i < applicationExceptionsList.length; i++)
+      {
+         if (applicationExceptionsList[i].isInstance(e)) throw e;
+      }
+
+   }
+
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPropagationInterceptor.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPropagationInterceptor.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxPropagationInterceptor.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,79 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.tm.TransactionManagerLocator;
+import org.jboss.tm.TransactionPropagationContextUtil;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 43966 $
+ */
+public class TxPropagationInterceptor implements Interceptor
+{
+   private TransactionManager tm;
+
+   public TxPropagationInterceptor(TransactionManager tm)
+   {
+      this.tm = tm;
+   }
+
+   public TxPropagationInterceptor()
+   {
+      tm = TransactionManagerLocator.getInstance().locate();
+   }
+
+   public String getName()
+   {
+      return "TxPropagationInterceptor";
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      Object tpc = invocation.getMetaData(ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT, ClientTxPropagationInterceptor.TRANSACTION_PROPAGATION_CONTEXT);
+      if (tpc != null)
+      {
+         Transaction tx = tm.getTransaction();
+         if (tx != null) throw new RuntimeException("cannot import a transaction context when a transaction is already associated with the thread");
+         Transaction importedTx = TransactionPropagationContextUtil.getTPCImporter().importTransactionPropagationContext(tpc);
+         tm.resume(importedTx);
+         try
+         {
+            return invocation.invokeNext();
+         }
+         finally
+         {
+            tm.suspend();
+         }
+      }
+      else
+      {
+         return invocation.invokeNext();
+      }
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReader.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReader.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReader.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,35 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+import javax.transaction.TransactionManager;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface TxTimeoutReader
+{
+   int getTransactionTimeOut(TransactionManager tm) throws Exception;
+   
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxTimeoutReaderFactory.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,56 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+/**
+ * Obtains the correct mechanism to get hold of a transaction timeout.
+ * Newer versions of JBoss should use the TransactionTimeoutConfiguration interfsce.
+ * For older versions we need to access the TxManager directly
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class TxTimeoutReaderFactory
+{
+   public static TxTimeoutReader getTxTimeoutReader()
+   {
+      try
+      {
+         Class clazz = Class.forName("org.jboss.tm.TransactionTimeoutConfiguration");
+         return new TransactionTimeoutConfigurationReader();
+      }
+      catch (ClassNotFoundException e)
+      {
+      }
+      
+      try
+      {
+         Class clazz = Class.forName("org.jboss.tm.TxManager");
+         return new TxManagerTimeOutReader();
+      }
+      catch (ClassNotFoundException e)
+      {
+      }
+      
+      return new NullTransactionTimeoutConfigurationReader();
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxType.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxType.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/tx/TxType.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,37 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.tx;
+
+/**
+ *
+ * @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ * @version $Revision: 57757 $
+ */
+public enum TxType
+{
+   MANDATORY,
+   REQUIRED,
+   REQUIRESNEW,
+   SUPPORTS,
+   NOTSUPPORTED,
+   NEVER
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/QueuedTxLock.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/QueuedTxLock.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/QueuedTxLock.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,407 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.txlock;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.deadlock.DeadlockDetector;
+import org.jboss.util.deadlock.Resource;
+
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.Transaction;
+import java.util.HashMap;
+import java.util.LinkedList;
+
+/**
+ * This class is holds threads awaiting the transactional lock to be free
+ * in a fair FIFO transactional queue.  Non-transactional threads
+ * are also put in this wait queue as well. This class pops the next waiting transaction from the queue
+ * and notifies only those threads waiting associated with that transaction.
+ *
+ * As of 04/10/2002, you can now specify in jboss.xml method attributes that define
+ * methods as read-only.  read-only methods(and read-only beans) will release transactional
+ * locks at the end of the invocation.  This decreases likelyhood of deadlock and increases
+ * performance.
+ *
+ * FIXME marcf: we should get solid numbers on this locking, bench in multi-thread environments
+ * We need someone with serious SUN hardware to run this lock into the ground
+ *
+ * @author <a href="marc.fleury at jboss.org">Marc Fleury</a>
+ * @author <a href="bill at burkecentral.com">Bill Burke</a>
+ *
+ * @version $Revision: 37406 $
+ */
+public class QueuedTxLock implements Resource
+{
+   public static final String TXLOCK = "TxLock";
+   public static final String TIMEOUT = "timeout";
+
+   private HashMap txLocks = new HashMap();
+   private LinkedList txWaitQueue = new LinkedList();
+
+   /** Transaction holding lock on bean */
+   private Transaction tx = null;
+   private boolean synched = false;
+   private boolean isSynchronized = false;
+   private Logger log = Logger.getLogger(this.getClass());
+
+   public Object getResourceHolder()
+   {
+      return tx;
+   }
+
+   public void sync() throws InterruptedException
+   {
+      synchronized (this)
+      {
+         while (synched)
+         {
+            this.wait();
+         }
+         synched = true;
+      }
+   }
+
+   public void releaseSync()
+   {
+      synchronized (this)
+      {
+         synched = false;
+         this.notify();
+      }
+   }
+
+   /**
+    * The setTransaction associates a transaction with the lock.
+    * The current transaction is associated by the schedule call.
+    */
+   public void setTransaction(Transaction tx)
+   {
+      this.tx = tx;
+   }
+
+   public Transaction getTransaction()
+   {
+      return tx;
+   }
+
+
+   private class TxLock
+   {
+
+      public Transaction waitingTx;
+      public String threadName;
+      public boolean isQueued;
+
+      public TxLock(Transaction trans)
+      {
+         this.threadName = Thread.currentThread().toString();
+         this.waitingTx = trans;
+         this.isQueued = true;
+      }
+
+      public boolean equals(Object obj)
+      {
+         if (obj == this) return true;
+
+         TxLock lock = (TxLock) obj;
+
+         return lock.waitingTx.equals(this.waitingTx);
+      }
+
+      public int hashCode()
+      {
+         return waitingTx.hashCode();
+      }
+
+      public String toString()
+      {
+         StringBuffer buffer = new StringBuffer(100);
+         buffer.append("TXLOCK waitingTx=").append(waitingTx);
+         buffer.append(" thread=").append(threadName);
+         buffer.append(" queued=").append(isQueued);
+         return buffer.toString();
+      }
+   }
+
+   protected TxLock getTxLock(Transaction miTx)
+   {
+      TxLock lock = null;
+      TxLock key = new TxLock(miTx);
+      lock = (TxLock) txLocks.get(key);
+      if (lock == null)
+      {
+         txLocks.put(key, key);
+         txWaitQueue.addLast(key);
+         lock = key;
+      }
+      return lock;
+   }
+
+   protected boolean isTxExpired(Transaction miTx) throws Exception
+   {
+      if (miTx != null && miTx.getStatus() == Status.STATUS_MARKED_ROLLBACK)
+      {
+         return true;
+      }
+      return false;
+   }
+
+
+   public boolean lockNoWait(Transaction transaction) throws Exception
+   {
+      this.sync();
+      if (log.isTraceEnabled())
+         log.trace("lockNoWait tx=" + transaction + " " + toString());
+      try
+      {
+         // And are we trying to enter with another transaction?
+         if (getTransaction() != null && !getTransaction().equals(transaction))
+         {
+            return false;
+         }
+         setTransaction(transaction);
+         return true;
+      }
+      finally
+      {
+         this.releaseSync();
+      }
+   }
+
+   /**
+    * doSchedule(Invocation)
+    *
+    * doSchedule implements a particular policy for scheduling the threads coming in.
+    * There is always the spec required "serialization" but we can add custom scheduling in here
+    *
+    * Synchronizing on lock: a failure to get scheduled must result in a wait() call and a
+    * release of the lock.  Schedulation must return with lock.
+    *
+    */
+   public void schedule(Transaction miTx, org.jboss.aop.joinpoint.Invocation mi)
+           throws Exception
+   {
+      boolean trace = log.isTraceEnabled();
+      this.sync();
+      try
+      {
+         if (trace) log.trace("Begin schedule");
+
+         if (isTxExpired(miTx))
+         {
+            log.error("Saw rolled back tx=" + miTx);
+            throw new RuntimeException("Transaction marked for rollback, possibly a timeout");
+         }
+
+         //Next test is independent of whether the context is locked or not, it is purely transactional
+         // Is the instance involved with another transaction? if so we implement pessimistic locking
+         waitForTx(mi, miTx, trace);
+         if (!isSynchronized)
+         {
+            isSynchronized = true;
+            miTx.registerSynchronization(new TxLockSynchronization());
+         }
+      }
+      finally
+      {
+         this.releaseSync();
+      }
+
+   }
+
+   /**
+    * Wait until no other transaction is running with this lock.
+    *
+    * @return    Returns true if this thread was scheduled in txWaitQueue
+    */
+   protected void waitForTx(org.jboss.aop.joinpoint.Invocation mi, Transaction miTx, boolean trace) throws Exception
+   {
+      boolean wasScheduled = false;
+      // Do we have a running transaction with the context?
+      // We loop here until either until success or until transaction timeout
+      // If we get out of the loop successfully, we can successfully
+      // set the transaction on this puppy.
+      TxLock txLock = null;
+      while (getTransaction() != null &&
+              // And are we trying to enter with another transaction?
+              !getTransaction().equals(miTx))
+      {
+         // Check for a deadlock on every cycle
+         try
+         {
+            DeadlockDetector.singleton.deadlockDetection(miTx, this);
+         }
+         catch (Exception e)
+         {
+            // We were queued, not any more
+            if (txLock != null && txLock.isQueued)
+            {
+               txLocks.remove(txLock);
+               txWaitQueue.remove(txLock);
+            }
+            throw e;
+         }
+
+         wasScheduled = true;
+         // That's no good, only one transaction per context
+         // Let's put the thread to sleep the transaction demarcation will wake them up
+         if (trace) log.trace("Transactional contention on context miTx=" + miTx + " " + toString());
+
+         if (txLock == null)
+            txLock = getTxLock(miTx);
+
+         if (trace) log.trace("Begin wait on " + txLock + " " + toString());
+
+         // And lock the threads on the lock corresponding to the Tx in MI
+         synchronized (txLock)
+         {
+            releaseSync();
+            try
+            {
+               int txTimeout = 0;
+               Integer timeout = (Integer) mi.getMetaData(TXLOCK, TIMEOUT);
+               if (timeout != null) txTimeout = timeout.intValue();
+               txLock.wait(txTimeout);
+            }
+            catch (InterruptedException ignored)
+            {
+            }
+         } // end synchronized(txLock)
+
+         this.sync();
+
+         if (trace) log.trace("End wait on " + txLock + " " + toString());
+         if (isTxExpired(miTx))
+         {
+            log.error(Thread.currentThread() + "Saw rolled back tx=" + miTx + " waiting for txLock");
+            if (txLock.isQueued)
+            {
+               // Remove the TxLock from the queue because this thread is exiting.
+               // Don't worry about notifying other threads that share the same transaction.
+               // They will timeout and throw the below RuntimeException
+               txLocks.remove(txLock);
+               txWaitQueue.remove(txLock);
+            }
+            else if (getTransaction() != null && getTransaction().equals(miTx))
+            {
+               // We're not qu
+               nextTransaction(trace);
+            }
+            if (miTx != null)
+            {
+               DeadlockDetector.singleton.removeWaiting(miTx);
+            }
+            throw new RuntimeException("Transaction marked for rollback, possibly a timeout");
+         }
+      } // end while(tx!=miTx)
+
+      // If we get here, this means that we have the txlock
+      if (!wasScheduled) setTransaction(miTx);
+      return;
+   }
+
+   /*
+    * nextTransaction()
+    *
+    * nextTransaction will
+    * - set the current tx to null
+    * - schedule the next transaction by notifying all threads waiting on the transaction
+    * - setting the thread with the new transaction so there is no race with incoming calls
+    */
+   protected void nextTransaction(boolean trace)
+   {
+      if (!synched)
+      {
+         throw new IllegalStateException("do not call nextTransaction while not synched!");
+      }
+
+      setTransaction(null);
+      // is there a waiting list?
+      TxLock thelock = null;
+      if (!txWaitQueue.isEmpty())
+      {
+         thelock = (TxLock) txWaitQueue.removeFirst();
+         txLocks.remove(thelock);
+         thelock.isQueued = false;
+         // The new transaction is the next one, important to set it up to avoid race with
+         // new incoming calls
+         if (thelock.waitingTx != null)
+            DeadlockDetector.singleton.removeWaiting(thelock.waitingTx);
+         setTransaction(thelock.waitingTx);
+         synchronized (thelock)
+         {
+            // notify All threads waiting on this transaction.
+            // They will enter the methodLock wait loop.
+            thelock.notifyAll();
+         }
+      }
+      if (trace)
+         log.trace("nextTransaction: " + thelock + " " + toString());
+   }
+
+   public void endTransaction()
+   {
+      boolean trace = log.isTraceEnabled();
+      if (trace)
+         log.trace("endTransaction: " + toString());
+      nextTransaction(trace);
+   }
+
+   public void endInvocation(Transaction thetx)
+   {
+      if (log.isTraceEnabled())
+         log.trace("endInvocation: miTx=" + thetx + " " + toString());
+   }
+
+   public String toString()
+   {
+      StringBuffer buffer = new StringBuffer(100);
+      buffer.append(" hash=").append(hashCode());
+      buffer.append(" tx=").append(getTransaction());
+      buffer.append(" synched=").append(synched);
+      buffer.append(" queue=").append(txWaitQueue);
+      return buffer.toString();
+   }
+
+   private final class TxLockSynchronization implements Synchronization
+   {
+      public void beforeCompletion()
+      {
+      }
+
+      public void afterCompletion(int status)
+      {
+         try
+         {
+            sync();
+         }
+         catch (InterruptedException ignored)
+         {
+         }
+         isSynchronized = false;
+         endTransaction();
+         releaseSync();
+      }
+   }
+}
+

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptor.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptor.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptor.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,83 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.txlock;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.logging.Logger;
+
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ *  This interceptor handles chooses an object to invoke
+ *  on based on the transaction
+ *
+ *  @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ *  @version $Revision: 37406 $
+ */
+public class TxLockInterceptor implements org.jboss.aop.advice.Interceptor
+{
+   /**
+    * Logging instance
+    */
+   protected Logger log = Logger.getLogger(this.getClass());
+
+   private final TransactionManager tm;
+   private final QueuedTxLock lock;
+
+   public TxLockInterceptor(TransactionManager tm, QueuedTxLock lock)
+   {
+      this.tm = tm;
+      this.lock = lock;
+   }
+
+   public String getName()
+   {
+      return "TxLockInterceptor";
+   }
+
+   /**
+    *
+    */
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      Transaction tx = tm.getTransaction();
+      if (tx == null) return invocation.invokeNext();
+
+      else
+      {
+      }
+
+
+      lock.schedule(tx, invocation);
+      try
+      {
+         return invocation.invokeNext();
+      }
+      finally
+      {
+         lock.endInvocation(tx);
+      }
+   }
+
+
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptorFactory.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptorFactory.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxLockInterceptorFactory.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,99 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.txlock;
+
+import org.jboss.aop.Advisor;
+import org.jboss.aop.InstanceAdvisor;
+import org.jboss.aop.joinpoint.Joinpoint;
+import org.jboss.aop.metadata.SimpleMetaData;
+import org.jboss.aop.util.PayloadKey;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.transaction.TransactionManager;
+
+/**
+ *
+ *  @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ *  @version $Revision: 37406 $
+ */
+public class TxLockInterceptorFactory implements org.jboss.aop.advice.AspectFactory
+{
+
+   private static TransactionManager getTransactionManager()
+   {
+      try
+      {
+         InitialContext ctx = new InitialContext();
+         TransactionManager tm = (TransactionManager) ctx.lookup("java:/TransactionManager");
+         return tm;
+      }
+      catch (NamingException e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+
+   public Object createPerVM()
+   {
+      throw new RuntimeException("this interceptor only supports PER_CLASS and PER_INSTANCE");
+   }
+
+   public Object createPerClass(Advisor advisor)
+   {
+      QueuedTxLock lock = new QueuedTxLock();
+      advisor.getClassMetaData().addMetaData(QueuedTxLock.TXLOCK, QueuedTxLock.TXLOCK, lock, PayloadKey.TRANSIENT);
+      return new TxLockInterceptor(getTransactionManager(), lock);
+
+   }
+
+   public Object createPerInstance(Advisor advisor, InstanceAdvisor instanceAdvisor)
+   {
+      SimpleMetaData instanceData = instanceAdvisor.getMetaData();
+      QueuedTxLock lock = null;
+      synchronized(instanceData)
+      {
+         lock = (QueuedTxLock)instanceData.getMetaData(QueuedTxLock.TXLOCK, QueuedTxLock.TXLOCK);
+         if (lock == null)
+         {
+            lock = new QueuedTxLock();
+            instanceData.addMetaData(QueuedTxLock.TXLOCK, QueuedTxLock.TXLOCK, lock, PayloadKey.TRANSIENT);
+         }
+      }
+      return new TxLockInterceptor(getTransactionManager(), lock);
+   }
+
+   public Object createPerJoinpoint(Advisor advisor, Joinpoint jp)
+   {
+      throw new RuntimeException("this interceptor only supports PER_CLASS and PER_INSTANCE");
+   }
+
+   public Object createPerJoinpoint(Advisor advisor, InstanceAdvisor instanceAdvisor, Joinpoint jp)
+   {
+      throw new RuntimeException("this interceptor only supports PER_CLASS and PER_INSTANCE");
+   }
+
+   public String getName()
+   {
+      return getClass().getName();
+   }
+}

Added: projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxSynchronized.java
===================================================================
--- projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxSynchronized.java	                        (rev 0)
+++ projects/jboss-aspects/trunk/transaction/src/main/org/jboss/aspects/txlock/TxSynchronized.java	2008-04-10 16:43:24 UTC (rev 71959)
@@ -0,0 +1,33 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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.aspects.txlock;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ *
+ *  @author <a href="mailto:bill at jboss.org">Bill Burke</a>
+ *  @version $Revision: 57757 $
+ */
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface TxSynchronized {}




More information about the jboss-cvs-commits mailing list