01: /*
02: * Copyright 2002-2006 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.interceptor;
18:
19: import java.io.Serializable;
20: import java.lang.reflect.Method;
21:
22: import org.springframework.util.Assert;
23:
24: /**
25: * Composite {@link TransactionAttributeSource} implementation that iterates
26: * over a given array of {@link TransactionAttributeSource} instances.
27: *
28: * @author Juergen Hoeller
29: * @since 2.0
30: */
31: public class CompositeTransactionAttributeSource implements
32: TransactionAttributeSource, Serializable {
33:
34: private final TransactionAttributeSource[] transactionAttributeSources;
35:
36: /**
37: * Create a new CompositeTransactionAttributeSource for the given sources.
38: * @param transactionAttributeSources the TransactionAttributeSource instances to combine
39: */
40: public CompositeTransactionAttributeSource(
41: TransactionAttributeSource[] transactionAttributeSources) {
42: Assert.notNull(transactionAttributeSources,
43: "TransactionAttributeSource array must not be null");
44: this .transactionAttributeSources = transactionAttributeSources;
45: }
46:
47: /**
48: * Return the TransactionAttributeSource instances that this
49: * CompositeTransactionAttributeSource combines.
50: */
51: public final TransactionAttributeSource[] getTransactionAttributeSources() {
52: return this .transactionAttributeSources;
53: }
54:
55: public TransactionAttribute getTransactionAttribute(Method method,
56: Class targetClass) {
57: for (int i = 0; i < this .transactionAttributeSources.length; i++) {
58: TransactionAttributeSource tas = this .transactionAttributeSources[i];
59: TransactionAttribute ta = tas.getTransactionAttribute(
60: method, targetClass);
61: if (ta != null) {
62: return ta;
63: }
64: }
65: return null;
66: }
67:
68: }
|