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;
17:
18: import javax.transaction.UserTransaction;
19: import javax.transaction.NotSupportedException;
20: import javax.transaction.SystemException;
21: import javax.transaction.HeuristicMixedException;
22: import javax.transaction.HeuristicRollbackException;
23: import javax.transaction.RollbackException;
24:
25: /**
26: * @version $Rev: 602704 $ $Date: 2007-12-09 09:58:22 -0800 $
27: */
28: public class RestrictedUserTransaction implements UserTransaction {
29: private final UserTransaction userTransaction;
30:
31: public RestrictedUserTransaction(UserTransaction userTransaction) {
32: this .userTransaction = userTransaction;
33: }
34:
35: public void begin() throws NotSupportedException, SystemException {
36: checkAccess("begin");
37: userTransaction.begin();
38: }
39:
40: public void commit() throws HeuristicMixedException,
41: HeuristicRollbackException, IllegalStateException,
42: RollbackException, SecurityException, SystemException {
43: checkAccess("commit");
44: userTransaction.commit();
45: }
46:
47: public int getStatus() throws SystemException {
48: checkAccess("getStatus");
49: return userTransaction.getStatus();
50: }
51:
52: public void rollback() throws IllegalStateException,
53: SecurityException, SystemException {
54: checkAccess("rollback");
55: userTransaction.rollback();
56: }
57:
58: public void setRollbackOnly() throws IllegalStateException,
59: SystemException {
60: checkAccess("setRollbackOnly");
61: userTransaction.setRollbackOnly();
62: }
63:
64: public void setTransactionTimeout(int i) throws SystemException {
65: checkAccess("setTransactionTimeout");
66: userTransaction.setTransactionTimeout(i);
67: }
68:
69: private void checkAccess(String methodName) {
70: Operation operation = ThreadContext.getThreadContext()
71: .getCurrentOperation();
72: if (operation == Operation.POST_CONSTRUCT) {
73: throw new IllegalStateException("userTransaction."
74: + methodName + "() not allowed in PostConstruct");
75: }
76: }
77: }
|