KickJava   Java API By Example, From Geeks To Geeks.

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


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.lang.reflect.Method JavaDoc;
20 import java.util.Collection JavaDoc;
21
22 import org.springframework.beans.factory.InitializingBean;
23 import org.springframework.metadata.Attributes;
24 import org.springframework.util.Assert;
25 import org.springframework.util.ObjectUtils;
26
27 /**
28  * Implementation of the <code>TransactionAttributeSource</code> interface that
29  * reads metadata via Spring's <code>Attributes</code> abstraction.
30  *
31  * <p>Typically used for reading in source-level attributes via
32  * Commons Attributes.
33  *
34  * @author Rod Johnson
35  * @author Juergen Hoeller
36  * @see org.springframework.metadata.Attributes
37  * @see org.springframework.metadata.commons.CommonsAttributes
38  */

39 public class AttributesTransactionAttributeSource extends AbstractFallbackTransactionAttributeSource
40         implements InitializingBean {
41     
42     /**
43      * Underlying Attributes implementation that we're using.
44      */

45     private Attributes attributes;
46
47
48     /**
49      * Create a new AttributesTransactionAttributeSource.
50      * @see #setAttributes
51      */

52     public AttributesTransactionAttributeSource() {
53     }
54
55     /**
56      * Create a new AttributesTransactionAttributeSource.
57      * @param attributes the Attributes implementation to use
58      * @see org.springframework.metadata.commons.CommonsAttributes
59      */

60     public AttributesTransactionAttributeSource(Attributes attributes) {
61         if (attributes == null) {
62             throw new IllegalArgumentException JavaDoc("Attributes is required");
63         }
64         this.attributes = attributes;
65     }
66
67     /**
68      * Set the Attributes implementation to use.
69      * @see org.springframework.metadata.commons.CommonsAttributes
70      */

71     public void setAttributes(Attributes attributes) {
72         this.attributes = attributes;
73     }
74
75     public void afterPropertiesSet() {
76         if (this.attributes == null) {
77             throw new IllegalArgumentException JavaDoc("'attributes' is required");
78         }
79     }
80
81
82     protected Collection JavaDoc findAllAttributes(Class JavaDoc clazz) {
83         Assert.notNull(this.attributes, "'attributes' is required");
84         return this.attributes.getAttributes(clazz);
85     }
86
87     protected Collection JavaDoc findAllAttributes(Method JavaDoc method) {
88         Assert.notNull(this.attributes, "'attributes' is required");
89         return this.attributes.getAttributes(method);
90     }
91
92
93     public boolean equals(Object JavaDoc other) {
94         if (this == other) {
95             return true;
96         }
97         if (!(other instanceof AttributesTransactionAttributeSource)) {
98             return false;
99         }
100         AttributesTransactionAttributeSource otherTas = (AttributesTransactionAttributeSource) other;
101         return ObjectUtils.nullSafeEquals(this.attributes, otherTas.attributes);
102     }
103
104     public int hashCode() {
105         return AttributesTransactionAttributeSource.class.hashCode();
106     }
107
108 }
109
Popular Tags