summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-01-21 21:38:00 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-01-21 21:38:00 +0000
commit1b44691db49f01e73ee419d483075ed51256b77d (patch)
tree81ec7f0ed7edbcafef4df0ed52468f3f710895e0 /sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org
parent0269f4bdcdd988aa67b911a3b1f3b3874da18304 (diff)
TUSCANY-3433 - add policy transaction from 1.x. Different here is that code is changed to match 2.x SPI and the "runtime" parts are in a separate package.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@901868 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicy.java49
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyImpl.java59
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyProcessor.java98
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/IncompatibleIntentException.java44
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java65
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionIntent.java35
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionInterceptor.java129
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerHelper.java243
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerWrapper.java90
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionModuleActivator.java89
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionPolicyProviderFactory.java62
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java63
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java62
-rw-r--r--sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionalAction.java31
14 files changed, 1119 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicy.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicy.java
new file mode 100644
index 0000000000..12ef603d01
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicy.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ * The model for Tuscany transaction policy.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface TransactionPolicy {
+ QName NAME = new QName(Constants.SCA11_TUSCANY_NS, "transactionPolicy");
+
+ enum Action {
+ PROPAGATE,
+ SUSPEND,
+ REQUIRE_GLOBAL,
+ REQUIRE_LOCAL,
+ REQUIRE_NONE
+ };
+
+ int getTransactionTimeout();
+
+ void setTransactionTimeout(int seconds);
+
+ void setAction(Action action);
+
+ Action getAction();
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyImpl.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyImpl.java
new file mode 100644
index 0000000000..f178876a72
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionPolicyImpl implements TransactionPolicy {
+ private boolean unresolved;
+ private int transactionTimeout = 1200;
+ private Action action = Action.PROPAGATE;
+
+ public int getTransactionTimeout() {
+ return transactionTimeout;
+ }
+
+ public void setTransactionTimeout(int transactionTimeout) {
+ this.transactionTimeout = transactionTimeout;
+ }
+
+ public Action getAction() {
+ return action;
+ }
+
+ public void setAction(Action policy) {
+ this.action = policy;
+ }
+
+ public QName getSchemaName() {
+ return NAME;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyProcessor.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyProcessor.java
new file mode 100644
index 0000000000..341cfc0016
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionPolicyProcessor.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.transaction;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
+import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionPolicyProcessor implements StAXArtifactProcessor<TransactionPolicy> {
+ public static final String TIMEOUT = "transactionTimeout";
+ public static final String ACTION = "action";
+
+ public QName getArtifactType() {
+ return TransactionPolicy.NAME;
+ }
+
+ public TransactionPolicyProcessor(FactoryExtensionPoint modelFactories) {
+ }
+
+ public TransactionPolicy read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
+ TransactionPolicy txPolicy = new TransactionPolicyImpl();
+ int event = reader.getEventType();
+ while (reader.hasNext()) {
+ event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT: {
+ String timeout = reader.getAttributeValue(null, TIMEOUT);
+ if (timeout != null) {
+ txPolicy.setTransactionTimeout(Integer.parseInt(timeout));
+ }
+ String action = reader.getAttributeValue(null, ACTION);
+ if (action != null) {
+ txPolicy.setAction(TransactionPolicy.Action.valueOf(action));
+ }
+ break;
+ }
+ }
+
+ if (event == END_ELEMENT) {
+ if (TransactionPolicy.NAME.equals(reader.getName())) {
+ break;
+ }
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+
+ return txPolicy;
+ }
+
+ public void write(TransactionPolicy policy, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException,
+ XMLStreamException {
+ // TODO
+ }
+
+ public Class<TransactionPolicy> getModelType() {
+ return TransactionPolicy.class;
+ }
+
+ public void resolve(TransactionPolicy policy, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {
+ // TODO
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/IncompatibleIntentException.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/IncompatibleIntentException.java
new file mode 100644
index 0000000000..e3cb6fc359
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/IncompatibleIntentException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleIntentException extends Exception {
+ private static final long serialVersionUID = -2993825019200280397L;
+
+ public IncompatibleIntentException() {
+ super();
+ }
+
+ public IncompatibleIntentException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public IncompatibleIntentException(String message) {
+ super(message);
+ }
+
+ public IncompatibleIntentException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java
new file mode 100644
index 0000000000..10d62e9ee3
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionImplementationPolicyProvider.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.transaction.TransactionPolicy;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionImplementationPolicyProvider extends BasePolicyProvider<TransactionPolicy> {
+ private TransactionManagerHelper helper;
+ private List<PolicySet> policySets;
+ private RuntimeComponent component;
+
+ public TransactionImplementationPolicyProvider(TransactionManagerHelper helper, RuntimeComponent component) {
+ super(TransactionPolicy.class, component);
+ this.helper = helper;
+ this.policySets = component.getPolicySets();
+ }
+
+ public PhasedInterceptor createInterceptor(Operation operation) {
+/* TODO - 2.x better way of doing this in 2.x */
+ for (PolicySet policySet : policySets) {
+ for (Object p : policySet.getPolicies()) {
+ if (p instanceof TransactionPolicy) {
+ TransactionInterceptor interceptor =
+ new TransactionInterceptor(helper, false, (TransactionPolicy)p, null);
+ return interceptor;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public String getPhase() {
+ return Phase.IMPLEMENTATION_POLICY;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionIntent.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionIntent.java
new file mode 100644
index 0000000000..ac17eb9f99
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionIntent.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public enum TransactionIntent {
+ managedTransactionLocal,
+ managedTransactionGlobal,
+ noManagedTransaction,
+ propagatesTransacton,
+ suspendsTransaction,
+ transactedOneWay,
+ immediateOneWay,
+ managedSharedTransaction
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionInterceptor.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionInterceptor.java
new file mode 100644
index 0000000000..c40cf96329
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionInterceptor.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.transaction.TransactionPolicy;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionInterceptor implements PhasedInterceptor {
+ private Invoker next;
+ private TransactionManagerHelper helper;
+ private boolean outbound;
+ private TransactionPolicy interactionPolicy;
+ private TransactionPolicy implementationPolicy;
+
+ public TransactionInterceptor(TransactionManagerHelper helper,
+ boolean outbound,
+ TransactionPolicy interactionPolicy,
+ TransactionPolicy implementationPolicy) {
+ super();
+ this.helper = helper;
+ this.outbound = outbound;
+ this.interactionPolicy = interactionPolicy;
+ this.implementationPolicy = implementationPolicy;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.Interceptor#getNext()
+ */
+ public Invoker getNext() {
+ return next;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.Interceptor#setNext(org.apache.tuscany.sca.invocation.Invoker)
+ */
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message)
+ */
+ public Message invoke(Message msg) {
+ TransactionalInvocation invocation = new TransactionalInvocation(next, msg);
+
+ Message result = null;
+ if (msg.getOperation().isNonBlocking()) {
+
+ }
+ TransactionIntent interactionIntent = TransactionIntent.propagatesTransacton;
+ if (interactionPolicy != null) {
+ if (interactionPolicy.getAction() == TransactionPolicy.Action.PROPAGATE) {
+ interactionIntent = TransactionIntent.propagatesTransacton;
+ } else {
+ interactionIntent = TransactionIntent.suspendsTransaction;
+ }
+ }
+ TransactionIntent implementationIntent = TransactionIntent.managedTransactionGlobal;
+ if (implementationPolicy != null) {
+ switch (implementationPolicy.getAction()) {
+ case REQUIRE_GLOBAL:
+ implementationIntent = TransactionIntent.managedTransactionGlobal;
+ break;
+ case REQUIRE_LOCAL:
+ implementationIntent = TransactionIntent.managedTransactionLocal;
+ break;
+ default:
+ implementationIntent = TransactionIntent.noManagedTransaction;
+ break;
+ }
+ }
+ try {
+ if (outbound) {
+ result = helper.handlesOutbound(interactionIntent, implementationIntent, invocation);
+ } else {
+ result = helper.handlesInbound(interactionIntent, implementationIntent, invocation);
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ private static class TransactionalInvocation implements TransactionalAction<Message> {
+ private final Invoker invoker;
+ private final Message message;
+
+ public TransactionalInvocation(Invoker invoker, Message message) {
+ super();
+ this.invoker = invoker;
+ this.message = message;
+ }
+
+ public Message run() throws Exception {
+ return invoker.invoke(message);
+ }
+
+ }
+
+ public String getPhase() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerHelper.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerHelper.java
new file mode 100644
index 0000000000..71f32093d1
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerHelper.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import java.lang.reflect.InvocationTargetException;
+
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.InvalidTransactionException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.Status;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionManagerHelper {
+ // private static final Logger logger = Logger.getLogger(TransactionManagerHelper.class.getName());
+
+ private TransactionManager tm;
+
+ public TransactionManagerHelper(TransactionManager tm) {
+ super();
+ this.tm = tm;
+ }
+
+ public Transaction managedGlobalTransactionPreInvoke() throws SystemException, NotSupportedException {
+ int status = tm.getStatus();
+ if (status == Status.STATUS_COMMITTED || status == Status.STATUS_NO_TRANSACTION
+ || status == Status.STATUS_ROLLEDBACK) {
+ tm.begin();
+ return tm.getTransaction();
+ }
+ return null;
+ }
+
+ public void managedGlobalTransactionPostInvoke(Transaction created, boolean rollback)
+ throws InvalidTransactionException, IllegalStateException, SystemException, SecurityException,
+ HeuristicMixedException, HeuristicRollbackException, RollbackException {
+ if (created != null) {
+ int status = created.getStatus();
+ if (status == Status.STATUS_MARKED_ROLLBACK) {
+ created.rollback();
+ } else if (status == Status.STATUS_ACTIVE) {
+ if (rollback) {
+ created.rollback();
+ } else {
+ created.commit();
+ }
+ }
+ }
+ }
+
+ public Transaction suspendsTransactionPreInvoke() throws SystemException {
+ if (tm.getTransaction() != null) {
+ return tm.suspend();
+ } else {
+ return null;
+ }
+ }
+
+ public void suspendsTransactionPostInvoke(Transaction suspended) throws InvalidTransactionException,
+ IllegalStateException, SystemException {
+ if (suspended != null) {
+ tm.resume(suspended);
+ }
+ }
+
+ public TransactionManager getTransactionManager() {
+ return tm;
+ }
+
+ public void setTransactionManager(TransactionManager tm) {
+ this.tm = tm;
+ }
+
+ public void validateOneway(TransactionIntent onewayIntent, TransactionIntent implIntent)
+ throws IncompatibleIntentException {
+ if (onewayIntent == TransactionIntent.transactedOneWay) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(onewayIntent + "<-X->" + implIntent);
+ }
+ }
+ }
+
+ public void validateInbound(TransactionIntent serviceIntent, TransactionIntent implIntent)
+ throws IncompatibleIntentException {
+ if (serviceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(serviceIntent + "<-X->" + implIntent);
+ }
+ }
+ }
+
+ public void validateOutbound(TransactionIntent referenceIntent, TransactionIntent implIntent)
+ throws IncompatibleIntentException {
+ if (referenceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(referenceIntent + "<-X->" + implIntent);
+ }
+ }
+ }
+
+ public <T> T handlesOutbound(TransactionIntent referenceIntent,
+ TransactionIntent implIntent,
+ TransactionalAction<T> action) throws Exception {
+
+ if (implIntent == null) {
+ implIntent = TransactionIntent.noManagedTransaction;
+ }
+
+ if (referenceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(referenceIntent + "<-X->" + implIntent);
+ } else {
+ // propagates the current TX
+ return run(action);
+ }
+ } else if (referenceIntent == TransactionIntent.suspendsTransaction) {
+ Transaction tx = suspendsTransactionPreInvoke();
+ try {
+ return run(action);
+ } finally {
+ suspendsTransactionPostInvoke(tx);
+ }
+ } else {
+ return run(action);
+ }
+ }
+
+ private <T> T run(TransactionalAction<T> action) throws Exception {
+ // Make sure a global TX is in place
+ Transaction tx = managedGlobalTransactionPreInvoke();
+ boolean rollback = false;
+ try {
+ return action.run();
+ } catch (InvocationTargetException e) {
+ throw e;
+ } catch (Throwable e) {
+ rollback = true;
+ if (e instanceof Error) {
+ throw (Error)e;
+ } else if (e instanceof RuntimeException) {
+ throw (RuntimeException)e;
+ } else {
+ throw (Exception)e;
+ }
+ } finally {
+ managedGlobalTransactionPostInvoke(tx, rollback);
+ }
+ }
+
+ public <T> T handlesInbound(TransactionIntent serviceIntent,
+ TransactionIntent implIntent,
+ TransactionalAction<T> action) throws Exception {
+ if (serviceIntent == null && implIntent == null) {
+ return run(action);
+ }
+
+ if (implIntent == null) {
+ implIntent = TransactionIntent.noManagedTransaction;
+ }
+
+ if (serviceIntent == TransactionIntent.propagatesTransacton) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(serviceIntent + "<-X->" + implIntent);
+ } else {
+ return run(action);
+ }
+ } else if (serviceIntent == TransactionIntent.suspendsTransaction) {
+ Transaction tx1 = suspendsTransactionPreInvoke();
+ try {
+ if (implIntent == TransactionIntent.managedTransactionGlobal) {
+ return run(action);
+ } else {
+ return action.run();
+ }
+ } finally {
+ suspendsTransactionPostInvoke(tx1);
+ }
+ } else {
+ if (implIntent == TransactionIntent.managedTransactionGlobal) {
+ // Start a new TX
+ return run(action);
+ } else {
+ return action.run();
+ }
+ }
+ }
+
+ public <T> void handlesOneWay(TransactionIntent onewayIntent,
+ TransactionIntent implIntent,
+ TransactionalAction<T> action) throws Exception {
+ if (implIntent == null) {
+ implIntent = TransactionIntent.noManagedTransaction;
+ }
+
+ if (onewayIntent == null) {
+ // Assume transactedOneWay
+ run(action);
+ return;
+ }
+
+ if (onewayIntent == TransactionIntent.transactedOneWay) {
+ if (implIntent != TransactionIntent.managedTransactionGlobal) {
+ throw new IncompatibleIntentException(onewayIntent + "<-X->" + implIntent);
+ } else {
+ run(action);
+ return;
+ }
+ } else {
+ // TransactionIntent.immediateOneWay
+ Transaction tx = suspendsTransactionPreInvoke();
+ try {
+ run(action);
+ return;
+ } finally {
+ suspendsTransactionPostInvoke(tx);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerWrapper.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerWrapper.java
new file mode 100644
index 0000000000..eac7293e62
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionManagerWrapper.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import java.io.File;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.geronimo.transaction.log.HOWLLog;
+import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+import org.apache.geronimo.transaction.manager.XidFactory;
+import org.apache.geronimo.transaction.manager.XidFactoryImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionManagerWrapper {
+ private TransactionManager transactionManager;
+ private HOWLLog howlLog;
+
+ private String logFileDir = "target/logs";
+ private String bufferClassName = "org.objectweb.howl.log.BlockLogBuffer";
+ private int bufferSizeKBytes = 32;
+ private boolean checksumEnabled = true;
+ private boolean adler32Checksum = true;
+ private int flushSleepTimeMilliseconds = 50;
+ private String logFileExt = "log";
+ private String logFileName = "transaction";
+ private int maxBlocksPerFile = -1;
+ private int maxLogFiles = 2;
+ private int maxBuffers = 0;
+ private int minBuffers = 4;
+ private int threadsWaitingForceThreshold = -1;
+ private File serverBaseDir = new File(System.getProperty("basedir", System.getProperty("user.dir")));
+
+ public TransactionManagerWrapper() {
+ super();
+ }
+
+ public void start() {
+ try {
+ XidFactory xidFactory = new XidFactoryImpl();
+ howlLog =
+ new HOWLLog(bufferClassName, bufferSizeKBytes, checksumEnabled, adler32Checksum,
+ flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile,
+ maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold, xidFactory,
+ serverBaseDir);
+
+ howlLog.doStart();
+ transactionManager = new GeronimoTransactionManager(1200, xidFactory, howlLog);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.ModuleActivator#stop(org.apache.tuscany.sca.core.ExtensionPointRegistry)
+ */
+ public void stop() {
+ try {
+ if (howlLog != null) {
+ howlLog.doStop();
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ public TransactionManager getTransactionManager() {
+ return transactionManager;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionModuleActivator.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionModuleActivator.java
new file mode 100644
index 0000000000..b027f3c117
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionModuleActivator.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import javax.transaction.TransactionManager;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionModuleActivator implements ModuleActivator {
+ private TransactionManagerWrapper wrapper;
+ private ExtensionPointRegistry registry;
+
+ public TransactionModuleActivator(ExtensionPointRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.ModuleActivator#start(org.apache.tuscany.sca.core.ExtensionPointRegistry)
+ */
+ public void start() {
+ if (registry != null) {
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ TransactionManager transactionManager = utilities.getUtility(TransactionManager.class);
+ if (transactionManager != null) {
+ // The transaction manage is provided by the hosting environment
+// RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint =
+// registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+// TransactionManagerHelper helper = new TransactionManagerHelper(transactionManager);
+// wireProcessorExtensionPoint.addWireProcessor(new TransactionRuntimeWireProcessor(helper));
+ return;
+ }
+ }
+ try {
+ wrapper = new TransactionManagerWrapper();
+ wrapper.start();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ if (registry != null) {
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ utilities.addUtility(wrapper.getTransactionManager());
+// RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint =
+// registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+// TransactionManagerHelper helper = new TransactionManagerHelper(wrapper.getTransactionManager());
+// wireProcessorExtensionPoint.addWireProcessor(new TransactionRuntimeWireProcessor(helper));
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.ModuleActivator#stop(org.apache.tuscany.sca.core.ExtensionPointRegistry)
+ */
+ public void stop() {
+ try {
+ if (wrapper != null) {
+ wrapper.stop();
+ wrapper = null;
+ }
+ if (registry != null && wrapper != null) {
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ utilities.removeUtility(wrapper.getTransactionManager());
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionPolicyProviderFactory.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionPolicyProviderFactory.java
new file mode 100644
index 0000000000..726d3e7c91
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionPolicyProviderFactory.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import javax.transaction.TransactionManager;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.policy.transaction.TransactionPolicy;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionPolicyProviderFactory implements PolicyProviderFactory<TransactionPolicy> {
+ private TransactionManagerHelper helper;
+
+ public TransactionPolicyProviderFactory(ExtensionPointRegistry registry) {
+ super();
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ TransactionManager tm = utilities.getUtility(TransactionManager.class);
+ this.helper = new TransactionManagerHelper(tm);
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component) {
+ return new TransactionImplementationPolicyProvider(helper, component);
+ }
+
+ public PolicyProvider createReferencePolicyProvider(EndpointReference endpointReference) {
+ return new TransactionReferencePolicyProvider(helper, endpointReference);
+ }
+
+ public PolicyProvider createServicePolicyProvider(Endpoint endpoint) {
+ return new TransactionServicePolicyProvider(helper, endpoint);
+ }
+
+ public Class<TransactionPolicy> getModelType() {
+ return TransactionPolicy.class;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java
new file mode 100644
index 0000000000..63ed674583
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionReferencePolicyProvider.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.EndpointReference;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.transaction.TransactionPolicy;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionReferencePolicyProvider extends BasePolicyProvider<TransactionPolicy> {
+ private TransactionManagerHelper helper;
+ private List<PolicySet> policySets;
+
+ public TransactionReferencePolicyProvider(TransactionManagerHelper helper, EndpointReference epr) {
+ super(TransactionPolicy.class, epr);
+ this.helper = helper;
+ this.policySets = epr.getPolicySets();
+ }
+
+ public PhasedInterceptor createInterceptor(Operation operation) {
+/* TODO - 2.x better way of doing this in 2.x */
+ for (PolicySet policySet : policySets) {
+ for (Object p : policySet.getPolicies()) {
+ if (p instanceof TransactionPolicy) {
+ TransactionInterceptor interceptor =
+ new TransactionInterceptor(helper, true, (TransactionPolicy)p, null);
+ return interceptor;
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getPhase() {
+ return Phase.REFERENCE_POLICY;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java
new file mode 100644
index 0000000000..d163fd4781
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionServicePolicyProvider.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.invocation.PhasedInterceptor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.transaction.TransactionPolicy;
+import org.apache.tuscany.sca.provider.BasePolicyProvider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TransactionServicePolicyProvider extends BasePolicyProvider<TransactionPolicy> {
+ private TransactionManagerHelper helper;
+ private List<PolicySet> policySets;
+
+ public TransactionServicePolicyProvider(TransactionManagerHelper helper, Endpoint ep) {
+ super(TransactionPolicy.class, ep);
+ this.helper = helper;
+ this.policySets = ep.getPolicySets();
+ }
+
+ public PhasedInterceptor createInterceptor(Operation operation) {
+ for (PolicySet policySet : policySets) {
+ for (Object p : policySet.getPolicies()) {
+ if (p instanceof TransactionPolicy) {
+ TransactionInterceptor interceptor =
+ new TransactionInterceptor(helper, true, (TransactionPolicy)p, null);
+ return interceptor;
+ }
+ }
+ }
+ return null;
+ }
+
+ public String getPhase() {
+ return Phase.SERVICE_POLICY;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionalAction.java b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionalAction.java
new file mode 100644
index 0000000000..2785177000
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/runtime/TransactionalAction.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.transaction.runtime;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface TransactionalAction<T> {
+ /**
+ * @return
+ * @throws Exception
+ */
+ T run() throws Exception;
+}