Chapter 3 Building Structural Diagrams


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>>.

Creating a Java BeanInfo class from the Language menu

Steps To create a Java BeanInfo class from the Language menu:

  1. Select Language→Create BeanInfo Classes to display the Create BeanInfo Classes selection window. This window contains a list of all the classes of type JavaBean in the model.
  2. Select the classes for which you want to generate Java BeanInfo classes and click OK.

    A BeanInfo class is created in the model for each selected class.

Creating a Java BeanInfo class from the class contextual menu

Steps To create a Java BeanInfo class from the class contextual menu:

  1. Right-click a class in the diagram, and select Create BeanInfo Class from the contextual menu.

 


Copyright (C) 2006. Sybase Inc. All rights reserved.