1. /*
  2. * @(#)SimpleBeanInfo.java 1.27 03/12/19
  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. /**
  9. * This is a support class to make it easier for people to provide
  10. * BeanInfo classes.
  11. * <p>
  12. * It defaults to providing "noop" information, and can be selectively
  13. * overriden to provide more explicit information on chosen topics.
  14. * When the introspector sees the "noop" values, it will apply low
  15. * level introspection and design patterns to automatically analyze
  16. * the target bean.
  17. */
  18. public class SimpleBeanInfo implements BeanInfo {
  19. /**
  20. * Deny knowledge about the class and customizer of the bean.
  21. * You can override this if you wish to provide explicit info.
  22. */
  23. public BeanDescriptor getBeanDescriptor() {
  24. return null;
  25. }
  26. /**
  27. * Deny knowledge of properties. You can override this
  28. * if you wish to provide explicit property info.
  29. */
  30. public PropertyDescriptor[] getPropertyDescriptors() {
  31. return null;
  32. }
  33. /**
  34. * Deny knowledge of a default property. You can override this
  35. * if you wish to define a default property for the bean.
  36. */
  37. public int getDefaultPropertyIndex() {
  38. return -1;
  39. }
  40. /**
  41. * Deny knowledge of event sets. You can override this
  42. * if you wish to provide explicit event set info.
  43. */
  44. public EventSetDescriptor[] getEventSetDescriptors() {
  45. return null;
  46. }
  47. /**
  48. * Deny knowledge of a default event. You can override this
  49. * if you wish to define a default event for the bean.
  50. */
  51. public int getDefaultEventIndex() {
  52. return -1;
  53. }
  54. /**
  55. * Deny knowledge of methods. You can override this
  56. * if you wish to provide explicit method info.
  57. */
  58. public MethodDescriptor[] getMethodDescriptors() {
  59. return null;
  60. }
  61. /**
  62. * Claim there are no other relevant BeanInfo objects. You
  63. * may override this if you want to (for example) return a
  64. * BeanInfo for a base class.
  65. */
  66. public BeanInfo[] getAdditionalBeanInfo() {
  67. return null;
  68. }
  69. /**
  70. * Claim there are no icons available. You can override
  71. * this if you want to provide icons for your bean.
  72. */
  73. public java.awt.Image getIcon(int iconKind) {
  74. return null;
  75. }
  76. /**
  77. * This is a utility method to help in loading icon images.
  78. * It takes the name of a resource file associated with the
  79. * current object's class file and loads an image object
  80. * from that file. Typically images will be GIFs.
  81. * <p>
  82. * @param resourceName A pathname relative to the directory
  83. * holding the class file of the current class. For example,
  84. * "wombat.gif".
  85. * @return an image object. May be null if the load failed.
  86. */
  87. public java.awt.Image loadImage(final String resourceName) {
  88. try {
  89. final Class c = getClass();
  90. java.awt.image.ImageProducer ip = (java.awt.image.ImageProducer)
  91. java.security.AccessController.doPrivileged(
  92. new java.security.PrivilegedAction() {
  93. public Object run() {
  94. java.net.URL url;
  95. if ((url = c.getResource(resourceName)) == null) {
  96. return null;
  97. } else {
  98. try {
  99. return url.getContent();
  100. } catch (java.io.IOException ioe) {
  101. return null;
  102. }
  103. }
  104. }
  105. });
  106. if (ip == null)
  107. return null;
  108. java.awt.Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
  109. return tk.createImage(ip);
  110. } catch (Exception ex) {
  111. return null;
  112. }
  113. }
  114. }