1 Properties

1.3 Obtaining Property Information

Additional information about a property is available through the PropertyInfo interface, which can be obtained using the getInfo() method of the property handle. Information supplied by PropertyInfo is static with respect to the exporting class and does not change (unlike the property values themselves, which do change). Such information includes the property’s name, whether or not it is read-only, and a comment describing what the property does.

Some of the PropertyInfo methods include:

interface PropertyInfo
{
   // gets the name of this property
   String getName();
   // returns true if this property cannot be set
   boolean isReadonly();
   // returns a string description of the property
   String getDescription();
   // returns an optional format string describing how the
   // property’s values should be formatted when printed.
   String getPrintFormat();
   // returns the class associated with this property’s value.
   Class getValueClass();
   // returns the class associated with this property’s host
   Class getHostClass();
   // returns true if the properties value should be written
   // by the PropertyList write method.
   boolean getAutoWrite();
   // returns the conditions under which this property
   // should be interactively edited.
   Edit getEditing();
   // Returns information about whether the property’s editing widget
   // should be able to expand or contract in order to save GUI space.
   ExpandState getWidgetExpandState();
   // Indicates if a slider is allowed in this property’s editing
   // widget
   boolean isSliderAllowed();
   // returns the default value for this property
   Object getDefaultValue();
   // returns a default numeric range for this property, if any
   public NumericInterval getDefaultNumericRange();
   // writes a value of this object out to a PrintStream
   void writeValue (
       Object value, PrintWriter pw, NumberFormat fmt);
   // scans a value of this object from a ReaderTokenizer
   Object scanValue (ReaderTokenizer rtok);
   // creates a Property for this property, attached
   // to the specified host object
   Property createHandle (HasProperties host);
   // returns true if a specified value equals this
   // property’s default value
   boolean valueEqualsDefault();
   // returns true if the property is inheritable
   boolean isInheritable();
   // returns the property’s numeric dimension, or -1 if it
   // is not numeric or does not have a fixed dimension
   int getDimension();
   // indicates that the property value can be shared among
   // several hosts.
   boolean isSharable();
}

Property information can also be obtained directly from the exporting class, using getAllPropertyInfo(), which returns information for all the properties exported by that class. This information is contained within a PropertyInfoList:

interface PropertyInfoList
{
   // number of properties in this list
   int size();
   // returns an iterator over all the property infos
   Iterator<PropertyInfo> iterator();
   // returns info for a specific named property
   PropertyInfo get (String name);
   // returns true if this list has no inheritable properties
   boolean hasNoInheritableProperties();
}

For example, suppose we want to print the names of all the properties associated with a given class. This could be done as follows:

   HasProperties exportingObject;
   ...
   PropertyInfoList infoList =
       exportingObject.getAllPropertyInfo();
   for (PropertyInfo info : infoList) {
      System.out.println (info.getName());
   }