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.
|
|
|
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.
| CODE EXAMPLE 3-1 A Simple Read-Write Property |
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.
| CODE EXAMPLE 3-2 A Boolean Property |
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.
| CODE EXAMPLE 3-3 An Indexed Property |
Event Sources
The JavaBeans component model defines design patterns for:
|
public void addEventListenerType(EventListenerType a);
public removeEventListenerType(EventListenerType a); |
CODE EXAMPLE 3-4 defines a multicast event source.
| CODE EXAMPLE 3-4 A Simple Listener |
Unicast Event Sources
By default, the following design pattern is used to define which unicast events an m-bean can send:
|
public void addEventListenerType(EventListenerType a)
throws java.util.TooManyListenersException; public removeEventListenerType(EventListenerType a); |
These design patterns are the same as those defined in "Multicast Event Sources" on page 36, except that the signature of the addEventListenerType method includes the clause throws java.util.TooManyListenersException. This exception is thrown if the addEventListenerType method is invoked when a listener is already registered.
Both the methods take the same EventListenerType type argument. This design pattern assumes that the m-bean is a unicast event source for the events specified in the EventListenerType interface.
Initializing and Deleting an M-Bean
The methods for initializing and deleting an m-bean are callbacks which the framework invokes. They are optional for an m-bean but if you want to provide them, you have to write them yourself. The methods are:
Note - The methods for initializing and deleting an m-bean are not part of the JavaBeans component model, but are specific to the m-bean model.
The initCmf method you define must have one of the following signatures::
|
public void initCmf(Framework cmf, ObjectName name)
throws IllegalAccessException, ServiceNotFoundException, InstanceAlreadyExistException; |
|
public void initCmf(Framework cmf, ObjectName name,
boolean persist, ModificationList list) throws IllegalAccessException, ServiceNotFoundException, InstanceAlreadyExistException; |
The parameters in the call to initCmf are as follows:
cmf - the framework that the m-bean is to be registered with
name - the object name to be assigned to the m-bean
persist - true if persistent storage is required for the registered m-bean, false otherwise
list - additional information for registering the m-bean
The deleteCmf method you define must have the following signature:
|
public void deleteCmf()
|
The services provided under com.sun.jaw.impl.agent.services contain an implementation of the deleteCmf method.
Actions
An action is a public method of an m-bean that is intended to be invoked remotely. Public methods in an m-bean that are not actions are intended to be invoked only by other local m-beans.
Note - The action design pattern is not part of the JavaBeans component model, but is specific to the m-bean model.
|
public AnyJavaType performAnAction(AnySignature)
|