JavaBeans of users
JavaBeans developers can give a beans add user (Customizer), property Editor (PropertyEditor) and Beansinfo interface to describe a beans content. Beans users can use this information that comes with beans in a construction environment to beans the look and actions that should be done. A beans does not have to have Beanscustomizer, Prpertyeditor, and Beansinfo, which, according to the actual situation, are optional, and when some beans are more complex, this information should be provided, Enables Beans users to wizard a beans in a way that allows them to be used. Some simple beans may not have this information, the constructor can use its own perspective device to perspective the contents of the beans and display the information in a standard property sheet or event table for the user to beans, and the beans properties, methods, and event names mentioned in the previous sections are named in a certain format. The main role is for the development tool to beans perspective. Of course, it is also convenient for programmers to use beans in handwritten programs, so that he can see his name and know his meaning.
User interface (Customizer Interface)
When a beans has its own user, it can display its own property sheet within the construction tool. Java must be implemented when defining a user. Beanss.customizer interface. For example, the following is a user-beans of a "button":
public class OurButtonCustomizer
extends Panel implements Customizer {
... ...
/* When the real phenomenon ourbuttoncustomizer such a general property sheet,
Be sure to implement Addproperchangelistener in them
And Removepropertychangelistener, so that
The constructor tool can use these feature codes to add listeners to a property event. */
... ...
private PropertyChangeSupport changes=new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener l) {
changes.addPropertyChangeListener(l);
public void removePropertyChangeListener(PropertyChangeListener l) {
changes.removePropertyChangeListener(l);
}
... ...
Property Editor Interface (PropertyEditor Interface)
A JavaBeans can provide a propertyeditor class that creates an editor for the specified property. This class must inherit from Java. Beanss.propertyeditorsupport class. Programmers who construct tools and handwriting code do not use this class directly, but rather instantiate and invoke this class in the Beansinfo in the next section. Cases:
public class MoleculeNameEditor extends java.Beanss.PropertyEditorSupport {
public String[] getTags() {
String resule[]={
"HyaluronicAcid","Benzene","buckmisterfullerine",
"cyclohexane","ethane","water"};
return resule;}
}
In the example above, a property editor is created for the Tags property, and in the constructor tool, you can select from the Drop-down table that the Moleculename attribute should be "hyaluronicaid" or "water".
Beansinfo interface
Each beans class may also have a beansinfo class associated with it, which describes the appearance of the beans when it appears inside the constructor tool. In Beansinfo, you can define properties, methods, events, display their names, and provide a simple help note. For example:
public class MoleculeBeansInfo extends SimpleBeansInfo {
public PropertyDescriptor[] getPropertyDescriptors() {
try {
PropertyDescriptor pd=new PropertyDescriptor("moleculeName",Molecule.class);
/* The Moleculenameeditor class in the previous section is referenced through PD, and the Moleculename property is obtained and returned.
pd.setPropertyEditorClass(MoleculeNameEditor.class);
PropertyDescriptor result[]={pd};
return result;
} catch(Exception ex) {
System.err.println("MoleculeBeansInfo: unexpected exeption: "+ex);
return null;
}
}
}
JavaBeans Persistence
When a JavaBeans is instantiated within a construction tool and connected to other beans, all its states should be saved, the next time it is load into the constructor tool, or at run time, it should be the last modified information. In order to do this, the information of some fields of beans should be saved, and the beans should be implemented java.io.Serializable interface when defining. For example:
public class Button
implements java.io.Serializable {
}
The information for the fields in the beans that implements the serialization interface is automatically saved. If you do not want to save information for some fields, you can prefix these fields with transient or static keywords, and the information for transient and static variables cannot be saved. In general, all publicly available attributes of a beans should be saved, and the internal state can optionally be saved. Beans developers to modify the software, you can add fields, remove references to other classes, change the private/protected/public state of a field, which does not affect the class's storage structure relationship. However, when you remove a field from a class, change the position of a variable in the class system, change a field to transient/static, or transient/static, and change to a different feature, the storage relationship changes.
Storage format for JavaBeans
When the JavaBeans component is designed, it is typically stored in a zip-format file with an extension jar, contains information about JavaBeans in the jar, and specifies which of these classes are JavaBeans in the manifest file. The JavaBeans of jar file storage greatly reduces the number of data transmitted in the network, and binds some resources required by JavaBeans runtime, this chapter mainly discusses some internal characteristics of JavaBeans and its conventional design methods, Reference is the JavaBeans specification 1.0A version. As the world's major ISVs support JavaBeans more and more, the specification is evolving in some detail, but the basic framework will not change much.