Developing Java Beans // notify listening objects of CurrentTemperature property changes protected void notifyTemperatureChange() { // fire the eventfirePropertyChange(”CurrentTemperature”, null, new Double(currentTemp)); } } 4.4 Constrained Properties To this point we’ve assumed that all the property changes that take place are acceptable. Often this will not be the case; it’s possible that an attempt to set a property to a given value will be unacceptable and therefore rejected. The simple case is when the object that owns the property wants to reject the change, but there may be times when another object wants a chance to voice its disapproval. Properties that go through this approval process are known as constrained properties. The design pattern for setting and getting constrained properties is similar to the design pattern for properties that are not constrained. The difference is that the set method declares that it throws the exception java.beans.PropertyVetoException. The method signatures look as follows: public get(); public void set( value) throws java.beans.PropertyVetoException; 4.4.1 Binding to Non-Specific Constrained Properties Those objects that want to participate in the approval process for a change to a constrained property must implement the java.beans.VetoableChangeListener interface. This interface contains a method called vetoableChange() that takes a single parameter of type PropertyChangeEvent. This method may throw the java.beans.PropertyVetoException if it wants to reject the change. Objects that support constrained properties must provide methods for registering and unregistering VetoableChangeListener objects. The methods should look like the following: public void addVetoableChangeListener(VetoableChangeListener p); public void removeVetoableChangeListener(VetoableChangelistener p); It’s possible for the object that owns the property to reject a change itself. So if a set() method is called with an unacceptable property value, the java.beans.PropertyVetoException can be thrown. If the owning object does not reject the change, it must send notifications to all registered VetoableChangeListener objects. This interaction is shown in Figure 4.2. Figure 4.2. Vetoable property changes page 60
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services
This entry was posted
on Friday, September 29th, 2006 at 8:00 pm and is filed under java.
You can follow any responses to this entry through the RSS 2.0 feed.
Responses are currently closed, but you can trackback from your own site.