@Override
	public void writeNamespace(final String prefix, final String namespaceURI)
			throws XMLStreamException {
		if (activeelement == null) {
			throw new IllegalStateException("Can only write a Namespace after starting an Element" +
					" and before adding content to that Element.");
		}
		if (prefix == null || JDOMConstants.NS_PREFIX_XMLNS.equals(prefix)) {
			// recurse with the "" prefix.
			// yet another special case....
			// if the element itself was written out without a prefix, and without a namespace
			// then we update the element to have the same namespace as we have here.
			// this is required to support some native Java Transform engines that do not
			// supply content in the right order.
			if ("".equals(activeelement.getNamespacePrefix())) {
				activeelement.setNamespace(Namespace.getNamespace("", namespaceURI));
			}
			writeNamespace("", namespaceURI);
		} else {
			pendingns.add(Namespace.getNamespace(prefix, namespaceURI));
		}
	}