String expectedMessage,
int expressionNumber)
throws ViewParameterException
{
StreamTypeService streamTypeService = new StreamTypeServiceImpl(statementContext.getEngineURI(), false);
ExprTimePeriodEvalDeltaConst timeDelta;
if (expression instanceof ExprTimePeriod) {
ExprTimePeriod validated = (ExprTimePeriod) ViewFactorySupport.validateExpr(viewName, statementContext, expression, streamTypeService, expressionNumber);
timeDelta = validated.constEvaluator(new ExprEvaluatorContextStatement(statementContext));
}
else {
Object result = ViewFactorySupport.validateAndEvaluateExpr(viewName, statementContext, expression, streamTypeService, expressionNumber);
if (!(result instanceof Number)) {
throw new ViewParameterException(expectedMessage);
}
Number param = (Number) result;
long millisecondsBeforeExpiry;
if (JavaClassHelper.isFloatingPointNumber(param)) {
millisecondsBeforeExpiry = Math.round(1000d * param.doubleValue());
}
else {
millisecondsBeforeExpiry = 1000 * param.longValue();
}
timeDelta = new ExprTimePeriodEvalDeltaConstMsec(millisecondsBeforeExpiry);
}
if (timeDelta.deltaMillisecondsAdd(0) < 1) {
throw new ViewParameterException(viewName + " view requires a size of at least 1 msec");
}
return timeDelta;
}