001: /*
002: * Copyright 2002-2007 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.beans.factory.support;
018:
019: import java.lang.reflect.Method;
020:
021: import org.springframework.beans.BeanMetadataElement;
022: import org.springframework.util.Assert;
023: import org.springframework.util.ObjectUtils;
024:
025: /**
026: * Object representing the override of a method on a managed
027: * object by the IoC container.
028: *
029: * <p>Note that the override mechanism is <i>not</i> intended as a
030: * generic means of inserting crosscutting code: use AOP for that.
031: *
032: * @author Rod Johnson
033: * @author Juergen Hoeller
034: * @since 1.1
035: */
036: public abstract class MethodOverride implements BeanMetadataElement {
037:
038: private final String methodName;
039:
040: private boolean overloaded = true;
041:
042: private Object source;
043:
044: /**
045: * Construct a new override for the given method.
046: * @param methodName the name of the method to override
047: */
048: protected MethodOverride(String methodName) {
049: Assert.notNull(methodName, "Method name must not be null");
050: this .methodName = methodName;
051: }
052:
053: /**
054: * Return the name of the method to be overridden.
055: */
056: public String getMethodName() {
057: return this .methodName;
058: }
059:
060: /**
061: * Set whether the overridden method has to be considered as overloaded
062: * (that is, whether arg type matching has to happen).
063: * <p>Default is "true"; can be switched to "false" to optimize runtime performance.
064: */
065: protected void setOverloaded(boolean overloaded) {
066: this .overloaded = overloaded;
067: }
068:
069: /**
070: * Return whether the overridden method has to be considered as overloaded
071: * (that is, whether arg type matching has to happen).
072: */
073: protected boolean isOverloaded() {
074: return this .overloaded;
075: }
076:
077: /**
078: * Set the configuration source <code>Object</code> for this metadata element.
079: * <p>The exact type of the object will depend on the configuration mechanism used.
080: */
081: public void setSource(Object source) {
082: this .source = source;
083: }
084:
085: public Object getSource() {
086: return this .source;
087: }
088:
089: /**
090: * Subclasses must override this to indicate whether they match
091: * the given method. This allows for argument list checking
092: * as well as method name checking.
093: * @param method the method to check
094: * @return whether this override matches the given method
095: */
096: public abstract boolean matches(Method method);
097:
098: public boolean equals(Object other) {
099: if (this == other) {
100: return true;
101: }
102: if (!(other instanceof MethodOverride)) {
103: return false;
104: }
105: MethodOverride that = (MethodOverride) other;
106: return (ObjectUtils.nullSafeEquals(this .methodName,
107: that.methodName)
108: && this .overloaded == that.overloaded && ObjectUtils
109: .nullSafeEquals(this .source, that.source));
110: }
111:
112: public int hashCode() {
113: int hashCode = ObjectUtils.nullSafeHashCode(this .methodName);
114: hashCode = 29 * hashCode
115: + ObjectUtils.nullSafeHashCode(this .source);
116: hashCode = 29 * hashCode + (this .overloaded ? 1 : 0);
117: return hashCode;
118: }
119:
120: }
|