use of jmri.util.prefs.InitializationException in project JMRI by JMRI.
the class ScriptButtonModelXml method load.
@Override
public boolean load(Element shared, Element perNode) throws JmriException {
// Should the script engines be pre-loaded here?
boolean result = false;
ScriptButtonModel model = new ScriptButtonModel();
// NOI18N
model.setName(shared.getAttribute("name").getValue());
for (Element child : shared.getChildren("property")) {
// NOI18N
if (// NOI18N
child.getAttributeValue("name").equals("script") && child.getAttributeValue("value") != null) {
// NOI18N
// NOI18N
String script = child.getAttributeValue("value");
try {
model.setScript(FileUtil.getFile(script));
result = true;
} catch (FileNotFoundException ex) {
model.addException(new InitializationException(Bundle.getMessage(Locale.ENGLISH, "ScriptButtonModel.ScriptNotFound", script), Bundle.getMessage("ScriptButtonModel.ScriptNotFound", script), ex));
log.error("Unable to create button for script {}", script);
}
}
}
// store the model
InstanceManager.getDefault(StartupActionsManager.class).addAction(model);
return result;
}
use of jmri.util.prefs.InitializationException in project JMRI by JMRI.
the class ManagerDefaultSelector method initialize.
@Override
public void initialize(Profile profile) throws InitializationException {
if (!this.isInitialized(profile)) {
// NOI18N
Preferences settings = ProfileUtils.getPreferences(profile, this.getClass(), true).node("defaults");
try {
for (String name : settings.keys()) {
String connection = settings.get(name, null);
Class<?> cls = this.classForName(name);
log.debug("Loading default {} for {}", connection, name);
if (cls != null) {
this.defaults.put(cls, connection);
log.debug("Loaded default {} for {}", connection, cls);
}
}
} catch (BackingStoreException ex) {
log.info("Unable to read preferences for Default Selector.");
}
InitializationException ex = this.configure();
ConfigureManager manager = InstanceManager.getNullableDefault(ConfigureManager.class);
if (manager != null) {
// allow ProfileConfig.xml to be written correctly
manager.registerPref(this);
}
this.setInitialized(profile, true);
if (ex != null) {
throw ex;
}
}
}
use of jmri.util.prefs.InitializationException in project JMRI by JMRI.
the class ManagerDefaultSelector method configure.
/**
* Load into InstanceManager
*
* @return an exception that can be passed to the user or null if no errors
* occur
*/
@CheckForNull
public InitializationException configure() {
InitializationException error = null;
List<SystemConnectionMemo> connList = InstanceManager.getList(SystemConnectionMemo.class);
log.debug("configure defaults into InstanceManager from {} memos, {} defaults", connList.size(), defaults.keySet().size());
for (Class<?> c : defaults.keySet()) {
// 'c' is the class to load
String connectionName = this.defaults.get(c);
// have to find object of that type from proper connection
boolean found = false;
for (SystemConnectionMemo memo : connList) {
String testName = memo.getUserName();
if (testName.equals(connectionName)) {
found = true;
// match, store
try {
if (memo.provides(c)) {
log.debug(" setting default for \"{}\" to \"{}\" in configure", c, memo.get(c));
InstanceManager.setDefault(c, memo.get(c));
}
} catch (NullPointerException ex) {
// NOI18N
String englishMsg = Bundle.getMessage(Locale.ENGLISH, "ErrorNullDefault", memo.getUserName(), c);
// NOI18N
String localizedMsg = Bundle.getMessage("ErrorNullDefault", memo.getUserName(), c);
error = new InitializationException(englishMsg, localizedMsg);
log.warn("SystemConnectionMemo for {} ({}) provides a null {} instance", memo.getUserName(), memo.getClass(), c);
}
break;
} else {
log.debug(" memo name didn't match: {} vs {}", testName, connectionName);
}
}
/*
* If the set connection can not be found then we shall set the manager default to use what
* has currently been set.
*/
if (!found) {
log.debug("!found, so resetting");
String currentName = null;
if (c == ThrottleManager.class && InstanceManager.getNullableDefault(ThrottleManager.class) != null) {
currentName = InstanceManager.throttleManagerInstance().getUserName();
} else if (c == PowerManager.class && InstanceManager.getNullableDefault(PowerManager.class) != null) {
currentName = InstanceManager.getDefault(PowerManager.class).getUserName();
} else if (c == ProgrammerManager.class && InstanceManager.getNullableDefault(ProgrammerManager.class) != null) {
currentName = InstanceManager.getDefault(ProgrammerManager.class).getUserName();
}
if (currentName != null) {
log.warn("The configured " + connectionName + " for " + c + " can not be found so will use the default " + currentName);
this.defaults.put(c, currentName);
}
}
}
return error;
}
Aggregations