Creating Bean Information

The bean info file contains information about the properties and methods supported by the bean.  There are several bean attributes used by the Able Agent Editor to position the beans on the icon palette ("able-category") and on the canvas ("able-slot").  The bean info file specifies the name of the bean class itself, the customizer class, and the icon (*.gif) files. The bean info file extends the java.beans.SimpleBeanInfo class, and overrides the getBeanDescriptor, getIcon, and getAdditionalBeanInfo methods.

The customary name of a bean info file is the term BeanInfo suffixed to the bean class name.

The bean info files provided with the simple and more complex examples are:

Member variables

Beans provided with Able typically define member variables for convenience to specify the bean class name, the customizer class name, and the names of the icons in various colors and dimensions. Here is an example from SimpleAbleBeanBeanInfo:

private final static Class customizerClass = com.ibm.able.examples.ablebean.SimpleAbleBeanCustomizer.class;
Class beanClass = SimpleAbleBean.class;
String iconColor16x16Filename = "simplebean16.gif";
String iconColor32x32Filename = "simplebean32.gif";

Note that customarily image files are placed in a resources or image directory, and if so, would be specified as:

String iconColor16x16Filename = "resources/simplebean16.gif";

Methods

Here are examples of the methods overridden from SimpleAbleBeanBeanInfo:

getBeanDescriptor()

This method provides the able-category, which is the name of the tab or palette to place the icon representing this object, and the able-slot, which is the horizontal column to used to position a new bean on the Agent Editor canvas.

public BeanDescriptor getBeanDescriptor() { 
  BeanDescriptor returnDescriptor = new BeanDescriptor(beanClass, customizerClass);
  returnDescriptor.setValue("hidden-state", Boolean.TRUE);
  // icon palette page
  returnDescriptor.setValue("able-category",Able.CAT_SAMPLES); // horizontal position on canvas
  returnDescriptor.setValue("able-slot", "2"); 
  return returnDescriptor;
}

If our bean were an agent that is intended to contain other beans, an additional descriptor value is used to determine whether the agent is to be listed in the File->New agent menu. Here is the example from SimpleAbleAgentBeanInfo:

returnDescriptor.setValue("able-listInNewAgentMenu", Boolean.TRUE);

getIcon()

This method provides the image for the requested size and color content.

public java.awt.Image getIcon(int iconKind) {
  switch (iconKind) {
    case BeanInfo.ICON_COLOR_16x16:
      return iconColor16x16Filename != null ? loadImage(iconColor16x16Filename) : null;
    case BeanInfo.ICON_COLOR_32x32:
      return iconColor32x32Filename != null ? loadImage(iconColor32x32Filename) : null;
    case BeanInfo.ICON_MONO_16x16:
      return iconMono16x16Filename != null ? loadImage(iconMono16x16Filename) : null;
    case BeanInfo.ICON_MONO_32x32:
      return iconMono32x32Filename != null ? loadImage(iconMono32x32Filename) : null;
  }
  return null;
}

getAdditionalBeanInfo()

This method finds the parent class, retrieves its BeanInfo object, and returns it.

public BeanInfo[] getAdditionalBeanInfo() {
  Class superclass = beanClass.getSuperclass();
  try {
    BeanInfo superBeanInfo = Introspector.getBeanInfo(superclass); // AbleObject info
    return new BeanInfo[] { superBeanInfo };
  } catch (IntrospectionException ex) {
    ex.printStackTrace();
    return null;
  }
}

getPropertyDescriptors()

This method returns an array of PropertyDescriptors for each named bean property. Any of these properties can be used to create property connections between any property of another bean, and they are also parameters available for viewing in an inspector.

public PropertyDescriptor[] getPropertyDescriptors() {
  try {
    PropertyDescriptor _action = new PropertyDescriptor("action", beanClass, "getAction", "setAction");
    PropertyDescriptor _command = new PropertyDescriptor("command", beanClass, "getCommand", "setCommand");
    PropertyDescriptor _condition = new PropertyDescriptor("condition", beanClass, "getCondition", "setCondition");
    PropertyDescriptor _fileName = new PropertyDescriptor("fileName", beanClass, "getFileName", "setFileName");
    PropertyDescriptor _threshold = new PropertyDescriptor("threshold", beanClass, "getThreshold", "setThreshold");
    PropertyDescriptor[] pds = new PropertyDescriptor[] {
          _action, _command, _condition, _fileName, _threshold };
    return pds;
  } catch (IntrospectionException ex) { 
    ex.printStackTrace();
    return null;
  }
}