public static NamespaceInfo setNamespace(XMLStreamWriter writer,
			String prefix, String namespaceURI, String defaultPrefix)
			throws XMLStreamException {
		String p = writer.getPrefix(namespaceURI);
		if (p == null) {
			// not defined yet
			NamespaceContext nsc = writer.getNamespaceContext();
			if (prefix == null || NO_PREFIX.equals(prefix)) {
				String defaultNamespaceURI = nsc.getNamespaceURI(NO_PREFIX);
				if (defaultNamespaceURI == null
						|| XMLConstants.NULL_NS_URI.equals(defaultNamespaceURI)) {
					// no defaultNS yet.
					writer.setDefaultNamespace(namespaceURI);
					return new NamespaceInfo(null, true);
				}
				return resolveNamespacePrefix(writer, nsc, defaultPrefix,
						namespaceURI);
			} else {
				return resolveNamespacePrefix(writer, nsc, prefix, namespaceURI);
			}
		} else {
			if (NO_PREFIX.equals(p)) {
				p = null;
			}
			return new NamespaceInfo(p, false);
		}
	}