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: import java.util.HashSet;
021: import java.util.Iterator;
022: import java.util.Set;
023:
024: /**
025: * Set of method overrides, determining which, if any, methods on a
026: * managed object the Spring IoC container will override at runtime.
027: *
028: * <p>The currently supported {@link MethodOverride} variants are
029: * {@link LookupOverride} and {@link ReplaceOverride}.
030: *
031: * @author Rod Johnson
032: * @author Juergen Hoeller
033: * @since 1.1
034: * @see MethodOverride
035: */
036: public class MethodOverrides {
037:
038: private final Set overrides = new HashSet();
039:
040: /**
041: * Create new MethodOverrides.
042: */
043: public MethodOverrides() {
044: }
045:
046: /**
047: * Deep copy constructor.
048: */
049: public MethodOverrides(MethodOverrides other) {
050: addOverrides(other);
051: }
052:
053: /**
054: * Copy all given method overrides into this object.
055: */
056: public void addOverrides(MethodOverrides other) {
057: if (other != null) {
058: this .overrides.addAll(other.getOverrides());
059: }
060: }
061:
062: /**
063: * Add the given method override.
064: */
065: public void addOverride(MethodOverride override) {
066: this .overrides.add(override);
067: }
068:
069: /**
070: * Return all method overrides contained by this object.
071: * @return Set of MethodOverride objects
072: * @see MethodOverride
073: */
074: public Set getOverrides() {
075: return this .overrides;
076: }
077:
078: /**
079: * Return whether the set of method overrides is empty.
080: */
081: public boolean isEmpty() {
082: return this .overrides.isEmpty();
083: }
084:
085: /**
086: * Return the override for the given method, if any.
087: * @param method method to check for overrides for
088: * @return the method override, or <code>null</code> if none
089: */
090: public MethodOverride getOverride(Method method) {
091: for (Iterator it = this .overrides.iterator(); it.hasNext();) {
092: MethodOverride methodOverride = (MethodOverride) it.next();
093: if (methodOverride.matches(method)) {
094: return methodOverride;
095: }
096: }
097: return null;
098: }
099:
100: public boolean equals(Object o) {
101: if (this == o)
102: return true;
103: if (o == null || getClass() != o.getClass())
104: return false;
105:
106: MethodOverrides that = (MethodOverrides) o;
107:
108: if (!this .overrides.equals(that.overrides))
109: return false;
110:
111: return true;
112: }
113:
114: public int hashCode() {
115: return this.overrides.hashCode();
116: }
117:
118: }
|