KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > beans > factory > support > MethodOverrides


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.beans.factory.support;
18
19 import java.lang.reflect.Method JavaDoc;
20 import java.util.HashSet JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Set JavaDoc;
23
24 /**
25  * Set of method overrides, determining which, if any, methods on a
26  * managed object the Spring IoC container will override at runtime.
27  *
28  * <p>The currently supported MethodOverride variants are
29  * LookupOverride and ReplaceOverride.
30  *
31  * @author Rod Johnson
32  * @since 1.1
33  * @see MethodOverride
34  * @see LookupOverride
35  * @see ReplaceOverride
36  */

37 public class MethodOverrides {
38
39     private final Set JavaDoc overrides = new HashSet JavaDoc();
40
41
42     /**
43      * Create new MethodOverrides.
44      */

45     public MethodOverrides() {
46     }
47
48     /**
49      * Deep copy constructor.
50      */

51     public MethodOverrides(MethodOverrides other) {
52         addOverrides(other);
53     }
54
55
56     /**
57      * Copy all given method overrides into this object.
58      */

59     public void addOverrides(MethodOverrides other) {
60         if (other != null) {
61             this.overrides.addAll(other.getOverrides());
62         }
63     }
64
65     /**
66      * Add the given method override.
67      */

68     public void addOverride(MethodOverride override) {
69         this.overrides.add(override);
70     }
71
72     /**
73      * Return all method overrides contained by this object.
74      * @return Set of MethodOverride objects
75      * @see MethodOverride
76      */

77     public Set JavaDoc getOverrides() {
78         return overrides;
79     }
80
81     /**
82      * Return whether the set of method overrides is empty.
83      */

84     public boolean isEmpty() {
85         return this.overrides.isEmpty();
86     }
87     
88     /**
89      * Return the override for the given method, if any.
90      * @param method method to check for overrides for
91      * @return the method override, or <code>null</code> if none
92      */

93     public MethodOverride getOverride(Method JavaDoc method) {
94         for (Iterator JavaDoc it = this.overrides.iterator(); it.hasNext();) {
95             MethodOverride methodOverride = (MethodOverride) it.next();
96             if (methodOverride.matches(method)) {
97                 return methodOverride;
98             }
99         }
100         return null;
101     }
102
103     public boolean equals(Object JavaDoc o) {
104         if (this == o) return true;
105         if (o == null || getClass() != o.getClass()) return false;
106
107         MethodOverrides that = (MethodOverrides) o;
108
109         if (!this.overrides.equals(that.overrides)) return false;
110
111         return true;
112     }
113
114     public int hashCode() {
115         return this.overrides.hashCode();
116     }
117 }
118
Popular Tags