Java Dynamic Management Kit 3.2 Programming Guide
[ Previous ][ Fast Back ]Chapter 3. Design Patterns for Developing M-Beans[ Fast Forward ][ Next ]

Properties

Properties are discrete, named attributes of a JavaBeans component that define its appearance or its behavior, or are a property of the managed resource that the m-bean represents. For example, a property named ipackets in an m-bean representing an Ethernet driver could be defined to represent the number of incoming packets.

Properties can have arbitrary types, including built-in Java types, and class or interface types such as java.awt.Color.

Properties are always accessed via method calls on the object that owns them. For readable properties, there is a getter method to read the property value. For writable properties, there is a setter method to allow the property value to be updated.

Simple Properties

By default, the following design pattern is used for identifying properties:
public PropertyType getPropertyName();
public void setPropertyName(PropertyType value);

If a class definition contains a matching pair of getPropertyName() and setPropertyName() methods that take and return the same type, these methods define a read-write property. If a class definition contains only one of these methods, the method defines either a read-only or write-only property called propertyName.

Example 3-1 provides an example of a simple read-write property.

Example 3-1. A Simple Read-Write Property
public Square getFoo();
public void setFoo(Square aValue);

Boolean Properties

In addition, for Boolean properties, it is possible to define a getter method using the following design pattern:
public boolean isPropertyName();

The isPropertyName() method might be provided instead of a getPropertyName() method, or it might be provided in addition to a getPropertyName() method.

Example 3-2 provides an example of a Boolean read-write property.

Example 3-2. A Boolean Property
public boolean isRectangle();
public void setRectangle(boolean m);

Indexed Properties

An indexed property is an array PropertyElement[] that is accessed by methods of the form:
public PropertyElement getPropertyName(int index);
public void setPropertyName(int index, PropertyElement b)

If a class definition contains any one or both of these method forms, PropertyName is an indexed property. These methods can be used to read and write an indexed property value.

These methods can be defined in addition to the methods defined for simple properties. Therefore, an indexed property can be represented by four accessor methods. This is illustrated for a property called foo by Example 3-3.

Example 3-3. An Indexed Property
public Bah[] getFoo();
public void setFoo(Bah a[]);
public Bah getFoo(int a);
public void setFoo(int a, Bah b);


[ Previous ][ Home ][ Next ]
Introduction[ Up ]Event Sources