Search in sources :

Example 16 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class NceSensorManager method createSystemName.

@Override
public String createSystemName(String curAddress, String prefix) throws JmriException {
    if (curAddress.contains(":")) {
        //Sensor address is presented in the format AIU Cab Address:Pin Number On AIU
        //Should we be validating the values of aiucab address and pin number?
        // Yes we should, added check for valid AIU and pin ranges DBoudreau 2/13/2013
        int seperator = curAddress.indexOf(":");
        try {
            aiucab = Integer.valueOf(curAddress.substring(0, seperator)).intValue();
            pin = Integer.valueOf(curAddress.substring(seperator + 1)).intValue();
        } catch (NumberFormatException ex) {
            log.error("Unable to convert " + curAddress + " into the cab and pin format of nn:xx");
            throw new JmriException("Hardware Address passed should be a number");
        }
        iName = (aiucab - 1) * 16 + pin - 1;
    } else {
        //Entered in using the old format
        try {
            iName = Integer.parseInt(curAddress);
        } catch (NumberFormatException ex) {
            log.error("Unable to convert " + curAddress + " Hardware Address to a number");
            throw new JmriException("Hardware Address passed should be a number");
        }
        pin = iName % 16 + 1;
        aiucab = iName / 16 + 1;
    }
    // only pins 1 through 14 are valid
    if (pin == 0 || pin > MAXPIN) {
        log.error("NCE sensor " + curAddress + " pin number " + pin + " is out of range only pin numbers 1 - 14 are valid");
        throw new JmriException("Sensor pin number is out of range");
    }
    if (aiucab == 0 || aiucab > MAXAIU) {
        log.error("NCE sensor " + curAddress + " AIU number " + aiucab + " is out of range only AIU 1 - 63 are valid");
        throw new JmriException("AIU number is out of range");
    }
    return prefix + typeLetter() + iName;
}
Also used : JmriException(jmri.JmriException)

Example 17 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class Apps method doDeferredLoad.

private boolean doDeferredLoad(File file) {
    boolean result;
    log.debug("start deferred load from config");
    try {
        ConfigureManager cmOD = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
        if (cmOD != null) {
            result = cmOD.loadDeferred(file);
        } else {
            log.error("Failed to get default configure manager");
            result = false;
        }
    } catch (JmriException e) {
        log.error("Unhandled problem loading deferred configuration", e);
        result = false;
    }
    log.debug("end deferred load from config file, OK={}", result);
    return result;
}
Also used : ConfigureManager(jmri.ConfigureManager) JmriException(jmri.JmriException)

Example 18 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class LoadXmlConfigAction method loadFile.

/**
     *
     * @param fileChooser {@link JFileChooser} to use for file selection
     * @return true if successful
     */
protected boolean loadFile(JFileChooser fileChooser) {
    boolean results = false;
    java.io.File file = getFile(fileChooser);
    if (file != null) {
        try {
            ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
            if (cm == null) {
                log.error("Failed to get default configure manager");
            } else {
                results = cm.load(file);
                if (results) {
                    // insure logix etc fire up
                    InstanceManager.getDefault(jmri.LogixManager.class).activateAllLogixs();
                    InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).initializeLayoutBlockPaths();
                    new jmri.jmrit.catalog.configurexml.DefaultCatalogTreeManagerXml().readCatalogTrees();
                }
            }
        } catch (JmriException e) {
            log.error("Unhandled problem in loadFile: " + e);
        }
    } else {
        // We assume that as the file is null then the user has clicked cancel.
        results = true;
    }
    return results;
}
Also used : ConfigureManager(jmri.ConfigureManager) JmriException(jmri.JmriException)

Example 19 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class JmriConfigurationManager method load.

