entry.setKey(name);
if (ParsingUtil.VALUE.equals(keyParts[1].trim())) {
entry.setValue(value);
} else if (ParsingUtil.CONSTRAINT.equals(keyParts[1].trim())) {
Constraint constraint = null;
if (value.startsWith(ParsingUtil.IN_LIST_KEYWORD)) {
String[] lStr = value.replace(ParsingUtil.BRACKET_OPENNING, "")
.replace(ParsingUtil.BRACKET_CLOSING, "")
.replace(ParsingUtil.IN_LIST_KEYWORD, "").split(ParsingUtil.COMMA);
List<Double> listDouble = new ArrayList<Double>();
for (String s : lStr) {
try {
Double d = Double.parseDouble(s.trim());
listDouble.add(d);
} catch (NumberFormatException e) {
List<String> listStr = new ArrayList<String>();
for (String str : lStr) {
listStr.add(str);
}
constraint = new InConstraintStr(listStr);
}
}
constraint = new InConstraint(listDouble);
} else if (value.startsWith(ParsingUtil.IN_RANGE_KEYWORD)) {
String[] lStr = value.replace(ParsingUtil.BRACKET_OPENNING, "")
.replace(ParsingUtil.BRACKET_CLOSING, "")
.replace(ParsingUtil.IN_RANGE_KEYWORD, "").split(ParsingUtil.COMMA);
if (lStr.length != 2) {
throw new FSParsingException(
"Can not parse in range constraint value: " + value);
}
try {
Double min = Double.parseDouble(lStr[0].trim());
Double max = Double.parseDouble(lStr[1].trim());
constraint = new MinMaxConstraint(min, max);
} catch (NumberFormatException e) {
throw new FSParsingException(
"Failed to parse number value for parameter: " + key
+ " (value=" + value + ")", e);
}
} else if (ParsingUtil.CONSTANT_KEYWORD.equals(value)) {
constraint = new ConstantConstraint();
}
if (constraint != null && (entry instanceof ParameterEntry)) {
((ParameterEntry) entry).addConstraint(constraint);
}
}
if (entry != null) {
registerEntry(entry, currentObject, currentSection);
}
}
}
} else if ((currentSection instanceof AcquisitionSection) && (currentObject == null)) {
if (key.equals(ParsingUtil.CONTINUOUS_RANGES) || key.equals(ParsingUtil.PERIOD)) {
entry = new PredefinedEntry(key, value, EntryType.INT);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.INFINITE_MODE) || key.equals(ParsingUtil.MANUAL_MODE)
|| key.equals(ParsingUtil.ZIGZAG)) {
entry = new PredefinedEntry(key, value, EntryType.BOOL);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.SCAN_DIMENSIONS)) {
entry = new PredefinedEntry(key, value, EntryType.MATRIX);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.SCAN_MODE)) {
entry = new PredefinedEntry(key, value, EntryType.STRING);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.CONTINUOUS)) {
entry = new PredefinedEntry(key, value, EntryType.BOOL);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.DIMENSIONS)) {
entry = new PredefinedEntry(key, value, EntryType.MATRIX);
registerEntry(entry, currentObject, currentSection);
} else {
entry = new Entry(key, value, false);
registerEntry(entry, currentObject, currentSection);
}
} else if ((currentSection instanceof BehaviorSection) && (currentObject == null)) {
if (ParsingUtil.ERROR_STRATEGY.equals(key)) {
entry = new PredefinedEntry(key, value, EntryType.ENUM);
registerEntry(entry, currentObject, currentSection);
}
} else if ((currentSection instanceof InfoSection) && (currentObject == null)) {
if (key.equals(ParsingUtil.AUTHORS) || key.equals(ParsingUtil.COMMENT)
|| key.equals(ParsingUtil.CONFIG_NAME) || key.equals(ParsingUtil.CONFIG_VERSION)
|| key.equals(ParsingUtil.FLYSCAN_VERSION) || key.equals(ParsingUtil.KEYWORDS)
|| key.equals(ParsingUtil.REVISION) || key.equals(ParsingUtil.VERSION)) {
entry = new PredefinedEntry(key, value, EntryType.STRING);
registerEntry(entry, currentObject, currentSection);
} else {
entry = new Entry(key, value, false);
registerEntry(entry, currentObject, currentSection);
}
} else if ((currentSection instanceof RecordingSection) && (currentObject == null)) {
if (key.equals(ParsingUtil.SPLIT) || key.equals(ParsingUtil.MAX_SCAN_LINES_PER_FILE)
|| key.equals(ParsingUtil.MAX_STEPS_PER_FILE)) {
entry = new PredefinedEntry(key, value, EntryType.NUMBER);
registerEntry(entry, currentObject, currentSection);
}
} else if ((currentObject != null) && ParsingUtil.BUFFER.equals(currentObject.getName())) {
if (key.equals(ParsingUtil.NAME)) {
entry = new PredefinedEntry(key, value, EntryType.STRING);
registerEntry(entry, currentObject, currentSection);
}
} else if (currentObject instanceof Actor) {
if (key.equals(ParsingUtil.IDENTIFIER) || key.equals(ParsingUtil.NAME)) {
entry = new PredefinedEntry(key, value, EntryType.STRING);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.DIMENSION)) {
entry = new PredefinedEntry(key, value, EntryType.INT);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.ENABLE)) {
entry = new PredefinedEntry(key, value, EntryType.BOOL);
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.TYPE)) {
entry = new PredefinedEntry(key, value, EntryType.STRING);
registerEntry(entry, currentObject, currentSection);
} else if (currentObject instanceof Actuator) {
if (key.equals(ParsingUtil.TRAJECTORY)) {
TrajectoryType type = null;
if (((Actuator<?>) currentObject).isCustomTrajectory()) {
type = TrajectoryType.CUSTOM;
entry = new PredefinedEntry(key, value, EntryType.STRING);
} else {
entry = new TrajectoryEntry(key, value);
if (currentObject instanceof ContinuousActuator) {
type = TrajectoryType.CONTINUOUS;
} else if (currentObject instanceof StepByStepActuator) {
type = TrajectoryType.STEP_BY_STEP;
}
// else {
// type = TrajectoryType.CUSTOM;
// }
try {
Trajectory trajectory = TrajectoryParser.getInstance().parse(value, type);
((TrajectoryEntry) entry).setTrajectory(trajectory);
} catch (FSParsingException e) {
// Bufferize FSParsingException in case of custom trajectory and
// 'custom_trajectory' keyword has not been read yet
trajectoryparsingExceptionBuffer.put((Actuator<?>) currentObject, e);
}
}
registerEntry(entry, currentObject, currentSection);
} else if (key.equals(ParsingUtil.CUSTOM_TRAJECTORY)) {
entry = new PredefinedEntry(key, value, EntryType.BOOL);
registerEntry(entry, currentObject, currentSection);
boolean isCustomTrajectory = Boolean.parseBoolean(value.trim());
((Actuator<?>) currentObject).setCustomTrajectory(isCustomTrajectory);
if (isCustomTrajectory) {
// Verify if a trajectory has been specified before and overwrite it
// This is the case where trajectory entry appears prior to
// custom_trajectory=true
// line
for (Entry e : currentObject.getEntries()) {
if (e instanceof TrajectoryEntry) {
String k = e.getKey();
String v = e.getValue();
e = new PredefinedEntry(k, v, EntryType.STRING);
}
}
// Delete map entry related to FSParsingException raised when parsing the custom
// trajectory fails
trajectoryparsingExceptionBuffer.remove(currentObject);
}
} else {
entry = new Entry(key, value, false);
registerEntry(entry, currentObject, currentSection);
}
} else if (currentObject instanceof Hook) {
if (key.equals(ParsingUtil.ACTION)) {
entry = new PredefinedEntry(key, value, EntryType.ENUM);
registerEntry(entry, currentObject, currentSection);
}
} else {
entry = new Entry(key, value, false);
registerEntry(entry, currentObject, currentSection);
}
} else if (currentObject != null && currentObject instanceof BehaviorObject) {
if (ParsingUtil.DELAY.equals(key) || ParsingUtil.TIMEOUT.equals(key)) {
entry = new PredefinedEntry(key, value, EntryType.INT);
registerEntry(entry, currentObject, currentSection);
} else if (ParsingUtil.ERROR_STRATEGY.equals(key)) {
entry = new PredefinedEntry(key, value, EntryType.ENUM);
registerEntry(entry, currentObject, currentSection);
} else {
entry = new Entry(key, value, false);
registerEntry(entry, currentObject, currentSection);
}
} else if (currentObject != null && currentObject instanceof HierarchicalConstraint) {
// TODO syntaxe des contraintes hiérarchiques à clarifier
if (key.endsWith("enum")) {
List<String> possibleValues = Arrays.asList(value.replaceAll(" ", "").split(","));
Constraint inConstraint = new InConstraintStr(possibleValues);
((HierarchicalConstraint) currentObject).setConstraint(inConstraint);
} else if (key.endsWith(ParsingUtil.VALUE)) {
String constant = value.trim();
Constraint constantConstraint = new ConstantConstraintStr(constant);
((HierarchicalConstraint) currentObject).setPrerequisite(constantConstraint);
} else if (key.endsWith("min")) {
Constraint constraint = ((HierarchicalConstraint) currentObject).getConstraint();
if (constraint == null) {
constraint = new MinMaxConstraint();
}
((MinMaxConstraint) constraint).setMin(Double.parseDouble(value.trim()));
((HierarchicalConstraint) currentObject).setConstraint(constraint);
} else if (key.endsWith("max")) {
Constraint constraint = ((HierarchicalConstraint) currentObject).getConstraint();
if (constraint == null) {
constraint = new MinMaxConstraint();
}
((MinMaxConstraint) constraint).setMax(Double.parseDouble(value.trim()));
((HierarchicalConstraint) currentObject).setConstraint(constraint);