public void checkValid(CharSequence literal)
throws DatatypeException {
// TODO find out what kind of thread concurrency guarantees are made
ContextFactory cf = new ContextFactory();
Context cx = cf.enterContext();
RegExpImpl rei = new RegExpImpl();
String anchoredRegex = "^(?:" + literal + ")$";
try {
rei.compileRegExp(cx, anchoredRegex, "");
} catch (EcmaError ee) {
throw newDatatypeException(ee.getErrorMessage());
} finally {
Context.exit();
}