@Override
public boolean load(URL file, boolean registerDeferred) throws JmriException {
    log.debug("loading {} ...", file);
    try {
        if (file == null || //NOI18N
        (new File(file.toURI())).getName().equals("ProfileConfig.xml") || (new File(file.toURI())).getName().equals(Profile.CONFIG)) {
            Profile profile = ProfileManager.getDefault().getActiveProfile();
            List<PreferencesManager> providers = new ArrayList<>(InstanceManager.getList(PreferencesManager.class));
            providers.stream().forEach((provider) -> {
                this.initializeProvider(provider, profile);
            });
            if (!this.initializationExceptions.isEmpty()) {
                if (!GraphicsEnvironment.isHeadless()) {
                    ArrayList<String> errors = new ArrayList<>();
                    this.initialized.forEach((provider) -> {
                        List<Exception> exceptions = provider.getInitializationExceptions(profile);
                        if (!exceptions.isEmpty()) {
                            exceptions.forEach((exception) -> {
                                errors.add(exception.getLocalizedMessage());
                            });
                        } else if (this.initializationExceptions.get(provider) != null) {
                            errors.add(this.initializationExceptions.get(provider).getLocalizedMessage());
                        }
                    });
                    Object list;
                    if (errors.size() == 1) {
                        list = errors.get(0);
                    } else {
                        list = new JList<>(errors.toArray(new String[errors.size()]));
                    }
                    JOptionPane.showMessageDialog(null, new Object[] { (list instanceof JList) ? Bundle.getMessage("InitExMessageListHeader") : null, list, // Add a visual break between list of errors and notes // NOI18N
                    "<html><br></html>", // NOI18N
                    Bundle.getMessage("InitExMessageLogs"), // NOI18N
                    Bundle.getMessage("InitExMessagePrefs") }, // NOI18N
                    Bundle.getMessage("InitExMessageTitle", Application.getApplicationName()), JOptionPane.ERROR_MESSAGE);
                    (new TabbedPreferencesAction()).actionPerformed();
                }
            }
            if (file != null && (new File(file.toURI())).getName().equals("ProfileConfig.xml")) {
                // NOI18N
                log.debug("Loading legacy configuration...");
                return this.legacy.load(file, registerDeferred);
            }
            return this.initializationExceptions.isEmpty();
        }
    } catch (URISyntaxException ex) {
        log.error("Unable to get File for {}", file);
        throw new JmriException(ex.getMessage(), ex);
    }
    return this.legacy.load(file, registerDeferred);
// return true; // always return true once legacy support is dropped
}
Also used : TabbedPreferencesAction(apps.gui3.TabbedPreferencesAction) ArrayList(java.util.ArrayList) JmriException(jmri.JmriException) URISyntaxException(java.net.URISyntaxException) PreferencesManager(jmri.spi.PreferencesManager) Profile(jmri.profile.Profile) URISyntaxException(java.net.URISyntaxException) InitializationException(jmri.util.prefs.InitializationException) JmriException(jmri.JmriException) File(java.io.File) XmlFile(jmri.jmrit.XmlFile) JList(javax.swing.JList)

Example 20 with JmriException

use of jmri.JmriException in project JMRI by JMRI.

the class SensorGroupConditional method calculate.

@SuppressWarnings("null")
@Override
public int calculate(boolean enabled, PropertyChangeEvent evt) {
    int currentState = super.calculate(false, evt);
    if (!enabled || evt == null) {
        return currentState;
    }
    String listener = ((Sensor) evt.getSource()).getSystemName();
    log.debug("SGConditional \"" + getUserName() + "\" (" + getSystemName() + ") has event from \"" + listener + "\"");
    if (Sensor.INACTIVE == ((Integer) evt.getNewValue()).intValue()) {
        return currentState;
    }
    for (int i = 0; i < _actionList.size(); i++) {
        ConditionalAction action = _actionList.get(i);
        Sensor sn = InstanceManager.sensorManagerInstance().getSensor(action.getDeviceName());
        if (sn == null) {
            log.error("invalid sensor name in action - " + action.getDeviceName());
        }
        if (// don't change who triggered the action
        !listener.equals(action.getDeviceName())) {
            // find the old one and reset it
            if (sn.getState() != action.getActionData()) {
                try {
                    sn.setKnownState(action.getActionData());
                } catch (JmriException e) {
                    log.warn("Exception setting sensor " + action.getDeviceName() + " in action");
                }
            }
        }
    }
    log.debug("SGConditional \"" + getUserName() + "\" (" + getSystemName() + "), state= " + currentState + "has set the group actions for " + listener);
    return currentState;
}
Also used : ConditionalAction(jmri.ConditionalAction) JmriException(jmri.JmriException) Sensor(jmri.Sensor)

Aggregations

JmriException (jmri.JmriException)80 Sensor (jmri.Sensor)22 JsonException (jmri.server.json.JsonException)22 IOException (java.io.IOException)20 JsonNode (com.fasterxml.jackson.databind.JsonNode)19 JsonMockConnection (jmri.server.json.JsonMockConnection)18 ArrayList (java.util.ArrayList)10 NamedBean (jmri.NamedBean)10 Turnout (jmri.Turnout)10 Test (org.junit.Test)7 SignalMast (jmri.SignalMast)6 ConfigureManager (jmri.ConfigureManager)5 SensorManager (jmri.SensorManager)5 File (java.io.File)4 PowerManager (jmri.PowerManager)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Light (jmri.Light)3 SignalHead (jmri.SignalHead)3 FileNotFoundException (java.io.FileNotFoundException)2 Hashtable (java.util.Hashtable)2