Creating Java BeanInfo Classes

If you are using the Java object language, you can create Java BeanInfo classes from any class with a type of "JavaBean".

A JavaBean is a reusable software component written in Java that can be manipulated visually in a builder tool. A Java BeanInfo class is used as a standard view of a Bean. Each JavaBean can implement a BeanInfo class. Bean implementors may want to provide explicit information about the methods, properties, and events of a Bean by providing a Java BeanInfo class.

The BeanInfo class is generated with an attribute, and the following operations:

You can view the complete code by clicking the Preview tab in the BeanInfo class property sheet.

Attribute Created

The attribute has the following code:

private static final Class <ClassCode>Class = <ClassCode>.class;

Operations Created

The constructor has the following code:

<ClassCode>BeanInfo()
{
   super();
 }

The getPropertyDescriptors() operation has the following code:

public PropertyDescriptor[] getPropertyDescriptors ()
{
 // Declare the property array
 PropertyDescriptor properties[] = null;

 // Set properties
 try
 {
  // Create the array
  properties = new PropertyDescriptor[<nbProperties>];
  // Set property 1
  properties[0] = new PropertyDescriptor("<propertyCode1>" ,<ClassCode>Class;
  properties[0].setConstrained(false);
  properties[0].setDisplayName("propertyName1");
  properties[0].setShortDescription("propertyComment1");
  // Set property 2
  properties[1] = new PropertyDescriptor("<propertyCode2>" ,<ClassCode>Class;
  properties[1].setConstrained(false);
  properties[1].setDisplayName("propertyName2");
  properties[1].setShortDescription("propertyComment2");

 }
 catch
 {
  // Handle errors
 }
 return properties;
}

The getMethodDescriptors() operation has the following code:

public MethodDescriptor[] getMethodDescriptors ()
{
 // Declare the method array
 MethodDescriptor methods[] = null;
 ParameterDescriptor parameters[] = null;
  
 // Set methods
 try
 {
  // Create the array
  methods = new MethodDescriptor[<nbMethods>];
  // Set method 1
  parameters = new ParameterDescriptor[<nbParameters1>];
  parameters[0] = new ParameterDescriptor();
  parameters[0].setName("parameterCode1");
  parameters[0].setDisplayName("parameterName1");
  parameters[0].setShortDescription("parameterComment1");
  methods[0] = new MethodDescriptor("<methodCode1>", parameters);
  methods[0].setDisplayName("methodName1");
  methods[0].setShortDescription("methodComment1");
  // Set method 2
  methods[1] = new MethodDescriptor("<methodCode2>");
  methods[1].setDisplayName("methodName2");
  methods[1].setShortDescription("methodComment2");

 }
 catch
 {
  // Handle errors
 }
 return methods;
 }

When you create a Java BeanInfo class, a dependency link is automatically created between both classes and the stereotype of the Java BeanInfo class is set to <<BeanInfo>>.