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;
}
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;
}
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;
}
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
}
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;
}
Aggregations