001package jmri.jmrit.logixng.actions;
002
003import java.util.Locale;
004import java.util.Map;
005
006import jmri.InstanceManager;
007import jmri.JmriException;
008import jmri.jmrit.logixng.*;
009
010/**
011 * Returns from a Module or a ConditionalNG.
012 *
013 * @author Daniel Bergqvist Copyright 2022
014 */
015public class Error extends AbstractDigitalAction {
016
017    private String _message = "";
018
019    public Error(String sys, String user) {
020        super(sys, user);
021    }
022
023    @Override
024    public Base getDeepCopy(Map<String, String> systemNames, Map<String, String> userNames) throws JmriException {
025        DigitalActionManager manager = InstanceManager.getDefault(DigitalActionManager.class);
026        String sysName = systemNames.get(getSystemName());
027        String userName = userNames.get(getSystemName());
028        if (sysName == null) sysName = manager.getAutoSystemName();
029        Error copy = new Error(sysName, userName);
030        copy.setComment(getComment());
031        copy.setMessage(_message);
032        return manager.registerAction(copy);
033    }
034
035    public void setMessage(String message) {
036        _message = message;
037    }
038
039    public String getMessage() {
040        return _message;
041    }
042
043    /** {@inheritDoc} */
044    @Override
045    public Category getCategory() {
046        return Category.FLOW_CONTROL;
047    }
048
049    /** {@inheritDoc} */
050    @Override
051    public void execute() throws JmriException {
052        throw new JmriException(_message);
053    }
054
055    @Override
056    public String getShortDescription(Locale locale) {
057        return Bundle.getMessage(locale, "Error_Short");
058    }
059
060    @Override
061    public String getLongDescription(Locale locale) {
062        return Bundle.getMessage(locale, "Error_Long", _message);
063    }
064
065    /** {@inheritDoc} */
066    @Override
067    public void setup() {
068        // Do nothing
069    }
070
071//    private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(WebBrowser.class);
072
073}