class SaajUtils {

	public static Name toName(QName qName, SOAPElement resolveElement) throws SOAPException {
		String qNamePrefix = qName.getPrefix();
		SOAPEnvelope envelope = getEnvelope(resolveElement);
		if (StringUtils.hasLength(qName.getNamespaceURI()) && StringUtils.hasLength(qNamePrefix)) {
			return envelope.createName(qName.getLocalPart(), qNamePrefix, qName.getNamespaceURI());
		} else if (StringUtils.hasLength(qName.getNamespaceURI())) {
			Iterator<?> prefixes;
			if (getSaajVersion(resolveElement) == SAAJ_11) {
				prefixes = resolveElement.getNamespacePrefixes();
			} else {
				prefixes = resolveElement.getVisibleNamespacePrefixes();
			}
			while (prefixes.hasNext()) {
				String prefix = (String) prefixes.next();
				if (qName.getNamespaceURI().equals(resolveElement.getNamespaceURI(prefix))) {
					return envelope.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI());
				}
			}
			return envelope.createName(qName.getLocalPart(), "", qName.getNamespaceURI());
		} else {
			return envelope.createName(qName.getLocalPart());
		}
	}

}