- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
Using the BeanInfo Interface in Java
Using the BeanInfo Interface Creating QR In Java Using Barcode creation for Java Control to generate, create QR Code 2d barcode image in Java applications. Quick Response Code Reader In Java Using Barcode reader for Java Control to read, scan read, scan image in Java applications. In our previous examples, design patterns were used to determine the information that was provided to a Bean user This section describes how a developer can use the BeanInfo interface to explicitly control this process This interface defines several methods, including these: PropertyDescriptor[ ] getPropertyDescriptors( ) EventSetDescriptor[ ] getEventSetDescriptors( ) MethodDescriptor[ ] getMethodDescriptors( ) They return arrays of objects that provide information about the properties, events, and methods of a Bean By implementing these methods, a developer can designate exactly what is presented to a user SimpleBeanInfo is a class that provides default implementations of the BeanInfo interface, including the three methods just shown You may extend this class and override one or more of them The following listing shows how this is done for the Colors Bean that was developed earlier ColorsBeanInfo is a subclass of SimpleBeanInfo It overrides getPropertyDescriptors( ) in order to designate which properties are presented to a Bean user This method creates a PropertyDescriptor object for the rectangular property The PropertyDescriptor constructor that is used is shown here: PropertyDescriptor(String property, Class beanCls) throws IntrospectionException Here, the first argument is the name of the property, and the second argument is the class of the Bean // A Bean information class package sunwdemocolors; import javabeans*; public class ColorsBeanInfo extends SimpleBeanInfo { public PropertyDescriptor[] getPropertyDescriptors() { try { PropertyDescriptor rectangular = new PropertyDescriptor("rectangular", Colorsclass); PropertyDescriptor pd[] = {rectangular}; return pd; } catch(Exception e) { } return null; } } You must compile this file from the BDK\\demo directory or set CLASSPATH so that it includes c:\\bdk\\demo If you don't, the compiler won't find the Colorsclass file properly After this file is successfully compiled, the colorsmft file can be updated, as shown here: Bar Code Maker In Java Using Barcode printer for Java Control to generate, create bar code image in Java applications. Recognizing Bar Code In Java Using Barcode decoder for Java Control to read, scan read, scan image in Java applications. - 596 - Making QR Code In C# Using Barcode creation for .NET framework Control to generate, create QR Code image in .NET framework applications. Make QR Code In .NET Framework Using Barcode encoder for ASP.NET Control to generate, create QR Code image in ASP.NET applications. Name: sunw/demo/colors/ColorsBeanInfoclass Name: sunw/demo/colors/Colorsclass Java-Bean: True Use the JAR tool to create a new colorsjar file Restart the BDK and create an instance of the Colors Bean in the BeanBox The introspection facilities are designed to look for a BeanInfo class If it exists, its behavior explicitly determines the information that is presented to a Bean user Otherwise, design patterns are used to infer this information Figure 25-5 shows how the Properties window now appears Compare it with Figure 243 You can see that the properties inherited from Component are no longer presented for the Colors Bean Only the rectangular property appears Print QR Code In VS .NET Using Barcode printer for .NET framework Control to generate, create QR Code ISO/IEC18004 image in .NET framework applications. Painting QR Code 2d Barcode In VB.NET Using Barcode creator for VS .NET Control to generate, create QR Code image in .NET framework applications. Figure 255: Using the ColorsBeanInfo Class
Drawing ANSI/AIM Code 39 In Java Using Barcode printer for Java Control to generate, create Code39 image in Java applications. Print GS1 DataBar In Java Using Barcode generation for Java Control to generate, create GS1 DataBar Expanded image in Java applications. Constrained Properties
UPC Symbol Generator In Java Using Barcode creator for Java Control to generate, create UPC Symbol image in Java applications. Code-39 Encoder In Java Using Barcode encoder for Java Control to generate, create Code 3/9 image in Java applications. A Bean that has a constrained property generates an event when an attempt is made to change its value The event is of type PropertyChangeEvent It is sent to objects that previously registered an interest in receiving such notifications Those other objects have the ability to veto the proposed change This capability allows a Bean to operate differently according to its run-time environment A full discussion of constrained properties is beyond the scope of this book Making USPS PLANET Barcode In Java Using Barcode creation for Java Control to generate, create USPS Confirm Service Barcode image in Java applications. Reading Universal Product Code Version A In .NET Framework Using Barcode recognizer for VS .NET Control to read, scan read, scan image in VS .NET applications. Persistence
European Article Number 13 Creation In Java Using Barcode creation for BIRT reports Control to generate, create UPC - 13 image in Eclipse BIRT applications. EAN-13 Generation In None Using Barcode generation for Microsoft Word Control to generate, create EAN13 image in Office Word applications. Persistence is the ability to save a Bean to nonvolatile storage and retrieve it at a later time The information that is particularly important are the configuration settings Let us first see how the BDK allows you to save a set of Beans that have been configured and connected together to form an application Recall our previous example involving both the Colors and TickTock Beans The rectangular property of the Colors Bean was changed to true, and the interval property of the TickTock Bean was changed to one second To save the application, go to the menu bar of the BeanBox and select File | Save A dialog box should appear, allowing you to specify the name of a file to which the Beans and their configuration parameters should be saved Supply a filename and click the OK button on that dialog box Exit from the BDK Start the BDK again To restore the application, go to the menu bar of the BeanBox and select File | Load A dialog box should appear, allowing you to specify the name of the file from which an application should be restored Supply the name of the file in which the Painting Linear 1D Barcode In Visual Basic .NET Using Barcode printer for Visual Studio .NET Control to generate, create Linear 1D Barcode image in .NET applications. Barcode Drawer In Java Using Barcode maker for Android Control to generate, create barcode image in Android applications. - 597 - Barcode Maker In None Using Barcode generation for Font Control to generate, create bar code image in Font applications. Bar Code Maker In Java Using Barcode creation for BIRT reports Control to generate, create bar code image in BIRT reports applications. application was saved, and click the OK button Your application should now be functioning Confirm that the rectangular property of the Colors Bean is true and that the interval property for the TickTock Bean is equal to one second The object serialization capabilities provided by the Java class libraries are used to provide persistence for Beans If a Bean inherits directly or indirectly from javaawtComponent, it is automatically serializable, because that class implements the javaioSerializable interface If a Bean does not inherit an implementation of the Serializable interface, you must provide this yourself Otherwise, containers cannot save the configuration of your component The transient keyword can be used to designate data members of a Bean that should not be serialized The color variable of the Colors class is an example of such an item
|
|