1. /*
  2. * @(#)BeanDescriptor.java 1.23 04/05/05
  3. *
  4. * Copyright 2004 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.ref.Reference;
  9. /**
  10. * A BeanDescriptor provides global information about a "bean",
  11. * including its Java class, its displayName, etc.
  12. * <p>
  13. * This is one of the kinds of descriptor returned by a BeanInfo object,
  14. * which also returns descriptors for properties, method, and events.
  15. */
  16. public class BeanDescriptor extends FeatureDescriptor {
  17. private Reference beanClassRef;
  18. private Reference customizerClassRef;
  19. /**
  20. * Create a BeanDescriptor for a bean that doesn't have a customizer.
  21. *
  22. * @param beanClass The Class object of the Java class that implements
  23. * the bean. For example sun.beans.OurButton.class.
  24. */
  25. public BeanDescriptor(Class<?> beanClass) {
  26. this(beanClass, null);
  27. }
  28. /**
  29. * Create a BeanDescriptor for a bean that has a customizer.
  30. *
  31. * @param beanClass The Class object of the Java class that implements
  32. * the bean. For example sun.beans.OurButton.class.
  33. * @param customizerClass The Class object of the Java class that implements
  34. * the bean's Customizer. For example sun.beans.OurButtonCustomizer.class.
  35. */
  36. public BeanDescriptor(Class<?> beanClass, Class<?> customizerClass) {
  37. beanClassRef = createReference(beanClass);
  38. customizerClassRef = createReference(customizerClass);
  39. String name = beanClass.getName();
  40. while (name.indexOf('.') >= 0) {
  41. name = name.substring(name.indexOf('.')+1);
  42. }
  43. setName(name);
  44. }
  45. /**
  46. * Gets the bean's Class object.
  47. *
  48. * @return The Class object for the bean.
  49. */
  50. public Class<?> getBeanClass() {
  51. return (Class)getObject(beanClassRef);
  52. }
  53. /**
  54. * Gets the Class object for the bean's customizer.
  55. *
  56. * @return The Class object for the bean's customizer. This may
  57. * be null if the bean doesn't have a customizer.
  58. */
  59. public Class<?> getCustomizerClass() {
  60. return (Class)getObject(customizerClassRef);
  61. }
  62. /*
  63. * Package-private dup constructor
  64. * This must isolate the new object from any changes to the old object.
  65. */
  66. BeanDescriptor(BeanDescriptor old) {
  67. super(old);
  68. beanClassRef = old.beanClassRef;
  69. customizerClassRef = old.customizerClassRef;
  70. }
  71. }