Working with the Bean Validator
Introduction
To analyze a bean, you select a bean,
select categories and options to analyze, run the analysis, and examine the results.
Selecting
a Bean to Analyze
To analyze a bean using the Bean
Validator in VisualAge for Java:
- From VisualAge for Java, import a bean
JAR or class file. If you have a bean that depends on another bean (bean.JAR and
bean1.JAR, respectively), then you must import both into the same project making sure that
you import bean.JAR first. Bean.JAR is the dependent bean and should be imported
after the base bean (bean1.JAR).
- Right-click the bean's primary class
file.
- Select Tools - Bean Validator
to launch the Bean Validator.
To analyze a bean using the Bean
Validator as a stand-alone tool:
- In the directory where you installed the
Bean Validator double-click bvalid. (For AIX, type sh bvalid.sh).
Alternatively, if you have a problem with the bat files, you can open a command prompt and
enter: java com.ibm.beantools.validator.Validator.
- Click the Select Bean
button.
- Navigate to the location of your JAR or
class file.
- Select the JAR or class file, and click
the Open button.
The name of your JAR or class file appears in the Bean Name field.
Selecting Categories and Options
Now, select the categories you want to
analyze in the bean. When you select a category, the Bean Validator checks all the cases
included in the category.
Two options
are available from the Options
tab:
- If you select the Bean Fields are
Serializable case, you can select Traverse Entire Class Graph
from the Options tab.
- If you select the Packaging
Category, the Options tab displays the current JAR File window. Since your bean may be
dependent on additional beans, you can validate these JAR files as well. This option
is only active when you use the Bean Validator as a VisualAge for Java plug-in tool.
To select the Packaging option:
- Click the Packaging category.
- Click the Select JAR file button
to display the Load JAR file dialog box.
- Find the JAR file and click Open.
The Bean Validator checks the packaging of the bean JAR.
Important: For packaging to work correctly in the VisualAge for
Java plug-in tool, locate the directory where you keep the bean.JAR and load the bean.JAR
from VisualAge for Java.
Understanding
the Results
After you select the categories you want
to check, click the Run button to analyze the bean. The bean's
diagnostic results display in the Results tab, as shown in the following illustration,
Use the scrollbar at the bottom to read longer messages.
The Bean Validator displays three
message indicators:
- pass
-- the bean meets JavaBean guidelines
- fail
-- the bean does not meet JavaBean
guidelines
- informational
-- provides extra information
about the bean
JavaBean guidelines specify that a bean
have a JAR file. If the Bean Validator does not detect a bean JAR, the entire Packaging
category fails
. A bean should also be serializable so
you can save it. If a bean does not implement Serialization properly, the case fails
. For all
other situations, the Bean Validator issues an informational
message; for example, if a bean
is not digitally signed.
Saving
the the Results
- To save your results to a text file, click Save Results.
- Specify the name and location of where to save the file, and click OK.
About
the Categories
The Bean Validator uses the JavaBean Guidelines
JavaBean Guidelines written by IBM JavaBean developers (previously known as the WebRunner
tools group) to check your bean in the following categories:
- Serialization
-- Implement the Serializable and Externalizable interfaces to assure your bean is
persistent.
- BeanInfo
-- Extends the java.beans.SimpleBeanInfo Class to provide introspective data describing
your bean.
- Packaging
--Verifies that a bean is packaged so it can be distributed to visual builders or across
the Internet.
- Internationalization
-- Verifies that a bean contains property files that support various languages and
countries.
- Serialization
- You must either implement Serialization
or Externalization to assure your bean is persistent. Serialization enables you to save
your bean by converting it to a serial object stream of data. Serialization requires that
you serialize or deserialize (write or read) to an object stream. The Externalizable
interface gives you more control over how your bean's data is saved. The Bean Validator
uses Reflection, which reports the contents of the bean, to verify that your bean
implements Serialization using proper serialization mechanisms in accordance with the
JavaBean Guidelines created by the VADD toolkit group. To learn more about object
serialization in VisualAge for Java, see Object Serialization in VisualAge in
VisualAge for Java online help. You can also refer to Sun's JavaBean specifications at http://www.javasoft.com/beans/docs/spec.html.
-
- Bean implements Serializable
- Uses Reflection to verify that the
Serializable or Externalizable interface is implemented.
-
- Bean fields are Serializable
- Uses Reflection to traverse all
non-transient data fields of the bean's class graph, and verifies that Serializable and
Externalizable are implemented properly.
-
- Bean is Serializable/Deserializable
- Bean is Serializable is a run-time test
that uses the default constructor to both serialize and deserialize a bean. If the
NotSerializable Exception is thrown, the Bean Validator concludes that Serialization is
not supported by your bean. Specifically, the case fails
because the bean or one of its fields failed to properly implement Serialization.
-
- Bean contains serialVersionUID
- This allows a bean to be backward
compatible with previous versions. SerialVersionUID is a constant long field used to store
the version number of a bean.
- If you fail to define a SerialVersionUID,
Java Serializable will generate one for you. However, any changes you make in your
bean's footprint will result in Serialization incompatibility. Declaring a
SerialVersionUID gives you more control over merging incompatible bean versioning. The
Bean Validator displays an informational
symbol next to category to tell you when the long integer is
not explicitly defined.
-
- BeanInfo
- BeanInfo data is used by visual builders
to textually and graphically depict the bean inside visual builders. The Bean Validator
verifies the existence of classes, methods, and icon information. See Bean Interfaces
and BeanInfo in VisualAge for Java online help to define a bean interface in
VisualAge for Java. You can also refer to Sun's JavaBean specifications at http://www.javasoft.com/beans/docs/spec.html.
-
- BeanInfo class
implemented
- Verifies that a BeanInfo
class is included with the bean. The Bean Validator concatenates the word
"BeanInfo" onto the bean name and then searches for the BeanInfo class in the
current package. If the BeanInfo does not exist, the Bean Validator provides an
informational message
.
- Bean Icons
- Verifies that the bean
provides bean icons so it can graphically depict itself inside a visual builder.
- Bean Descriptor
- Verifies that BeanInfo provides a
BeanDescriptor with more information about the bean.
- Method, Property, and
Event Descriptors
- Tells whether a bean uses
custom or default descriptors. Also verifies that EventListeners implement the
java.util.EventListener interface.
- Property Editors
- Verifies that
non-primitive properties provide a
custom Property Editor.
- Bean Customizer
- Tells whether BeanInfo
provides a customizer.
-
- Packaging
- A Java Archive file (JAR) is a compressed
file and container that holds everything your bean needs to be functional. The Bean
Validator checks for a manifest file, dependencies, design and run-time classes, and
digital signatures. For more information on packaging, see the JavaBean Guidelines
JavaBean Guidelines. You can also refer to Sun's JavaBean specifications at http://www.javasoft.com/beans/docs/spec.html.
-
- Verify MANIFEST items
- Verifies that the manifest file, which
contains a list of the JAR contents, is included inside the JAR file. The Bean Validator
also verifies that all fields listed in the manifest file are actual zip entries in the
JAR. If the Bean Validator detects that the manifest file is not in the JAR, the entire
Packaging category fails
.
- JAR contains beans
- Reads the manifest file to see how many
beans are contained in the JAR. Generates a listing of all the beans delivered in the
JAR, and warns of case-sensitivity problem in the MANIFEST file.
- Depends-On flag satisfied
- Reads the Depends-On attribute and
assures that all dependencies are contained in the JAR file. If Depends-On contains
a class and or a ser file, the Bean Validator verifies that these files are also in the
JAR file.
- Digest-Algorithms present
- Verifies that the JAR file contains the
MD5-Digest and SHA-Digest algorithms. MD5-Digest and SHA-Digest are numerical
representations that assure your files have not been damaged or corrupted during
transmission. These algorithms assure that the complete class is delivered over the
network and protects against tampering.
- Design-time-only classes
- The Bean Validator generates a list of
classes declared to be Design-Time-Only. It also verifies that run-time classes do not
have a Depends-On relationship against design-time-only classes. Design-Time-Only classes
include BeanInfo classes, descriptors, customizers, icons, and gifs.
- JAR has valid signature
- To secure the contents of your JAR file,
JDK 1.1 provides a utility called javakey. The javakey utility lets you authenticate
the contents of your JAR so that the receiver of the JAR knows the file is secure
and its contents are from a trustworthy signer. Authentication requires that the
signer have a public key-private key pair that must be authenticated by a digitally signed
certificate from an entity (company or person). The javakey utility also manages
entities, public and private keys, and certificates.
-
- The Bean Validator verifies that the two
files necessary to accomplish signature authentication are contained in the META-INF
directory. The first file, a security signature file (.sf), describes the elements
of the digitally signed certificate. The second file contains an encrypted copy of the
signature file (.dsa).
-
- Internationalization
- Organizes your bean applications into
locale-specific units to extend your application globally.
- Resource Bundles
- Checks whether the bean provides classes
that extend java.util.ResouceBundle.
- Property Files
- Property files are the preferred
mechanism for localizing beans. Use property files to localize a bean without
recompiling.
- Countries and Languages
- Generates a list of countries and
languages for which the bean has been localized.
