Developing Java Beans changed, the getPropertyName() method may
Developing Java Beans null, it goes back to the source to get the value of the CurrentTemperature property. If it isn’t null, the value is retrieved directly from the new value object. A support class called java.beans.PropertyChangeSupport can be used to fire property change events to the registered listeners. You can either inherit from this class, or directly use an instance of it. PropertyChangeSupport implements the java.io.Serializable interface, which we discuss in Chapter 5. The method signatures of this class are as follows: public class java.beans.PropertyChangeSupportimplements java.io.Serializable { // construct the objectpublic PropertyChangeSupport(Object source); // add a property change listener public synchronized void addPropertyChangeListener(PropertyChangeListener l); // fire a property change event to any listeners public void firePropertyChange(String propertyName, Object oldValue, Object newValue); // remove a property change listener public synchronized void removePropertyChangeListener(PropertyChangeListener l); } We could reimplement the Temperature class by inheriting from the PropertyChangeSupportclass. This would eliminate the code that deals with the property change events. Note that the version of the constructor that takes no parameters calls the superclass constructor to make itself the event source. Although we aren’t going to keep the Temperature class like this, here’s what the code would look like if we did: package BeansBook.Simulator; import java.beans.*; import java.util.Vector; public class Temperature extends PropertyChangeSupport { // the current temperature in Celsiusprotected double currentTemp = 22.2; // the constructors public Temperature(double startingTemp) { this(); currentTemp = startingTemp; } public Temperature() { super(this); } // the get method for property CurrentTemperature public double getCurrentTemperature() { return currentTemp; } page 59
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services