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