Please see code examples at Bean Shell Programming