001: /*
002: * Copyright 2004-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: package org.springframework.binding.method;
017:
018: import org.springframework.core.style.ToStringCreator;
019: import org.springframework.util.Assert;
020:
021: /**
022: * A specification for a method consisting of the methodName and an optional set
023: * of named arguments. This class provides the ability to resolve a method with
024: * parameters and evaluate its argument values as part of a
025: * {@link MethodInvoker method invoker attempt}.
026: *
027: * @author Keith Donald
028: */
029: public class MethodSignature {
030:
031: /**
032: * The name of the method, e.g "execute".
033: */
034: private String methodName;
035:
036: /**
037: * The parameter types of the method, e.g "int param1".
038: */
039: private Parameters parameters;
040:
041: /**
042: * Creates a method signature with no parameters.
043: * @param methodName the name of the method
044: */
045: public MethodSignature(String methodName) {
046: this (methodName, Parameters.NONE);
047: }
048:
049: /**
050: * Creates a method signature with a single parameter.
051: * @param methodName the name of the method
052: * @param parameter the method parameter
053: */
054: public MethodSignature(String methodName, Parameter parameter) {
055: this (methodName, new Parameters(parameter));
056: }
057:
058: /**
059: * Creates a method signature with a list of parameters.
060: * @param methodName the name of the method
061: * @param parameters the method parameters
062: */
063: public MethodSignature(String methodName, Parameters parameters) {
064: Assert.notNull(methodName, "The method name is required");
065: Assert.notNull(parameters, "The parameters are required");
066: this .methodName = methodName;
067: this .parameters = parameters;
068: }
069:
070: /**
071: * Returns the method name.
072: */
073: public String getMethodName() {
074: return methodName;
075: }
076:
077: /**
078: * Returns the method parameters.
079: */
080: public Parameters getParameters() {
081: return parameters;
082: }
083:
084: public boolean equals(Object obj) {
085: if (!(obj instanceof MethodSignature)) {
086: return false;
087: }
088: MethodSignature other = (MethodSignature) obj;
089: return methodName.equals(other.methodName)
090: && parameters.equals(other.parameters);
091: }
092:
093: public int hashCode() {
094: return methodName.hashCode() + parameters.hashCode();
095: }
096:
097: public String toString() {
098: return new ToStringCreator(this ).append("methodName",
099: methodName).append("parameters", parameters).toString();
100: }
101: }
|