stella.sensor
Class FileCurrent

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by stella.sensor.AbstractDataCollector
                  extended by stella.sensor.FileCurrent
All Implemented Interfaces:
Cloneable, DataCollecting, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying

public class FileCurrent
extends AbstractDataCollector

A simple class that writes out the data it obtained from the SensorRepository to a file. If the KEY_MAPLIST property is given, only sensors present in this list are writtn. The file (KEY_CURRENT) is writtn whenever data is available. Depending on the KEY_APPEND property, the file is either newly writtn at each call or appended to. A typical file may look as

   #      Date           nsolz       solz
   30.09.02 18:10:07*  +35.08866* +35.27701*
   
The values given are the physical averages, if available. Otherwise the raw values are given.
If the data events received are weather-data events, their rule is added to the value. Bad weather data receives an extra KEY_BADFLAG string added to the value, while for good weather data this string is replaced with an empty string of equal length.


Nested Class Summary
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private  DateFormat date
          The date formatter to use for output.
private static boolean DEFAPPEND
          The default appending behaviour.
private static String DEFBADFLAG
          The default setting of the bad-weather indicator.
private static String DEFCURRENT
          The default name of the output file.
private static String DEFDATE
          The date/time formatter.
private static long DEFINTERVAL
          The default notification period in ms.
private static boolean DEFSTRICT
          The default adding to file behaviour on incomplete sets.
private static String DEFUNIT
          The default unit string.
private static String DEFVALIDFLAG
          The default setting of the non-valid-reading indicator.
private static String DEFWEATHER
          The default binding name of the weather trigger.
static String KEY_APPEND
          The key defining if appending should be enabled.
static String KEY_BADFLAG
          The key to the bad-weather indicator.
static String KEY_CURRENT
          The key to the file where the current data should be writtn to.
static String KEY_DATE
          The key to the date-format string.
static String KEY_MAPLIST
          The key to a list of sensor that should be mapped.
static String KEY_STRICT
          If true, only data sets containing all sensors are writtn.
static String KEY_UNIT
          The key to the default unit string.
static String KEY_VALIDFLAG
          The key to the non-valid reading indicator.
static String KEY_WEATHER
          The key to the bindname of the weather parameter.
private  List map
          The list of all sensor names that should be mapped in the output file.
private  Map validread
          A mapping of sensor names to last valid readings.
 
Fields inherited from class stella.sensor.AbstractDataCollector
KEY_CLASS, KEY_INTERVAL, KEY_RMIDATACOLLECT
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG
 
Constructor Summary
FileCurrent(Map prop)
          Constructs a new file collector.
 
Method Summary
 long getInterval()
          Returns the notification interval.
private static boolean isValidReading(DataEvent de)
          Defines if the handed-over data event consists of valid readings.
 void processData(Map sensor, boolean weather)
          The file collector writes out all the data it received in a single file.
 String toString()
          A short description of the current data collector.
private  void writeData(Writer out, Map data, boolean weather)
          Writes the sensor data to the given stream.
private  void writeHeader(Writer out, Map data)
          Writes a header to the specified stream.
 
Methods inherited from class stella.sensor.AbstractDataCollector
createDataCollector
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, init, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.Initializable
init
 

Field Detail

KEY_CURRENT

public static final String KEY_CURRENT
The key to the file where the current data should be writtn to.

See Also:
Constant Field Values

KEY_APPEND

public static final String KEY_APPEND
The key defining if appending should be enabled.

See Also:
Constant Field Values

KEY_WEATHER

public static final String KEY_WEATHER
The key to the bindname of the weather parameter.

See Also:
Constant Field Values

KEY_BADFLAG

public static final String KEY_BADFLAG
The key to the bad-weather indicator.

See Also:
Constant Field Values

KEY_VALIDFLAG

public static final String KEY_VALIDFLAG
The key to the non-valid reading indicator.

See Also:
Constant Field Values

KEY_MAPLIST

public static final String KEY_MAPLIST
The key to a list of sensor that should be mapped. If undefined, all sensors are writtn to the output file.

See Also:
Constant Field Values

KEY_STRICT

public static final String KEY_STRICT
If true, only data sets containing all sensors are writtn.

See Also:
Constant Field Values

KEY_UNIT

public static final String KEY_UNIT
The key to the default unit string.

See Also:
Constant Field Values

KEY_DATE

public static final String KEY_DATE
The key to the date-format string.

See Also:
Constant Field Values

DEFINTERVAL

private static final long DEFINTERVAL
The default notification period in ms.

See Also:
Constant Field Values

DEFCURRENT

private static final String DEFCURRENT
The default name of the output file.

See Also:
Constant Field Values

DEFAPPEND

private static final boolean DEFAPPEND
The default appending behaviour.

See Also:
Constant Field Values

DEFWEATHER

private static final String DEFWEATHER
The default binding name of the weather trigger.

See Also:
Constant Field Values

DEFBADFLAG

private static final String DEFBADFLAG
The default setting of the bad-weather indicator.

See Also:
Constant Field Values

DEFVALIDFLAG

private static final String DEFVALIDFLAG
The default setting of the non-valid-reading indicator.

See Also:
Constant Field Values

DEFSTRICT

private static final boolean DEFSTRICT
The default adding to file behaviour on incomplete sets.

See Also:
Constant Field Values

DEFUNIT

private static final String DEFUNIT
The default unit string.

See Also:
Constant Field Values

DEFDATE

private static final String DEFDATE
The date/time formatter.

See Also:
Constant Field Values

map

private List map
The list of all sensor names that should be mapped in the output file.


validread

private Map validread
A mapping of sensor names to last valid readings.


date

private DateFormat date
The date formatter to use for output.

Constructor Detail

FileCurrent

public FileCurrent(Map prop)
Constructs a new file collector. The KEY_CURRENT, the KEY_APPEND, the KEY_STRICT, the KEY_WEATHER and the two flags, KEY_BADFLAG and KEY_VALIDFLAG obtain their default values if not present. If the KEY_MAPLIST property is set, the look-up list for the sensors to output is initialized.

Method Detail

getInterval

public long getInterval()
Returns the notification interval.


processData

public void processData(Map sensor,
                        boolean weather)
The file collector writes out all the data it received in a single file. This file is updated whenever new data arrives.
To give the file a unique characteristic, it is advisable that the calling method uses a sorted map to allow a constant ordering of the sensor readouts in the file.

Parameters:
sensor - Mapping sensor names to data events.
weather - True if current weather is good.

writeHeader

private void writeHeader(Writer out,
                         Map data)
                  throws IOException
Writes a header to the specified stream. If the map look-up list is defined, only matching sensor names are considered.

Throws:
IOException

writeData

private void writeData(Writer out,
                       Map data,
                       boolean weather)
                throws IOException
Writes the sensor data to the given stream. If the look-up list map exists, only sensors given in this list are writtn out.

Throws:
IOException

toString

public String toString()
A short description of the current data collector.

Overrides:
toString in class PropertyContainer

isValidReading

private static boolean isValidReading(DataEvent de)
Defines if the handed-over data event consists of valid readings. This is fulfilled if