KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > transaction > interceptor > MapTransactionAttributeSource


1 /*
2  * Copyright 2002-2005 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 JavaDoc;
20 import java.util.Collection JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.HashMap JavaDoc;
23
24 /**
25  * Inherits fallback behaviour from AbstractFallbackTransactionAttributeSource
26  * @author Rod Johnson
27  */

28 public class MapTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource {
29     
30     /**
31      * Map from Method or Clazz to TransactionAttribute
32      */

33     private HashMap JavaDoc attributeMap = new HashMap JavaDoc();
34     
35     public void register(Method JavaDoc m, TransactionAttribute txAtt) {
36         attributeMap.put(m, txAtt);
37     }
38     
39     public void register(Class JavaDoc clazz, TransactionAttribute txAtt) {
40         attributeMap.put(clazz, txAtt);
41     }
42     
43     /**
44      * @see org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource#findAllAttributes(java.lang.Class)
45      */

46     protected Collection JavaDoc findAllAttributes(Class JavaDoc clazz) {
47         return doFindAllAttributes(clazz);
48     }
49     
50     /**
51      * @see org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource#findAllAttributes(java.lang.reflect.Method)
52      */

53     protected Collection JavaDoc findAllAttributes(Method JavaDoc m) {
54         return doFindAllAttributes(m);
55     }
56     
57     private Collection JavaDoc doFindAllAttributes(Object JavaDoc what) {
58         //System.out.println("Trying key " + what);
59
Object JavaDoc att = attributeMap.get(what);
60         return att != null ? Collections.singleton(att) : null;
61     }
62     
63
64 }
65
Popular Tags