001package jmri.beans; 002 003import java.util.Set; 004 005/** 006 * Generic implementation of {@link jmri.beans.BeanInterface} with a complete 007 * implementation of {@link java.beans.PropertyChangeSupport} and support for 008 * arbitrary properties defined at runtime. 009 * <p> 010 * See the PropertyChangeSupport documentation for complete documentation of 011 * those methods. 012 * 013 * @author Randall Wood 014 * @see java.beans.PropertyChangeSupport 015 */ 016public abstract class ArbitraryBean extends Bean { 017 018 protected final ArbitraryPropertySupport arbitraryPropertySupport = new ArbitraryPropertySupport(this); 019 020 @Override 021 public void setProperty(String key, Object value) { 022 if (BeanUtil.hasIntrospectedProperty(this, key)) { 023 BeanUtil.setIntrospectedProperty(this, key, value); 024 } else { 025 Object oldValue = this.arbitraryPropertySupport.getProperty(key); 026 this.arbitraryPropertySupport.setProperty(key, value); 027 this.firePropertyChange(key, oldValue, value); 028 } 029 } 030 031 @Override 032 public void setIndexedProperty(String key, int index, Object value) { 033 if (BeanUtil.hasIntrospectedIndexedProperty(this, key)) { 034 BeanUtil.setIntrospectedIndexedProperty(this, key, index, value); 035 } else { 036 Object oldValue = this.arbitraryPropertySupport.getIndexedProperty(key, index); 037 this.arbitraryPropertySupport.setIndexedProperty(key, index, value); 038 this.fireIndexedPropertyChange(key, index, oldValue, value); 039 } 040 } 041 042 @Override 043 public Object getIndexedProperty(String key, int index) { 044 return this.arbitraryPropertySupport.getIndexedProperty(key, index); 045 } 046 047 @Override 048 public Object getProperty(String key) { 049 return this.arbitraryPropertySupport.getProperty(key); 050 } 051 052 @Override 053 public boolean hasProperty(String key) { 054 return this.arbitraryPropertySupport.hasProperty(key); 055 } 056 057 @Override 058 public boolean hasIndexedProperty(String key) { 059 return this.arbitraryPropertySupport.hasIndexedProperty(key); 060 } 061 062 @Override 063 public Set<String> getPropertyNames() { 064 return this.arbitraryPropertySupport.getPropertyNames(); 065 } 066 067}