KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > binding > method > MethodSignature


1 /*
2  * Copyright 2002-2006 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 package org.springframework.binding.method;
17
18 import java.io.Serializable JavaDoc;
19
20 import org.springframework.core.style.ToStringCreator;
21 import org.springframework.util.Assert;
22
23 /**
24  * A specification for a <code>Method</code> consisting of the methodName
25  * and an optional set of named arguments.
26  *
27  * @author Keith Donald
28  */

29 public class MethodSignature implements Serializable JavaDoc {
30
31     /**
32      * The name of the method, e.g execute
33      */

34     private String JavaDoc methodName;
35
36     /**
37      * The parameter types of the method, e.g int param1
38      */

39     private Parameters parameters;
40
41     /**
42      * Creates a method key with no parameters
43      * @param methodName the name of the method.
44      */

45     public MethodSignature(String JavaDoc methodName) {
46         this(methodName, Parameters.NONE);
47     }
48
49     /**
50      * Creates a method key with a single parameter.
51      * @param methodName the name of the method
52      * @param parameter the method parameter
53      */

54     public MethodSignature(String JavaDoc methodName, Parameter parameter) {
55         this(methodName, new Parameters(parameter));
56     }
57
58     /**
59      * Creates a method key with a list of parameters.
60      * @param methodName the name of the method
61      * @param parameters the method parameters
62      */

63     public MethodSignature(String JavaDoc methodName, Parameters parameters) {
64         Assert.notNull(methodName, "The method name is required");
65         Assert.notNull(parameters, "The parameters are required");
66         this.methodName = methodName;
67         this.parameters = parameters;
68     }
69
70     public Parameters getParameters() {
71         return parameters;
72     }
73
74     public String JavaDoc getMethodName() {
75         return methodName;
76     }
77
78     public boolean equals(Object JavaDoc obj) {
79         if (!(obj instanceof MethodSignature)) {
80             return false;
81         }
82         MethodSignature other = (MethodSignature)obj;
83         return methodName.equals(methodName) && parameters.equals(other.parameters);
84     }
85
86     public int hashCode() {
87         return methodName.hashCode() + parameters.hashCode();
88     }
89
90     public String JavaDoc toString() {
91         return new ToStringCreator(this).append("methodName", methodName).append("parameters", parameters).toString();
92     }
93 }
Popular Tags