class DefaultGroovyScriptService implements GroovyScriptService {

	@Override
	public Object validateScript(String script) throws ResultCodeException {
		Assert.notNull(script, "Script is required.");
		try {
			GroovyShell shell = new GroovyShell();
			return shell.parse(script);
		} catch (MultipleCompilationErrorsException e) {
			// get last error, it is possible add all errors
			Object error = e.getErrorCollector().getLastError();
			if (error instanceof SyntaxErrorMessage) {
				SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage)error;
				SyntaxException cause = syntaxErrorMessage.getCause();
				//
				throw new ResultCodeException(CoreResultCode.GROOVY_SCRIPT_SYNTAX_VALIDATION,
						ImmutableMap.of("message", cause.getOriginalMessage(), "line", cause.getLine()), e);
			}
			//
			throw new ResultCodeException(CoreResultCode.GROOVY_SCRIPT_VALIDATION, e);
		} catch (CompilationFailedException ex) {
			throw new ResultCodeException(CoreResultCode.GROOVY_SCRIPT_VALIDATION, ex);
		}
	}

}