use of bsh.ParseException in project adempiere by adempiere.
the class BeanShellEditor method actionValidate.
// actionProcess
/**
* Validate Script
*/
private void actionValidate() {
/** Example:
import org.compiere.util.DB;
import java.sql.*;
PreparedStatement pstmt =DB.prepareStatement("select Name, Password from AD_User where Name like 'Super%'");
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
result = rs.getString("Name") + "; password= " + rs.getString("Password");
}
**/
MUser user = MUser.get(Env.getCtx());
if (!user.isAdministrator()) {
fResult.setText("Not Administrator");
return;
}
//
m_script.setScript(editor.getText());
Exception e = null;
try {
m_script.validate();
} catch (ParseException e1) {
e = e1;
}
if (e != null) {
ADialog.error(m_WindowNo, this, "ScriptError", e.toString());
fResult.setText("Syntax errors detected.");
} else
fResult.setText("No syntax errors detected.");
}
use of bsh.ParseException in project jPOS by jpos.
the class BSHMethodTest method testExecuteThrowsParseException1.
@Test
public void testExecuteThrowsParseException1() throws Throwable {
Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
e.addContent("XXXXXXX XXXXXXXXX XXXX");
e.setAttributes(new ArrayList());
try {
BSHMethod.createBshMethod(e).execute(arguments, "testBSHMethodResultName");
fail("Expected ParseException to be thrown");
} catch (ParseException ex) {
assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 19")));
}
}
use of bsh.ParseException in project jPOS by jpos.
the class BSHMethodTest method testExecuteThrowsParseException.
@Test
public void testExecuteThrowsParseException() throws Throwable {
Element e = new Element("testBSHMethodName", Namespace.NO_NAMESPACE);
e.addContent("XXXXXXX XXXXXXXXX XXXX");
e.setAttributes(new ArrayList());
Map<Integer, ?> arguments = new HashMap();
Collection<?> returnNames = new ArrayList();
try {
BSHMethod.createBshMethod(e).execute(arguments, returnNames);
fail("Expected ParseException to be thrown");
} catch (ParseException ex) {
assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 19")));
}
}
use of bsh.ParseException in project jPOS by jpos.
the class BSHTransactionParticipantTest method testExecuteMethodThrowsParseException.
@Test
public void testExecuteMethodThrowsParseException() throws Throwable {
BSHTransactionParticipant bSHTransactionParticipant = new BSHTransactionParticipant();
try {
bSHTransactionParticipant.executeMethod(new BSHMethod("\u000E\u0019\u0003/\u0008Tz<|p", false), 100L, new CharConversionException(), new LogEvent("testBSHTransactionParticipantTag", new Object()), "testBSHTransactionParticipantResultName");
fail("Expected ParseException to be thrown");
} catch (ParseException ex) {
assertThat(ex.getMessage(), allOf(notNullValue(), containsString("line 1, column 4")));
}
}
use of bsh.ParseException in project symmetric-ds by JumpMind.
the class BshDatabaseWriterFilter method executeScripts.
@Override
protected void executeScripts(DataContext context, String key, Set<String> scripts, boolean isFailOnError) {
Interpreter interpreter = getInterpreter(context);
String currentScript = null;
try {
bind(interpreter, context, null, null, null);
if (scripts != null) {
for (String script : scripts) {
currentScript = script;
interpreter.eval(script);
}
}
} catch (EvalError e) {
if (e instanceof ParseException) {
String errorMsg = String.format("Evaluation error while parsing the following beanshell script:\n\n%s\n\nThe error was on line %d and the error message was: %s", currentScript, e.getErrorLineNumber(), e.getMessage());
log.error(errorMsg, e);
if (isFailOnError) {
throw new SymmetricException(errorMsg);
}
} else if (e instanceof TargetError) {
Throwable target = ((TargetError) e).getTarget();
String errorMsg = String.format("Evaluation error occured in the following beanshell script:\n\n%s\n\nThe error was on line %d", currentScript, e.getErrorLineNumber());
log.error(errorMsg, target);
if (isFailOnError) {
if (target instanceof RuntimeException) {
throw (RuntimeException) target;
} else {
throw new SymmetricException(target);
}
} else {
log.error("Failed while evaluating script", target);
}
}
}
}
Aggregations