Image and who can't figure out why the BeanBox won't load the bean. The problem is that java.awt.Image isn't Serializable, therefore neither is anything that contains a java.awt.Image, at least without custom serialization.I myself have spent countless hours putting println() statements into the BeanBox code then recompiling it, trying to figure out why my beans won't load. Sometimes it's due to
some simple, stupid thing -- like forgetting to define the zero-argument constructor, or even the class, as public. Other times, it turns out to be something more obscure.
While the requirements to write a Java class as a JavaBean are simple and straightforward, there are some hidden implications
that many bean builder tools don't address. These little gotchas can easily eat up an afternoon, as you hunt through your code, searching for the reason your builder tool can't find your
bean. If you're lucky, you'll get a pop-up dialog box with a cryptic error message -- something along the lines of "NoSuchMethodException caught in FoolTool Introspection." If you're unlucky, the JavaBean you've poured so much sweat into will refuse to appear in your builder tool, and you'll
spend the afternoon rehearsing the vocabulary your mother tried so hard to cure you of. The BeanBox has long been an egregious
offender in this regard, and though it has been improving, it will still drop properties and even whole beans without providing
the developer with a single clue as to why.
This month, I'll be leading you out of the "land of the missing bean" by introducing a new tool called, oddly, BeanLint, which analyzes classes within jar files, looking for possible problems that would make the classes unusable as beans. While
this tool doesn't cover every possible bean problem, it does identify some of the major common problems that make beans unloadable.
In order to understand how BeanLint works its magic, this month and next we'll delve into some of the lesser-known corners of the standard Java API:
Introspector to produce a report of all of the class's beanlike properties for any class in the jar file that passes all tests (and is,
therefore, a potential bean)
By the time we're done, you'll have a useful tool for debugging your beans, you'll better understand bean requirements, and you'll learn about some of Java's cool new features at the same time.
For a class file to be a JavaBean, there are two simple requirements:
java.io.SerializableThat's it. Follow those two simple rules, and your class will be a JavaBean. The simplest JavaBean, then, looks something like this:
BeanLint to do even more. The spec is available for download at http://java.sun.com/beans/spec.html
class BeanLint can be downloaded at http://www.javaworld.com/jw-12-1998/beans/BeanLint.java
resolve flag in java.lang.ClassLoader, see http://java.sun.com/products/jdk/1.1/docs/api/java.lang.ClassLoader.html