import java.beans.*; public class Country { // instances of Property- and VetoableChangeSupport to give all the // hard work of listener management to. protected PropertyChangeSupport changesButler; protected VetoableChangeSupport vetosButler; // the guts of the vetoable 'countryStatus' property protected String countryStatus; // the guts of the 'countryName' property protected String countryName; //------------------------------------------------------------------- // Country Constructors //------------------------------------------------------------------- public Country() { // all beans need default constructors! this("Atlantis", "hidden"); } public Country(String name, String status) { this.countryName = name; this.countryStatus = status; changesButler = new PropertyChangeSupport(this); vetosButler = new VetoableChangeSupport(this); } //------------------------------------------------------------------- // set()/get() for 'CountryName' property //------------------------------------------------------------------- public void setCountryName( String newValue) { String oldName = countryName; countryName = newValue; changesButler.firePropertyChange("countryName", oldName, newValue); } public String getCountryName() { return countryName; } //------------------------------------------------------------------- // set()/get() for 'CountryStatus' vetoable property //------------------------------------------------------------------- public void setCountryStatus(String newValue) throws PropertyVetoException { // see if any listener objects first. Note that the property has not // yet changed at this time. vetosButler.fireVetoableChange("countryStatus", countryStatus, newValue); // if any listener vetoed the change, then this line will never be // executed: the veto exception would have aborted the method and // returned to the caller of setCountryStatus(). // if no listener vetoed, then we just change the property value. countryStatus = newValue; } public String getCountryStatus() { return countryStatus; } //------------------------------------------------------------------- // the listener (de)registration methods are trivial: just let the // Property- or VetoableChangeSupport class do all the hard work for us. //------------------------------------------------------------------- public void addPropertyChangeListener (PropertyChangeListener l) { changesButler.addPropertyChangeListener(l); } public void removePropertyChangeListener (PropertyChangeListener l) { changesButler.removePropertyChangeListener(l); } public void addVetoableChangeListener (VetoableChangeListener l) { vetosButler.addVetoableChangeListener(l); } public void removeVetoableChangeListener (VetoableChangeListener l) { vetosButler.removeVetoableChangeListener(l); } } // End of Class Country