View Javadoc
1   /*
2    * Copyright 2002-2014 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
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.lang.reflect.Method;
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  /**
24   * Inherits fallback behavior from AbstractFallbackTransactionAttributeSource.
25   *
26   * @author Rod Johnson
27   * @author Juergen Hoeller
28   */
29  public class MapTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource {
30  
31  	private final Map<Object, TransactionAttribute> attributeMap = new HashMap<Object, TransactionAttribute>();
32  
33  
34  	public void register(Method method, TransactionAttribute txAtt) {
35  		this.attributeMap.put(method, txAtt);
36  	}
37  
38  	public void register(Class<?> clazz, TransactionAttribute txAtt) {
39  		this.attributeMap.put(clazz, txAtt);
40  	}
41  
42  
43  	@Override
44  	protected TransactionAttribute findTransactionAttribute(Method method) {
45  		return this.attributeMap.get(method);
46  	}
47  
48  	@Override
49  	protected TransactionAttribute findTransactionAttribute(Class<?> clazz) {
50  		return this.attributeMap.get(clazz);
51  	}
52  
53  }