1. /*
  2. * @(#)FeatureDescriptor.java 1.24 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. /**
  12. * The FeatureDescriptor class is the common baseclass for PropertyDescriptor,
  13. * EventSetDescriptor, and MethodDescriptor, etc.
  14. * <p>
  15. * It supports some common information that can be set and retrieved for
  16. * any of the introspection descriptors.
  17. * <p>
  18. * In addition it provides an extension mechanism so that arbitrary
  19. * attribute/value pairs can be associated with a design feature.
  20. */
  21. public class FeatureDescriptor {
  22. /**
  23. * Constructs a <code>FeatureDescriptor</code>.
  24. */
  25. public FeatureDescriptor() {
  26. }
  27. /**
  28. * Gets the programmatic name of this feature.
  29. *
  30. * @return The programmatic name of the property/method/event
  31. */
  32. public String getName() {
  33. return name;
  34. }
  35. /**
  36. * Sets the programmatic name of this feature.
  37. *
  38. * @param name The programmatic name of the property/method/event
  39. */
  40. public void setName(String name) {
  41. this.name = name;
  42. }
  43. /**
  44. * Gets the localized display name of this feature.
  45. *
  46. * @return The localized display name for the property/method/event.
  47. * This defaults to the same as its programmatic name from getName.
  48. */
  49. public String getDisplayName() {
  50. if (displayName == null) {
  51. return getName();
  52. }
  53. return displayName;
  54. }
  55. /**
  56. * Sets the localized display name of this feature.
  57. *
  58. * @param displayName The localized display name for the
  59. * property/method/event.
  60. */
  61. public void setDisplayName(String displayName) {
  62. this.displayName = displayName;
  63. }
  64. /**
  65. * The "expert" flag is used to distinguish between those features that are
  66. * intended for expert users from those that are intended for normal users.
  67. *
  68. * @return True if this feature is intended for use by experts only.
  69. */
  70. public boolean isExpert() {
  71. return expert;
  72. }
  73. /**
  74. * The "expert" flag is used to distinguish between features that are
  75. * intended for expert users from those that are intended for normal users.
  76. *
  77. * @param expert True if this feature is intended for use by experts only.
  78. */
  79. public void setExpert(boolean expert) {
  80. this.expert = expert;
  81. }
  82. /**
  83. * The "hidden" flag is used to identify features that are intended only
  84. * for tool use, and which should not be exposed to humans.
  85. *
  86. * @return True if this feature should be hidden from human users.
  87. */
  88. public boolean isHidden() {
  89. return hidden;
  90. }
  91. /**
  92. * The "hidden" flag is used to identify features that are intended only
  93. * for tool use, and which should not be exposed to humans.
  94. *
  95. * @param hidden True if this feature should be hidden from human users.
  96. */
  97. public void setHidden(boolean hidden) {
  98. this.hidden = hidden;
  99. }
  100. /**
  101. * The "preferred" flag is used to identify features that are particularly
  102. * important for presenting to humans.
  103. *
  104. * @return True if this feature should be preferentially shown to human users.
  105. */
  106. public boolean isPreferred() {
  107. return preferred;
  108. }
  109. /**
  110. * The "preferred" flag is used to identify features that are particularly
  111. * important for presenting to humans.
  112. *
  113. * @param preferred True if this feature should be preferentially shown
  114. * to human users.
  115. */
  116. public void setPreferred(boolean preferred) {
  117. this.preferred = preferred;
  118. }
  119. /**
  120. * Gets the short description of this feature.
  121. *
  122. * @return A localized short description associated with this
  123. * property/method/event. This defaults to be the display name.
  124. */
  125. public String getShortDescription() {
  126. if (shortDescription == null) {
  127. return getDisplayName();
  128. }
  129. return shortDescription;
  130. }
  131. /**
  132. * You can associate a short descriptive string with a feature. Normally
  133. * these descriptive strings should be less than about 40 characters.
  134. * @param text A (localized) short description to be associated with
  135. * this property/method/event.
  136. */
  137. public void setShortDescription(String text) {
  138. shortDescription = text;
  139. }
  140. /**
  141. * Associate a named attribute with this feature.
  142. *
  143. * @param attributeName The locale-independent name of the attribute
  144. * @param value The value.
  145. */
  146. public void setValue(String attributeName, Object value) {
  147. if (table == null) {
  148. table = new java.util.Hashtable();
  149. }
  150. table.put(attributeName, value);
  151. }
  152. /**
  153. * Retrieve a named attribute with this feature.
  154. *
  155. * @param attributeName The locale-independent name of the attribute
  156. * @return The value of the attribute. May be null if
  157. * the attribute is unknown.
  158. */
  159. public Object getValue(String attributeName) {
  160. if (table == null) {
  161. return null;
  162. }
  163. return table.get(attributeName);
  164. }
  165. /**
  166. * Gets an enumeration of the locale-independent names of this
  167. * feature.
  168. *
  169. * @return An enumeration of the locale-independent names of any
  170. * attributes that have been registered with setValue.
  171. */
  172. public java.util.Enumeration attributeNames() {
  173. if (table == null) {
  174. table = new java.util.Hashtable();
  175. }
  176. return table.keys();
  177. }
  178. /**
  179. * Package-private constructor,
  180. * Merge information from two FeatureDescriptors.
  181. * The merged hidden and expert flags are formed by or-ing the values.
  182. * In the event of other conflicts, the second argument (y) is
  183. * given priority over the first argument (x).
  184. *
  185. * @param x The first (lower priority) MethodDescriptor
  186. * @param y The second (higher priority) MethodDescriptor
  187. */
  188. FeatureDescriptor(FeatureDescriptor x, FeatureDescriptor y) {
  189. expert = x.expert | y.expert;
  190. hidden = x.hidden | y.hidden;
  191. name = y.name;
  192. shortDescription = x.shortDescription;
  193. if (y.shortDescription != null) {
  194. shortDescription = y.shortDescription;
  195. }
  196. displayName = x.displayName;
  197. if (y.displayName != null) {
  198. displayName = y.displayName;
  199. }
  200. addTable(x.table);
  201. addTable(y.table);
  202. }
  203. /*
  204. * Package-private dup constructor
  205. * This must isolate the new object from any changes to the old object.
  206. */
  207. FeatureDescriptor(FeatureDescriptor old) {
  208. expert = old.expert;
  209. hidden = old.hidden;
  210. name = old.name;
  211. shortDescription = old.shortDescription;
  212. displayName = old.displayName;
  213. addTable(old.table);
  214. }
  215. private void addTable(java.util.Hashtable t) {
  216. if (t == null) {
  217. return;
  218. }
  219. java.util.Enumeration keys = t.keys();
  220. while (keys.hasMoreElements()) {
  221. String key = (String)keys.nextElement();
  222. Object value = t.get(key);
  223. setValue(key, value);
  224. }
  225. }
  226. private boolean expert;
  227. private boolean hidden;
  228. private boolean preferred;
  229. private String shortDescription;
  230. private String name;
  231. private String displayName;
  232. private java.util.Hashtable table;
  233. }