001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
013: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
014: * License for the specific language governing permissions and limitations under
015: * the License.
016: */
017:
018: package java.beans;
019:
020: import java.lang.reflect.Method;
021:
022: /**
023: * Describes a bean's method.
024: */
025: public class MethodDescriptor extends FeatureDescriptor {
026:
027: private Method method;
028:
029: private ParameterDescriptor[] parameterDescriptors;
030:
031: /**
032: * <p>
033: * Constructs an instance with the given {@link Method} and
034: * {@link ParameterDescriptor}s. The {@link #getName()} is set as the name
035: * of the <code>method</code> passed.
036: * </p>
037: *
038: * @param method
039: * The Method to set.
040: * @param parameterDescriptors
041: * An array of parameter descriptors.
042: */
043: public MethodDescriptor(Method method,
044: ParameterDescriptor[] parameterDescriptors) {
045: super ();
046:
047: if (method == null) {
048: throw new NullPointerException();
049: }
050: this .method = method;
051: this .parameterDescriptors = parameterDescriptors;
052:
053: setName(method.getName());
054: }
055:
056: /**
057: * <p>
058: * Constructs an instance with the given {@link Method}. The
059: * {@link #getName()} is set as the name of the <code>method</code>
060: * passed.
061: * </p>
062: *
063: * @param method
064: * The Method to set.
065: */
066: public MethodDescriptor(Method method) {
067: super ();
068:
069: if (method == null) {
070: throw new NullPointerException();
071: }
072: this .method = method;
073:
074: setName(method.getName());
075: }
076:
077: /**
078: * <p>
079: * Gets the method.
080: * </p>
081: *
082: * @return A {@link Method} instance.
083: */
084: public Method getMethod() {
085: return method;
086: }
087:
088: /**
089: * <p>
090: * Gets the parameter descriptors.
091: * </p>
092: *
093: * @return An array of {@link ParameterDescriptor} instance or
094: * <code>null</code>.
095: */
096: public ParameterDescriptor[] getParameterDescriptors() {
097: return parameterDescriptors;
098: }
099:
100: void merge(MethodDescriptor anotherMethod) {
101: super.merge(anotherMethod);
102: if (method == null) {
103: method = anotherMethod.method;
104: }
105: if (parameterDescriptors == null) {
106: parameterDescriptors = anotherMethod.parameterDescriptors;
107: }
108: }
109: }
|