01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.transaction.annotation;
18:
19: import java.io.Serializable;
20: import java.lang.reflect.AnnotatedElement;
21: import java.util.ArrayList;
22:
23: import org.springframework.transaction.interceptor.NoRollbackRuleAttribute;
24: import org.springframework.transaction.interceptor.RollbackRuleAttribute;
25: import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute;
26: import org.springframework.transaction.interceptor.TransactionAttribute;
27:
28: /**
29: * Strategy implementation for parsing Spring's {@link Transactional} annotation.
30: *
31: * @author Juergen Hoeller
32: * @since 2.5
33: */
34: public class SpringTransactionAnnotationParser implements
35: TransactionAnnotationParser, Serializable {
36:
37: public TransactionAttribute parseTransactionAnnotation(
38: AnnotatedElement ae) {
39: Transactional ann = ae.getAnnotation(Transactional.class);
40: if (ann != null) {
41: RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
42: rbta.setPropagationBehavior(ann.propagation().value());
43: rbta.setIsolationLevel(ann.isolation().value());
44: rbta.setTimeout(ann.timeout());
45: rbta.setReadOnly(ann.readOnly());
46: ArrayList<RollbackRuleAttribute> rollBackRules = new ArrayList<RollbackRuleAttribute>();
47: Class[] rbf = ann.rollbackFor();
48: for (int i = 0; i < rbf.length; ++i) {
49: RollbackRuleAttribute rule = new RollbackRuleAttribute(
50: rbf[i]);
51: rollBackRules.add(rule);
52: }
53: String[] rbfc = ann.rollbackForClassName();
54: for (int i = 0; i < rbfc.length; ++i) {
55: RollbackRuleAttribute rule = new RollbackRuleAttribute(
56: rbfc[i]);
57: rollBackRules.add(rule);
58: }
59: Class[] nrbf = ann.noRollbackFor();
60: for (int i = 0; i < nrbf.length; ++i) {
61: NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(
62: nrbf[i]);
63: rollBackRules.add(rule);
64: }
65: String[] nrbfc = ann.noRollbackForClassName();
66: for (int i = 0; i < nrbfc.length; ++i) {
67: NoRollbackRuleAttribute rule = new NoRollbackRuleAttribute(
68: nrbfc[i]);
69: rollBackRules.add(rule);
70: }
71: rbta.getRollbackRules().addAll(rollBackRules);
72: return rbta;
73: } else {
74: return null;
75: }
76: }
77:
78: }
|