}
}
// check namespace declarations on this element against writer state
List uris = new ArrayList();
GrowableIntArray indexes = new GrowableIntArray();
GrowableStringArray prefs = new GrowableStringArray();
int base = writer.getNamespaceCount();
for (int i = 0; i < defcnt; i++) {
String pref = (String)m_namespaces.get(i * 2);
String uri = (String)m_namespaces.get(i * 2 + 1);
int index = uriindexes.get(uri);
if (index >= 0) {
if (writer.getNamespacePrefix(index) == null) {
indexes.add(index);
prefs.add(makeUniquePrefix(pref, prefixes));
}
} else {
indexes.add(base + uris.size());
prefs.add(makeUniquePrefix(pref, prefixes));
uris.add(uri);
}
}
// add the namespace declarations to current element
writer.pushExtensionNamespaces((String[])uris.toArray(new String[uris.size()]));
writer.openNamespaces(indexes.toArray(), prefs.toArray());
for (int i = 0; i < prefs.size(); i++) {
String prefix = prefs.get(i);
String name = prefix.length() > 0 ? "xmlns:" + prefix : "xmlns";
writer.addAttribute(0, name, writer.getNamespaceUri(indexes.get(i)));
}
} catch (IOException e) {
throw new JiBXException("Error writing output document", e);
}