if (this.currentWeight > 0) {
this.weights.add(Integer.valueOf(this.currentWeight));
}
this.currentWeight = 1;
// namespace handling
OpenElementEvent open = null;
// namespace aware configuration
if (this.config.isNamespaceAware()) {
String uri = element.getNamespaceURI() == null? "" : element.getNamespaceURI();
String name = element.getLocalName();
handlePrefixMapping(uri, element.getPrefix());
open = this.efactory.makeOpenElement(uri, name);
// not namespace aware
} else {
open = this.efactory.makeOpenElement(null, element.getNodeName());
}
this.sequence.addEvent(open);
NamedNodeMap atts = element.getAttributes();
// only 1 attribute, just load it
if (atts.getLength() == 1) {
load((Attr)atts.item(0));
// several attributes sort them in alphabetical order
// TODO: also use URI
} else if (atts.getLength() > 1) {
String[] names = new String[atts.getLength()];
for (int i = 0; i < atts.getLength(); i++) {
Attr attr = (Attr)atts.item(i);
names[i] = attr.getName();
}
Arrays.sort(names);
for (String name : names) {
load((Attr)atts.getNamedItem(name));
}
}
// load all the child nodes
NodeList list = element.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
loadNode(list.item(i));
}
CloseElementEvent close = this.efactory.makeCloseElement(open);
this.sequence.addEvent(close);
// handle the weights
close.setWeight(this.currentWeight);
open.setWeight(this.currentWeight);
this.currentWeight += popWeight();
}