001package jmri.implementation; 002 003import jmri.Reporter; 004 005/** 006 * Abstract base for the Reporter interface. 007 * <p> 008 * Implements the parameter binding support. 009 * <p> 010 * Note that we consider it an error for there to be more than one object that 011 * corresponds to a particular physical Reporter on the layout. 012 * 013 * Abstract class providing the basic logic of the Reporter 014 * interface 015 * 016 * @author Bob Jacobsen Copyright (C) 2001 017 * @author Matthew Harris Copyright (C) 2011 018 */ 019public abstract class AbstractReporter extends AbstractNamedBean implements Reporter { 020 021 public AbstractReporter(String systemName) { 022 super(systemName); 023 } 024 025 public AbstractReporter(String systemName, String userName) { 026 super(systemName, userName); 027 } 028 029 @Override 030 public String getBeanType() { 031 return Bundle.getMessage("BeanNameReporter"); 032 } 033 034 @Override 035 public Object getCurrentReport() { 036 return _currentReport; 037 } 038 039 @Override 040 public Object getLastReport() { 041 return _lastReport; 042 } 043 044 /** 045 * Provide a general method for updating the report. 046 */ 047 @Override 048 public void setReport(Object r) { 049 if (r == _currentReport) { 050 return; 051 } 052 Object old = _currentReport; 053 Object oldLast = _lastReport; 054 _currentReport = r; 055 if (r != null) { 056 _lastReport = r; 057 // notify 058 firePropertyChange(PROPERTY_LAST_REPORT, oldLast, _lastReport); 059 } 060 // notify 061 firePropertyChange(PROPERTY_CURRENT_REPORT, old, _currentReport); 062 } 063 064 /** 065 * {@inheritDoc} 066 * <p> 067 * Default implementation is a no-op for generic reporters. 068 */ 069 @Override 070 public void notifySeenElsewhere(jmri.IdTag tag, Reporter newReporter) { 071 // Default no-op 072 } 073 074 /** 075 * Helper function to notify that the collection property has been updated. 076 * Always uses null as the previous value as the collection might be the same object. 077 * <p> 078 * This should only be used if we don't have a change in the current report. If notify(tag) is 079 * already called, there is no need to additionally call this. 080 */ 081 public void notifyCollectionUpdated() { 082 if (this instanceof jmri.CollectingReporter) { 083 firePropertyChange(Reporter.PROPERTY_COLLECTION, null, ((jmri.CollectingReporter) this).getCollection()); 084 } 085 } 086 087 // internal data members 088 protected Object _lastReport = null; 089 protected Object _currentReport = null; 090 091}