/** Configures an integer. * @param flag one of POSTIVE_ONLY, NON_NEGATIVE and ANY_VALUE. */ private static Integer parseInteger(Element el, String subnm, int flag) throws UiException { //Note: we throw exception rather than warning to make sure //the developer correct it String val = el.getElementValue(subnm, true); if (val != null && val.length() > 0) { try { final int v = Integer.parseInt(val); if ((flag == POSITIVE_ONLY && v <= 0) || (flag == NON_NEGATIVE && v < 0)) throw new UiException(message( "The " + subnm + " element must be a " + (flag == POSITIVE_ONLY ? "positive" : "non-negative") + " number, not " + val, el)); return new Integer(v); } catch (NumberFormatException ex) { //eat throw new UiException(message("The " + subnm + " element must be a number, not " + val, el)); } } return null; }
private static <T> Class<T> parseClass(Element el, String elnm, Class<?> cls, boolean required) { //Note: we throw exception rather than warning to make sure //the developer correct it final String clsnm = el.getElementValue(elnm, true); if (clsnm != null && clsnm.length() != 0) { try { final Class<?> klass = Classes.forNameByThread(clsnm); if (cls != null && !cls.isAssignableFrom(klass)) { String msg = message(clsnm + " must implement " + cls.getName(), el); if (required) throw new UiException(msg); log.error(msg); return null; } // if (log.debuggable()) log.debug("Using "+clsnm+" for "+cls); return cast(klass); } catch (Throwable ex) { String msg = ex instanceof ClassNotFoundException ? clsnm + " not found" : "Unable to load " + clsnm; msg = message(msg, el); if (required) throw new UiException(msg, ex); log.error(msg); return null; } } else if (required) throw new UiException(message(elnm + " required", el)); return null; }
v = parseInteger(el, "error-code", NON_NEGATIVE); if (v == null) throw new UiException(message("error-code is required", el)); String uri = IDOMs.getRequiredElementValue(el, "reload-uri"); if ("false".equals(uri))