KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2006 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.io.Serializable JavaDoc;
20 import java.lang.reflect.Method JavaDoc;
21
22 import org.springframework.util.ObjectUtils;
23
24 /**
25  * Very simple implementation of TransactionAttributeSource which will always return
26  * the same TransactionAttribute for all methods fed to it. The TransactionAttribute
27  * may be specified, but will otherwise default to PROPAGATION_REQUIRED. This may be
28  * used in the cases where you want to use the same transaction attribute with all
29  * methods being handled by a transaction interceptor.
30  *
31  * @author Colin Sampaleanu
32  * @since 15.10.2003
33  * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
34  * @see org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator
35  */

36 public class MatchAlwaysTransactionAttributeSource implements TransactionAttributeSource, Serializable JavaDoc {
37   
38     private TransactionAttribute transactionAttribute = new DefaultTransactionAttribute();
39
40
41     /**
42      * Allows a transaction attribute to be specified, using the String form, for
43      * example, "PROPAGATION_REQUIRED".
44      * @param transactionAttribute The String form of the transactionAttribute to use.
45      * @see org.springframework.transaction.interceptor.TransactionAttributeEditor
46      */

47     public void setTransactionAttribute(TransactionAttribute transactionAttribute) {
48         this.transactionAttribute = transactionAttribute;
49     }
50
51
52     public TransactionAttribute getTransactionAttribute(Method JavaDoc method, Class JavaDoc targetClass) {
53         return this.transactionAttribute;
54     }
55
56
57     public boolean equals(Object JavaDoc other) {
58         if (this == other) {
59             return true;
60         }
61         if (!(other instanceof MatchAlwaysTransactionAttributeSource)) {
62             return false;
63         }
64         MatchAlwaysTransactionAttributeSource otherTas = (MatchAlwaysTransactionAttributeSource) other;
65         return ObjectUtils.nullSafeEquals(this.transactionAttribute, otherTas.transactionAttribute);
66     }
67
68     public int hashCode() {
69         return MatchAlwaysTransactionAttributeSource.class.hashCode();
70     }
71
72     public String JavaDoc toString() {
73         return getClass().getName() + ": " + this.transactionAttribute;
74     }
75
76 }
77
Popular Tags