//TODO optimize to be better than numLines*numPoints
while( (msg = reader.readLine()) != null) {
//Give all points the chance to find their data
for(DataPointRT dp: this.dataPoints){
AsciiFilePointLocatorRT pl = dp.getPointLocator();
AsciiFilePointLocatorVO plVo = pl.getVo();
Pattern pointValuePattern = Pattern.compile(plVo.getValueRegex());
Matcher pointValueMatcher = pointValuePattern.matcher(msg); //Use the index from the above message
if(pointValueMatcher.find()){
if(plVo.getPointIdentifier().equals(pointValueMatcher.group(plVo.getPointIdentifierIndex()))) {
String value = pointValueMatcher.group(plVo.getValueIndex());
PointValueTime newValue;
Date dt;
if(plVo.getHasTimestamp() && !plVo.getTimestampFormat().equals(".")) {
SimpleDateFormat fmt = new SimpleDateFormat(plVo.getTimestampFormat());
dt = fmt.parse(pointValueMatcher.group(plVo.getTimestampIndex()));
}
else if(plVo.getHasTimestamp()) {
dt = new Date(Long.parseLong(pointValueMatcher.group(plVo.getTimestampIndex())));
}
else {
dt = new Date();
}
//Switch on the type
switch(plVo.getDataTypeId()){
case DataTypes.ALPHANUMERIC:
newValue = new PointValueTime(value, dt.getTime());
break;
case DataTypes.NUMERIC:
newValue = new PointValueTime(Double.parseDouble(value), dt.getTime());
break;
case DataTypes.MULTISTATE:
newValue = new PointValueTime(Integer.parseInt(value), dt.getTime());
break;
case DataTypes.BINARY:
newValue = new PointValueTime(Boolean.parseBoolean(value), dt.getTime());
break;
default:
throw new ShouldNeverHappenException("Uknown Data type for point");
}
if(!plVo.getHasTimestamp())
dp.updatePointValue(newValue);
else
dp.savePointValueDirectToCache(newValue, null, true, true);
}
}