public String getNamespaceURI(String prefix) { return super.getNamespaceURI(prefix); }
private SOAPElement completeNamespaceDeclaration() { String prefix = getPrefix(); String nsURI = getNamespaceURI(); if (prefix != null && nsURI != null) { String prevNS = getNamespaceURI(prefix); if (nsURI.equals(prevNS) == false) addNamespaceDeclaration(prefix, nsURI); } return this; }
/** * Changes the name of this Element to newName if possible. SOAP Defined elements such as SOAPEnvelope, SOAPHeader, SOAPBody etc. cannot * have their names changed using this method. Any attempt to do so will result in a SOAPException being thrown. * * Callers should not rely on the element instance being renamed as is. * Implementations could end up copying the content of the SOAPElement to a renamed instance. * @param qname the new name for the Element. * @return The renamed Node * @throws SOAPException if changing the name of this Element is not allowed. */ public SOAPElement setElementQName(QName qname) throws SOAPException { if (Constants.NS_SOAP11_ENV.equals(getNamespaceURI()) || Constants.NS_SOAP12_ENV.equals(getNamespaceURI())) throw new SOAPException(BundleUtils.getMessage(bundle, "CHANGING_NAME_IS_NOT_ALLOWED", getLocalName())); return setElementQNameInternal(qname); }
/** * Creates a QName whose namespace URI is the one associated with the parameter, prefix, in the context of this SOAPElement. * The remaining elements of the new QName are taken directly from the parameters, localName and prefix. * @param localName a String containing the local part of the name. * @param prefix a String containing the prefix for the name. * @return a QName with the specified localName and prefix, and with a namespace that is associated with the prefix in the context of this SOAPElement. * This namespace will be the same as the one that would be returned by getNamespaceURI(String) if it were given prefix as it's parameter. * @throws SOAPException if the QName cannot be created. * @since SAAJ 1.3 */ public QName createQName(String localName, String prefix) throws SOAPException { String nsURI = getNamespaceURI(prefix); if (nsURI == null) throw new SOAPException(BundleUtils.getMessage(bundle, "CANNOT_OBTAIN_NAMESPACE_URI", prefix)); return new QName(nsURI, localName, prefix); }
/** * Sets the encoding style for this SOAPElement object to one specified. * * @see http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383495 * @see http://www.w3.org/TR/soap12-part1/#soapencattr * * @param encodingStyle a String giving the encoding style * @throws IllegalArgumentException if there was a problem in the encoding style being set. * @throws javax.xml.soap.SOAPException if setting the encodingStyle is invalid for this SOAPElement. */ public void setEncodingStyle(String encodingStyle) throws SOAPException { String namespaceURI = getNamespaceURI(Constants.PREFIX_ENV); NameImpl name = new NameImpl("encodingStyle", Constants.PREFIX_ENV, namespaceURI); addAttribute(name, encodingStyle); }
/** * Creates a new SOAPElement object initialized with the specified local name and prefix and adds the new element to this SOAPElement object. * * @param localName a String giving the local name for the new element * @param prefix a String giving the namespace prefix for the new element * @return the new SOAPElement object that was created * @throws javax.xml.soap.SOAPException if there is an error in creating the SOAPElement object */ public SOAPElement addChildElement(String localName, String prefix) throws SOAPException { String nsURI = getNamespaceURI(prefix); if (nsURI == null) throw new IllegalArgumentException(BundleUtils.getMessage(bundle, "CANNOT_OBTAIN_NAMESPACE_URI", prefix)); Name nameImp = new NameImpl(localName, prefix, nsURI); return addChildElement(nameImp); }
/** * The default implementation uses a DOMWriter. * SOAPContentElements overwrite this to optimize DOM callbacks. */ public void writeElement(Writer writer) throws IOException { String qualName = getElementName().getQualifiedName(); writer.write("<" + qualName); // namespaces Iterator<String> nsPrefixes = getNamespacePrefixes(); while (nsPrefixes.hasNext()) { String prefix = (String)nsPrefixes.next(); writer.write(" xmlns:" + prefix + "='" + getNamespaceURI(prefix) + "'"); } // attributes Iterator<Name> attNames = getAllAttributes(); while (attNames.hasNext()) { NameImpl name = (NameImpl)attNames.next(); String attPrefix = name.getPrefix() != null ? name.getPrefix() : ""; String attFqn = attPrefix.length() > 0 ? attPrefix + ":" + name.getLocalName() : name.getLocalName(); writer.write(" " + attFqn + "='" + getAttributeValue(name) + "'"); } writer.write(">"); writeElementContent(writer); writer.write("</" + qualName + ">"); }