Java SOAP Message ensureNamespaceDeclared(SOAPElement elem, String namespaceURI, String prefix)

Here you can find the source of ensureNamespaceDeclared(SOAPElement elem, String namespaceURI, String prefix)

Description

ensure Namespace Declared

License

Open Source License

Declaration

public static void ensureNamespaceDeclared(SOAPElement elem, String namespaceURI, String prefix)
            throws SOAPException 

Method Source Code

//package com.java2s;
/*/*w  w w . ja va 2  s. c o  m*/
 * JBoss, Home of Professional Open Source
 * Copyright 2005, JBoss Inc., and individual contributors as indicated
 * by the @authors tag.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the JBPM BPEL PUBLIC LICENSE AGREEMENT as
 * published by JBoss Inc.; either version 1.0 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

import javax.xml.soap.SOAPElement;

import javax.xml.soap.SOAPException;

public class Main {
    public static void ensureNamespaceDeclared(SOAPElement elem, String namespaceURI, String prefix)
            throws SOAPException {
        if (prefix == null || prefix.length() == 0) {
            if (namespaceURI == null || namespaceURI.length() == 0)
                return; // do not declare the empty namespace

            // verify the given URI is the default namespace
            if (!namespaceURI.equals(elem.getNamespaceURI(""))) {
                // the given URI is not the default namespace, declare locally
                elem.addNamespaceDeclaration("", namespaceURI);
            }
        } else {
            if (namespaceURI == null || namespaceURI.length() == 0)
                throw new IllegalArgumentException("namespaceURI cannot be empty unless prefix is empty");

            // verify given prefix is associated to given URI
            if (!namespaceURI.equals(elem.getNamespaceURI(prefix))) {
                // prefix is associated with other/no URI, declare locally
                elem.addNamespaceDeclaration(prefix, namespaceURI);
            }
        }
    }
}

Related

  1. createDoc(SOAPMessage soapMsg)
  2. createException(String code, String message)
  3. createFault(String message)
  4. createSOAPFault(SOAPFault fault, Throwable cause)
  5. createSOAPRequestForPartnerCategories( String userId)
  6. ensureNamespaceDeclared(SOAPElement element, String prefix, String nsURI)
  7. extractXMLPayloadFromSOAPMessage(SOAPMessage messageSOAP)
  8. getAttachmentContentType(SOAPMessage message)
  9. getBody(SOAPMessage m)