Developing Java Beans reject an unacceptable change to

Developing Java Beans theTemperature = temperature; // register for property change events theTemperature.addPropertyChangeListener(this); // construct the constrained property support object constrainedHandler = new VetoableChangeSupport(this); } [The existing code goes here] // add a VetoableChangeListener public void addVetoableChangeListener(VetoableChangeListener l) { // defer to the support handler constrainedHandler.addVetoableChangeListener(l); } // remove a VetoableChangeListener public void removeVetoableChangeListener(VetoableChangeListener l) { // defer to the support handler constrainedHandler.removeVetoableChangeListener(l); } // get the MinimumTemperature property value public double getMinimumTemperature() { return minTemperature; } // set the MinimumTemperature property value public void setMinimumTemperature(double newVal) throws PropertyVetoException { // let’s check against our own criterion first if (newVal < 10.0) { PropertyChangeEvent e = new PropertyChangeEvent(this, "MinimumTemperature", null, new Double(newVal)); throw new PropertyVetoException("Bad MinimumTemperature", e); } // defer to the support handler constrainedHandler.fireVetoableChange("MinimumTemperature", new Double(minTemperature), new Double(newVal)); // if the previous call did not throw an exception, then we are// free to make the changeminTemperature = newVal; } } The setMinimumTemperature() method first checks to see that the new value is not less than the absolute minimum value of 10 degrees Celsius. If it's not, the fireVetoableChange() method is called on the support object. This method handles all of the details of notifying the registered VetoableChangeListener objects and reverting them to the old value if any of them reject the change. If the change is rejected, the PropertyVetoException will be thrown. If not, the last line saves the new value of the property. page 63
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services

Comments are closed.