protected void marshalElement(Element element)
throws JiBXException, IOException {
// accumulate all needed namespace declarations
int size = element.nodeCount();
Namespace ns = element.getNamespace();
int nsi = findNamespaceIndex(ns);
ArrayList nss = null;
boolean hascontent = false;
int defind = -1;
String defuri = null;
for (int i = 0; i < size; i++) {
Node node = element.node(i);
if (node instanceof Namespace) {
Namespace dns = (Namespace)node;
if (findNamespaceIndex(dns) < 0) {
if (nss == null) {
nss = new ArrayList();
}
nss.add(dns);
String prefix = dns.getPrefix();
if (prefix == null || prefix.length() == 0) {
defind = nss.size() - 1;
defuri = dns.getURI();
}
}
} else {
hascontent = true;
}
}
// check for namespace declarations required
String[] uris = null;
if (nss == null) {
m_xmlWriter.startTagOpen(nsi, element.getName());
} else {
int base = getNextNamespaceIndex();
if (defind >= 0) {
m_defaultNamespaceIndex = base + defind;
m_defaultNamespaceURI = defuri;
}
uris = new String[nss.size()];
int[] nums = new int[nss.size()];
String[] prefs = new String[nss.size()];
for (int i = 0; i < uris.length; i++) {
Namespace addns = (Namespace)nss.get(i);
uris[i] = addns.getURI();
nums[i] = base + i;
prefs[i] = addns.getPrefix();
if (nsi < 0 && ns.equals(addns)) {
nsi = base + i;
}
}
m_xmlWriter.pushExtensionNamespaces(uris);