01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.openejb.core.stateful;
17:
18: import org.apache.openejb.ApplicationException;
19: import org.apache.openejb.InvalidateReferenceException;
20: import org.apache.openejb.ContainerType;
21: import org.apache.openejb.SystemException;
22: import org.apache.openejb.core.transaction.TransactionContext;
23: import org.apache.openejb.core.transaction.TransactionPolicy;
24:
25: /**
26: * Wraps the TxPolicies for Stateful Session beans with container-managed
27: * transaction demarkation that do not implement the SessionSynchronization
28: * interface.
29: *
30: * The following method TxPolicies are wrapped regardless:
31: *
32: * TX_NEVER
33: * TX_NOT_SUPPORTED
34: */
35: public class StatefulContainerManagedTxPolicy extends TransactionPolicy {
36:
37: protected TransactionPolicy policy;
38:
39: public StatefulContainerManagedTxPolicy(TransactionPolicy policy) {
40: super (policy.getPolicyType(), policy.getContainer());
41: this .policy = policy;
42: if (container.getContainerType() != ContainerType.STATEFUL) {
43: throw new IllegalArgumentException();
44: }
45: }
46:
47: public String policyToString() {
48: return policy.policyToString();
49: }
50:
51: public void beforeInvoke(Object instance, TransactionContext context)
52: throws SystemException, ApplicationException {
53: policy.beforeInvoke(instance, context);
54: }
55:
56: public void afterInvoke(Object instance, TransactionContext context)
57: throws ApplicationException, SystemException {
58: policy.afterInvoke(instance, context);
59: }
60:
61: public void handleApplicationException(Throwable appException,
62: boolean rollback, TransactionContext context)
63: throws ApplicationException, SystemException {
64: policy.handleApplicationException(appException, rollback,
65: context);
66: }
67:
68: public void handleSystemException(Throwable sysException,
69: Object instance, TransactionContext context)
70: throws ApplicationException, SystemException {
71: try {
72: policy.handleSystemException(sysException, instance,
73: context);
74: } catch (InvalidateReferenceException e) {
75: throw e;
76: } catch (ApplicationException e) {
77: // DMB: Not sure we want this here
78: throw new InvalidateReferenceException(e.getRootCause());
79: }
80: }
81:
82: }
|