@Override
public Object parse(String value) throws Exception {
// clean up extra space
value = value.trim();
ScaleToExtentType se = Wcs20Factory.eINSTANCE.createScaleToExtentType();
int base = 0;
for (;;) {
// search the open parenthesis
int idxOpen = value.indexOf("(", base);
if (idxOpen == -1) {
throw new WCS20Exception(
"Invalid ScaleExtent syntax, expecting a comma separate list of axisName(min,max)*",
WCS20Exception.WCS20ExceptionCode.InvalidEncodingSyntax, "scaleExtent");
}
int idxNextOpen = value.indexOf("(", idxOpen + 1);
// search the closed parens
int idxClosed = value.indexOf(")", idxOpen);
if (idxClosed == -1 || (idxNextOpen > 0 && idxClosed > idxNextOpen)) {
throw new WCS20Exception(
"Invalid ScaleExtent syntax, expecting a comma separate list of axisName(min,max)*",
WCS20Exception.WCS20ExceptionCode.InvalidEncodingSyntax, "scaleExtent");
}
int idxNextClosed = value.indexOf(")", idxClosed + 1);
// the comma between the parens (we start from base to make sure it's actually between the parens)
int idxMid = value.indexOf(",", base);
if (idxMid == -1 || idxMid >= idxClosed - 1 || idxMid <= idxOpen + 1) {
throw new WCS20Exception(
"Invalid ScaleExtent syntax, expecting a comma separate list of axisName(min,max)*",
WCS20Exception.WCS20ExceptionCode.InvalidEncodingSyntax, "scaleExtent");
}
int idxNextMid = value.indexOf(",", idxMid + 1);
if(idxNextMid != -1 && idxNextMid < idxClosed) {
throw new WCS20Exception(
"Invalid ScaleExtent syntax, expecting a comma separate list of axisName(min,max)*",
WCS20Exception.WCS20ExceptionCode.InvalidEncodingSyntax, "scaleExtent");
}
// extract the three components
String axisName = value.substring(base, idxOpen);
String low = value.substring(idxOpen + 1, idxMid);
String high = value.substring(idxMid + 1, idxClosed);
try {
TargetAxisExtentType te = Wcs20Factory.eINSTANCE.createTargetAxisExtentType();
te.setAxis(axisName.trim());
te.setLow(Double.valueOf(low));
te.setHigh(Double.valueOf(high));
se.getTargetAxisExtent().add(te);
} catch(NumberFormatException e) {
WCS20Exception ex = new WCS20Exception(
"Invalid ScaleExtent syntax, expecting a comma separate list of axisName(min,max)*",
WCS20Exception.WCS20ExceptionCode.InvalidEncodingSyntax, "scaleExtent");
ex.initCause(e);