001package jmri.configurexml;
002
003import org.slf4j.Logger;
004import org.slf4j.LoggerFactory;
005
006/**
007 * Default operation for reporting errors while loading.
008 *
009 * @author Bob Jacobsen Copyright (c) 2010
010 */
011public class ErrorHandler {
012
013    /**
014     * Handle an error.
015     * <p>
016     * Default implementation formats and puts in log.
017     *
018     * @param e the error
019     */
020    public void handle(ErrorMemo e) {
021        StringBuilder m = new StringBuilder(e.description);
022        if (e.systemName != null) {
023            m.append(" System name \"").append(e.systemName).append("\"");
024        }
025        if (e.userName != null && !e.userName.isEmpty()) {
026            m.append(" User name \"").append(e.userName).append("\"");
027        }
028        if (e.operation != null) {
029            m.append(" while ").append(e.operation);
030        }
031        if (e.adapter != null) {
032            m.append(" in adaptor of type ").append(e.adapter.getClass().getName());
033        }
034        if (e.exception != null) {
035            m.append(" Exception: ").append(e.exception.toString());
036        }
037        m.append("\nSee http://jmri.org/help/en/package/jmri/configurexml/ErrorHandler.shtml for possibly more information.");
038        if (e.exception != null) {
039            log.error("Load Error: {}", m.toString(), e.exception);
040        } else {
041            log.error("Load Error: {}", m.toString());
042        }
043    }
044
045    /**
046     * Invoked when operation complete.
047     * <p>
048     * Default implementation doesn't do anything here, everything already
049     * logged above.
050     */
051        @edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "NM_CONFUSING", 
052            justification = "Seems to be a false positive due to jmri.jmris.simpleserver.parser.SimpleCharStream.Done()")
053    public void done() {
054    }
055
056    // initialize logging
057    private final static Logger log = LoggerFactory.getLogger(ErrorHandler.class);
058}