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