public Iterator getNamespaceAxisIterator(Object contextNode) throws UnsupportedAxisException {
if (!(contextNode instanceof OMContainer &&
contextNode instanceof OMElement)) {
return JaxenConstants.EMPTY_ITERATOR;
}
OMContainer omContextNode = (OMContainer) contextNode;
List nsList = new ArrayList();
HashSet prefixes = new HashSet();
for (OMContainer context = omContextNode;
context != null && !(context instanceof OMDocument);
context = ((OMElement) context).getParent()) {
OMElement element = (OMElement) context;
ArrayList declaredNS = new ArrayList();
Iterator i = element.getAllDeclaredNamespaces();
while (i != null && i.hasNext()) {
declaredNS.add(i.next());
}
declaredNS.add(element.getNamespace());
for (Iterator iter = element.getAllAttributes();
iter != null && iter.hasNext();) {
OMAttribute attr = (OMAttribute) iter.next();
OMNamespace namespace = attr.getNamespace();
if (namespace != null) {
declaredNS.add(namespace);
}
}
for (Iterator iter = declaredNS.iterator();
iter != null && iter.hasNext();) {
OMNamespace namespace = (OMNamespace) iter.next();
if (namespace != null) {
String prefix = namespace.getPrefix();
if (prefix != null && !prefixes.contains(prefix)) {
prefixes.add(prefix);
nsList.add(new OMNamespaceEx(namespace, context));
}
}
}
}
nsList.add(
new OMNamespaceEx(
omContextNode.getOMFactory().createOMNamespace(
"http://www.w3.org/XML/1998/namespace",
"xml"),
omContextNode));
return nsList.iterator();
}