1. /*
  2. * @(#)MethodDescriptor.java 1.22 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.beans;
  8. import java.lang.reflect.*;
  9. /**
  10. * A MethodDescriptor describes a particular method that a Java Bean
  11. * supports for external access from other components.
  12. */
  13. public class MethodDescriptor extends FeatureDescriptor {
  14. /**
  15. * Constructs a <code>MethodDescriptor</code> from a
  16. * <code>Method</code>.
  17. *
  18. * @param method The low-level method information.
  19. */
  20. public MethodDescriptor(Method method) {
  21. this.method = method;
  22. setName(method.getName());
  23. }
  24. /**
  25. * Constructs a <code>MethodDescriptor</code> from a
  26. * <code>Method</code> providing descriptive information for each
  27. * of the method's parameters.
  28. *
  29. * @param method The low-level method information.
  30. * @param parameterDescriptors Descriptive information for each of the
  31. * method's parameters.
  32. */
  33. public MethodDescriptor(Method method,
  34. ParameterDescriptor parameterDescriptors[]) {
  35. this.method = method;
  36. this.parameterDescriptors = parameterDescriptors;
  37. setName(method.getName());
  38. }
  39. /**
  40. * Gets the method that this MethodDescriptor encapsualtes.
  41. *
  42. * @return The low-level description of the method
  43. */
  44. public Method getMethod() {
  45. return method;
  46. }
  47. /**
  48. * Gets the ParameterDescriptor for each of this MethodDescriptor's
  49. * method's parameters.
  50. *
  51. * @return The locale-independent names of the parameters. May return
  52. * a null array if the parameter names aren't known.
  53. */
  54. public ParameterDescriptor[] getParameterDescriptors() {
  55. return parameterDescriptors;
  56. }
  57. /*
  58. * Package-private constructor
  59. * Merge two method descriptors. Where they conflict, give the
  60. * second argument (y) priority over the first argument (x).
  61. * @param x The first (lower priority) MethodDescriptor
  62. * @param y The second (higher priority) MethodDescriptor
  63. */
  64. MethodDescriptor(MethodDescriptor x, MethodDescriptor y) {
  65. super(x,y);
  66. method = x.method;
  67. parameterDescriptors = x.parameterDescriptors;
  68. if (y.parameterDescriptors != null) {
  69. parameterDescriptors = y.parameterDescriptors;
  70. }
  71. }
  72. /*
  73. * Package-private dup constructor
  74. * This must isolate the new object from any changes to the old object.
  75. */
  76. MethodDescriptor(MethodDescriptor old) {
  77. super(old);
  78. method = old.method;
  79. if (old.parameterDescriptors != null) {
  80. int len = old.parameterDescriptors.length;
  81. parameterDescriptors = new ParameterDescriptor[len];
  82. for (int i = 0; i < len ; i++) {
  83. parameterDescriptors[i] = new ParameterDescriptor(old.parameterDescriptors[i]);
  84. }
  85. }
  86. }
  87. private Method method;
  88. private ParameterDescriptor parameterDescriptors[];
  89. }