use of jmri.jmrit.revhistory.FileHistory in project JMRI by JMRI.
the class ConfigXmlManager method loadOnSwingThread.
private boolean loadOnSwingThread(URL url, boolean registerDeferred) throws JmriConfigureXmlException {
boolean result = true;
Element root = null;
/* We will put all the elements into a load list, along with the load order
As XML files prior to 2.13.1 had no order to the store, beans would be stored/loaded
before beans that they were dependant upon had been stored/loaded
*/
Map<Element, Integer> loadlist = Collections.synchronizedMap(new LinkedHashMap<>());
try {
setValidate(validate);
root = super.rootFromURL(url);
// get the objects to load
List<Element> items = root.getChildren();
for (int i = 0; i < items.size(); i++) {
//Put things into an ordered list
Element item = items.get(i);
if (item.getAttribute("class") == null) {
// this is an element that we're not meant to read
log.debug("skipping {}", item);
continue;
}
String adapterName = item.getAttribute("class").getValue();
if (log.isDebugEnabled()) {
log.debug("attempt to get adapter {} for {}", adapterName, item);
}
adapterName = currentClassName(adapterName);
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
int order = adapter.loadOrder();
log.debug("add {} to load list with order id of {}", item, order);
loadlist.put(item, order);
}
ArrayList<Map.Entry<Element, Integer>> l = new ArrayList<>(loadlist.entrySet());
Collections.sort(l, (Map.Entry<Element, Integer> o1, Map.Entry<Element, Integer> o2) -> o1.getValue().compareTo(o2.getValue()));
for (int i = 0; i < l.size(); i++) {
Element item = l.get(i).getKey();
String adapterName = item.getAttribute("class").getValue();
adapterName = currentClassName(adapterName);
if (log.isDebugEnabled()) {
log.debug("load " + item + " via " + adapterName);
}
XmlAdapter adapter = null;
try {
adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
if (adapter.loadDeferred() && registerDeferred) {
// register in the list for deferred load
loadDeferredList.add(item);
if (log.isDebugEnabled()) {
log.debug("deferred load registered for " + item + " " + adapterName);
}
} else {
boolean loadStatus = adapter.load(item, item);
if (log.isDebugEnabled()) {
log.debug("load status for " + item + " " + adapterName + " is " + loadStatus);
}
// if any adaptor load fails, then the entire load has failed
if (!loadStatus) {
result = false;
}
}
} catch (Exception e) {
creationErrorEncountered(adapter, "load(" + url.getFile() + ")", "Unexpected error (Exception)", null, null, e);
// keep going, but return false to signal problem
result = false;
} catch (Throwable et) {
creationErrorEncountered(adapter, "in load(" + url.getFile() + ")", "Unexpected error (Throwable)", null, null, et);
// keep going, but return false to signal problem
result = false;
}
}
} catch (java.io.FileNotFoundException e1) {
// this returns false to indicate un-success, but not enough
// of an error to require a message
creationErrorEncountered(null, "opening file " + url.getFile(), "File not found", null, null, e1);
result = false;
} catch (org.jdom2.JDOMException e) {
creationErrorEncountered(null, "parsing file " + url.getFile(), "Parse error", null, null, e);
result = false;
} catch (java.io.IOException e) {
creationErrorEncountered(null, "loading from file " + url.getFile(), "IOException", null, null, e);
result = false;
} catch (ClassNotFoundException e) {
creationErrorEncountered(null, "loading from file " + url.getFile(), "ClassNotFoundException", null, null, e);
result = false;
} catch (InstantiationException e) {
creationErrorEncountered(null, "loading from file " + url.getFile(), "InstantiationException", null, null, e);
result = false;
} catch (IllegalAccessException e) {
creationErrorEncountered(null, "loading from file " + url.getFile(), "IllegalAccessException", null, null, e);
result = false;
} finally {
// no matter what, close error reporting
handler.done();
}
// loading complete, as far as it got, make history entry
FileHistory r = InstanceManager.getNullableDefault(FileHistory.class);
if (r != null) {
FileHistory included = null;
if (root != null) {
Element filehistory = root.getChild("filehistory");
if (filehistory != null) {
included = jmri.jmrit.revhistory.configurexml.FileHistoryXml.loadFileHistory(filehistory);
}
}
r.addOperation((result ? "Load OK" : "Load with errors"), url.getFile(), included);
} else {
log.info("Not recording file history");
}
return result;
}
use of jmri.jmrit.revhistory.FileHistory in project JMRI by JMRI.
the class FileHistoryXml method loadOperation.
public static void loadOperation(FileHistory r, Element e) {
Element s;
String type = null;
s = e.getChild("type");
if (s != null) {
type = s.getText();
}
String date = null;
s = e.getChild("date");
if (s != null) {
date = s.getText();
}
String filename = null;
s = e.getChild("filename");
if (s != null) {
filename = s.getText();
}
FileHistory filehistory = null;
s = e.getChild("filehistory");
if (s != null) {
filehistory = loadFileHistory(s);
}
r.addOperation(type, date, filename, filehistory);
}
use of jmri.jmrit.revhistory.FileHistory in project JMRI by JMRI.
the class FileHistoryAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
JFrame frame = new JmriJFrame() {
};
// JmriJFrame to ensure fits on screen
JTextArea pane = new JTextArea();
// add a little space at top
pane.append("\n");
pane.setEditable(false);
JScrollPane scroll = new JScrollPane(pane);
frame.getContentPane().add(scroll);
FileHistory r = InstanceManager.getNullableDefault(FileHistory.class);
if (r == null) {
pane.append("<No History Found>\n");
} else {
pane.append(r.toString());
}
// add a little space at bottom
pane.append("\n");
frame.pack();
// start scrolled to top
JScrollBar b = scroll.getVerticalScrollBar();
b.setValue(b.getMaximum());
// show
frame.setVisible(true);
}
use of jmri.jmrit.revhistory.FileHistory in project JMRI by JMRI.
the class FileHistoryXml method storeDirectly.
public static Element storeDirectly(Object o) {
final FileHistory r = (FileHistory) o;
if (r == null) {
// no file history object, not recording
return null;
}
Element e = historyElement(r, defaultDepth);
// add one more element for this store
FileHistory.OperationMemo rev = r.new OperationMemo() {
{
type = "Store";
date = (new java.util.Date()).toString();
filename = "";
history = null;
}
};
e.addContent(operationElement(rev, 10));
// and return
return e;
}
use of jmri.jmrit.revhistory.FileHistory in project JMRI by JMRI.
the class AppsBase method installManagers.
protected void installManagers() {
// Install a history manager
InstanceManager.store(new FileHistory(), FileHistory.class);
// record startup
InstanceManager.getDefault(FileHistory.class).addOperation("app", Application.getApplicationName(), null);
// Install a user preferences manager
InstanceManager.store(JmriUserPreferencesManager.getDefault(), UserPreferencesManager.class);
// install the abstract action model that allows items to be added to the, both
// CreateButton and Perform Action Model use a common Abstract class
InstanceManager.store(new CreateButtonModel(), CreateButtonModel.class);
// install preference manager
InstanceManager.store(new TabbedPreferences(), TabbedPreferences.class);
// install the named bean handler
InstanceManager.store(new NamedBeanHandleManager(), NamedBeanHandleManager.class);
//Install Entry Exit Pairs Manager
InstanceManager.store(new EntryExitPairs(), EntryExitPairs.class);
}
Aggregations