/** * Add message to Advisory if there is one otherwise throw an exception. * * @param message Error message * @throws ParsingException Thrown only if there is not Advisory. */ private static void error(String message) throws ParsingException { final Advisory advisory = Context.getButDontThrow(Advisory.class); if (advisory != null) { advisory.error(message); } else { throw new ParsingException(message); } }
/** * Can't override valueOf() so uUse this method instead as it treats boolean properly. If an error * is detected the Advisory is updated. * * @param key The key to look up. * @return The DataType associated with the given key. */ public static DataType valueOfCorrected(String key) { DataType result; try { if ("boolean".equals(key)) { result = bool; } else { result = DataType.valueOf(key); } } catch (final IllegalArgumentException e) { // todo Perhaps throw the catch when the Locus is known? final Advisory advisory = Context.get(Advisory.class); advisory.error("Invalid data type: " + key); result = any; } return result; }