KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.Assert;
22 import org.springframework.util.ObjectUtils;
23
24 /**
25  * Represents an override of a method that looks up an object in the same IoC context.
26  *
27  * <p>Methods eligible for lookup override must not have arguments.
28  *
29  * @author Rod Johnson
30  * @author Juergen Hoeller
31  * @since 1.1
32  */

33 public class LookupOverride extends MethodOverride {
34     
35     private final String JavaDoc beanName;
36
37
38     /**
39      * Construct a new LookupOverride.
40      * @param methodName the name of the method to override.
41      * This method must have no arguments.
42      * @param beanName name of the bean in the current BeanFactory
43      * that the overriden method should return
44      */

45     public LookupOverride(String JavaDoc methodName, String JavaDoc beanName) {
46         super(methodName);
47         Assert.notNull(beanName, "Bean name must not be null");
48         this.beanName = beanName;
49     }
50
51     /**
52      * Return the name of the bean that should be returned by this method.
53      */

54     public String JavaDoc getBeanName() {
55         return this.beanName;
56     }
57
58
59     /**
60      * Match method of the given name, with no parameters.
61      */

62     public boolean matches(Method JavaDoc method) {
63         return (method.getName().equals(getMethodName()) && method.getParameterTypes().length == 0);
64     }
65
66
67     public String JavaDoc toString() {
68         return "LookupOverride for method '" + getMethodName() + "'; will return bean '" + this.beanName + "'";
69     }
70
71     public boolean equals(Object JavaDoc other) {
72         return (other instanceof LookupOverride && super.equals(other) &&
73                 ObjectUtils.nullSafeEquals(this.beanName, ((LookupOverride) other).beanName));
74     }
75
76     public int hashCode() {
77         return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.beanName));
78     }
79
80 }
81
Popular Tags