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