Fast widget loading - tooltwist/documentation GitHub Wiki

This modification provides a few benefits:

  1. Widgets are loaded using XD rather than XData, so the FastXML parser is used rather than the old DOM parser. This runs much faster, and is also easier on the Java heap.

  2. Widgets are now loaded independently of the properties, and the properties aren't loaded until they are required.

  3. Projects aren't loaded until they are referenced. (later ZZZ)

Using XD rather than XData

The methods used to load widgets have previously used a XNodes node parameter containing a pointer into the definition file. With this change, these methods now receive XSelector node, and they will need to access the data slightly differently. Specifically:

  • use getString() instead of getText().
  • use select() instead of getNodes().

Most of these changes will be internal, however widgets that are containers (i.e. contain a list of child widgets) will usually have a method:

@Override
protected void loadPropertiesFromXml(WbdGenerator generator, WbdWidget widget, XNodes node) throws WbdException

This definition should be changed to:

protected void loadPropertiesFromXml(WbdGenerator generator, WbdWidget widget, XSelector node) throws WbdException, XDException

IMPORTANT: Provided the @Override annotation is there, Eclipse will recognise the changed method signature, but please search for instances without the annotation - they won't present an error message and will silently not be called.

Late widget initialization

Previously, widgets were allocated by the function that loads them from XML.

public WbdWidget loadBasicPropertiesFromXml(WbdGenerator generator, XNodes node)

To allow lazy loading, the widget's definition isn't loaded from file until such time as the widget is actually used. However, this means that the widget must be able to be allocated prior to loading it's definition. To allow this, widget allocation is separated out of the loadBasicPropertiesFromXml method. For example:

WbdWidget child = new WbdWidget();
child.loadBasicPropertiesFromXml(WbdGenerator generator, XSelector node);

Internal Notes

The WbdWidget constructor has also been split from:

public WbdWidget(String linkedWidgetFullPath, String idWithinRootWidget);

into two separate methods:

public WbdWidget() throws WbdException;	
public void may2013_markAsInitialized(String linkedWidgetFullPath, String idWithinRootWidget);

The second of these should only be called as the widget definition is loaded, from within loadBasicPropertiesFromXml().