Introspecting the Environment

The Java introspection mechanism is designed to allow you to explicitly expose various features of your Beans. This is essentially the environment asking for information about a Bean. However, there is some information that a Bean might want to know about its environment. Your Bean may want to know whether it is running in an environment that supports a graphical user interface (GUI), and it may also want to know if it is running in a development environment that is considered to be operating in design mode. Although these issues are not covered by the introspection mechanism, they seem to follow the same model; one object asks for information about another.

Design-time vs. Run-time

It is certainly possible that you would want to design a Bean that behaved differently at design-time than it does at run-time. Maybe the Bean does an enormous amount of processing, or it has some other feature that just doesn’t lend itself well to a design-time environment. A development tool can call the setDesignTime() method on the java.beans.Beans class to indicate whether or not the system is running in design mode. In turn, your Bean can call the isDesignTime() method on the same class to find out if it is running in design mode. This call could be made at the time the Bean is instantiated and stored in a variable. This way the Bean can always check the state of this variable before performing a function that is dependent upon whether it is running in design mode. ...

Get Developing Java Beans now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.