Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[ice-dev] Very big changes to XML handling

Everyone,

I spent the past couple days reworking the way that we handle XML. I was having a lot of trouble getting the AbstractListComponent to work properly with the XML scheme as it was previously implemented, so I decided to do a little bit of a code review.

The previous scheme was pretty simple. Everything that needed to be written to or read from XML implemented the Persistable interface. The implementation or use of this interface occurred in 295 places in the code, but they actually only used in 5 production, run-time places. The remaining 290 places were either places where unused implementations were provided (or empty implementations! You know who you are...) or the tests.

So, I deleted them all.

The new scheme uses the XMLPersistenceProvider, which now realizes the IWriter and IReader interfaces. If you have an IFile in an Item, writing or reading something to XML is as simple as calling something like

getIOService().getWriter("xml").write(form,file);

with the exception of inside the setupForm operation. The IOService is not available on the Item when the setupForm operation is called because it is called during the constructor. In this case, getting the XML is still relatively easy using the ICEJAXBHandler. For example,

// Get the PROTEUS spec file
IFile specFile = getPreferencesDirectory().getFile("ICEProteusInput.xml");
// Try to get the Form from it
ArrayList<Class> classList = new ArrayList<Class>();
classList.add(Form.class);
ICEJAXBHandler handler = new ICEJAXBHandler();
try {
form = (Form) handler.read(classList, specFile.getContents());
} catch (NullPointerException | JAXBException | IOException
| CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

I renamed the ICEJAXBManipulator to the ICEJAXBManipulator and modified it so that it takes a list of classes with which its JAXBContext should be instantiated. It should be used in any case where the IOService can't be used. The IOService only works with Forms, but the ICEJAXBManipulator can handle everything annotated with JAXB, such as the Entry, ICEObject or AbstractListComponent classes.

This may seem like a pain, but it isn't. I rewrote all of the tests to use this (something like 78 places or something) instead of the old scheme. In general, you should never have to use the ICEJAXBHandler, but it is there if you need it. The IOService took the place of 3/5 of the production XML calls and the ICEJAXBHandler took the place of the remaining 2/5 because they were in setupForm() for PROTEUS and SHARP. I have submitted a bug ticket so that we can fix those two so that they can use the IOService instead.

I don't imagine that this will affect you very much, but I thought an explanation was in order given the degree of the changes. 

I also updated the IWriter and IReader interfaces to use IFile instead of URIs. It is just a more convenient handle to the file with more operations than the URI interface.

Both ICE and the build are faster now thanks to some optimizations that I was able to make in this process.

As usual, file any tickets if you experience bugs with this and let me know if you have any concerns. This is a good example of how a code review can vastly improve the system with a moderate amount of follow up work.

Merry Christmas!

Jay

--
Jay Jay Billings
Oak Ridge National Laboratory
Twitter Handle: @jayjaybillings

Back to the top