KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2002-2007 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
21 import org.springframework.beans.BeanMetadataElement;
22 import org.springframework.util.Assert;
23 import org.springframework.util.ObjectUtils;
24
25 /**
26  * Object representing the override of a method on a managed
27  * object by the IoC container.
28  *
29  * <p>Note that the override mechanism is <i>not</i> intended as a
30  * generic means of inserting crosscutting code: use AOP for that.
31  *
32  * @author Rod Johnson
33  * @author Juergen Hoeller
34  * @since 1.1
35  */

36 public abstract class MethodOverride implements BeanMetadataElement {
37     
38     private final String JavaDoc methodName;
39
40     private boolean overloaded = true;
41
42     private Object JavaDoc source;
43
44
45     /**
46      * Construct a new override for the given method.
47      * @param methodName the name of the method to override
48      */

49     protected MethodOverride(String JavaDoc methodName) {
50         Assert.notNull(methodName, "Method name must not be null");
51         this.methodName = methodName;
52     }
53
54     /**
55      * Return the name of the method to be overridden.
56      */

57     public String JavaDoc getMethodName() {
58         return this.methodName;
59     }
60
61     /**
62      * Set whether the overridden method has to be considered as overloaded
63      * (that is, whether arg type matching has to happen).
64      * <p>Default is "true"; can be switched to "false" to optimize runtime performance.
65      */

66     protected void setOverloaded(boolean overloaded) {
67         this.overloaded = overloaded;
68     }
69
70     /**
71      * Return whether the overridden method has to be considered as overloaded
72      * (that is, whether arg type matching has to happen).
73      */

74     protected boolean isOverloaded() {
75         return this.overloaded;
76     }
77
78     /**
79      * Set the configuration source <code>Object</code> for this metadata element.
80      * <p>The exact type of the object will depend on the configuration mechanism used.
81      */

82     public void setSource(Object JavaDoc source) {
83         this.source = source;
84     }
85
86     public Object JavaDoc getSource() {
87         return this.source;
88     }
89
90
91     /**
92      * Subclasses must override this to indicate whether they match
93      * the given method. This allows for argument list checking
94      * as well as method name checking.
95      * @param method the method to check
96      * @return whether this override matches the given method
97      */

98     public abstract boolean matches(Method JavaDoc method);
99
100
101     public boolean equals(Object JavaDoc other) {
102         if (this == other) {
103             return true;
104         }
105         if (!(other instanceof MethodOverride)) {
106             return false;
107         }
108         MethodOverride that = (MethodOverride) other;
109         return (ObjectUtils.nullSafeEquals(this.methodName, that.methodName) &&
110                 this.overloaded == that.overloaded &&
111                 ObjectUtils.nullSafeEquals(this.source, that.source));
112     }
113
114     public int hashCode() {
115         int hashCode = ObjectUtils.nullSafeHashCode(this.methodName);
116         hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.source);
117         hashCode = 29 * hashCode + (this.overloaded ? 1 : 0);
118         return hashCode;
119     }
120
121 }
122
Popular Tags