aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /** aoqi@0: * aoqi@0: * @author SAAJ RI Development Team aoqi@0: */ aoqi@0: package com.sun.xml.internal.messaging.saaj.soap.ver1_2; aoqi@0: aoqi@0: import java.util.List; aoqi@0: import java.util.Iterator; aoqi@0: import java.util.logging.Logger; aoqi@0: import java.util.logging.Level; aoqi@0: aoqi@0: import javax.xml.namespace.QName; aoqi@0: import javax.xml.soap.*; aoqi@0: aoqi@0: import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderElementImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; aoqi@0: import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants; aoqi@0: aoqi@0: aoqi@0: public class Header1_2Impl extends HeaderImpl { aoqi@0: aoqi@0: protected static final Logger log = aoqi@0: Logger.getLogger( aoqi@0: LogDomainConstants.SOAP_VER1_2_DOMAIN, aoqi@0: "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings"); aoqi@0: aoqi@0: public Header1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) { aoqi@0: super(ownerDocument, NameImpl.createHeader1_2Name(prefix)); aoqi@0: } aoqi@0: aoqi@0: protected NameImpl getNotUnderstoodName() { aoqi@0: return NameImpl.createNotUnderstood1_2Name(null); aoqi@0: } aoqi@0: aoqi@0: protected NameImpl getUpgradeName() { aoqi@0: return NameImpl.createUpgrade1_2Name(null); aoqi@0: } aoqi@0: aoqi@0: protected NameImpl getSupportedEnvelopeName() { aoqi@0: return NameImpl.createSupportedEnvelope1_2Name(null); aoqi@0: } aoqi@0: aoqi@0: public SOAPHeaderElement addNotUnderstoodHeaderElement(final QName sourceName) aoqi@0: throws SOAPException { aoqi@0: aoqi@0: if (sourceName == null) { aoqi@0: log.severe("SAAJ0410.ver1_2.no.null.to.addNotUnderstoodHeader"); aoqi@0: throw new SOAPException("Cannot pass NULL to addNotUnderstoodHeaderElement"); aoqi@0: } aoqi@0: if ("".equals(sourceName.getNamespaceURI())) { aoqi@0: log.severe("SAAJ0417.ver1_2.qname.not.ns.qualified"); aoqi@0: throw new SOAPException("The qname passed to addNotUnderstoodHeaderElement must be namespace-qualified"); aoqi@0: } aoqi@0: String prefix = sourceName.getPrefix(); aoqi@0: if ("".equals(prefix)) { aoqi@0: prefix = "ns1"; aoqi@0: } aoqi@0: Name notunderstoodName = getNotUnderstoodName(); aoqi@0: SOAPHeaderElement notunderstoodHeaderElement = aoqi@0: (SOAPHeaderElement) addChildElement(notunderstoodName); aoqi@0: notunderstoodHeaderElement.addAttribute( aoqi@0: NameImpl.createFromUnqualifiedName("qname"), aoqi@0: getQualifiedName( aoqi@0: new QName( aoqi@0: sourceName.getNamespaceURI(), aoqi@0: sourceName.getLocalPart(), aoqi@0: prefix))); aoqi@0: notunderstoodHeaderElement.addNamespaceDeclaration( aoqi@0: prefix, aoqi@0: sourceName.getNamespaceURI()); aoqi@0: return notunderstoodHeaderElement; aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addTextNode(String text) throws SOAPException { aoqi@0: log.log( aoqi@0: Level.SEVERE, aoqi@0: "SAAJ0416.ver1_2.adding.text.not.legal", aoqi@0: getElementQName()); aoqi@0: throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Header is not legal"); aoqi@0: } aoqi@0: aoqi@0: protected SOAPHeaderElement createHeaderElement(Name name) aoqi@0: throws SOAPException { aoqi@0: String uri = name.getURI(); aoqi@0: if (uri == null || uri.equals("")) { aoqi@0: log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified"); aoqi@0: throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified"); aoqi@0: } aoqi@0: return new HeaderElement1_2Impl( aoqi@0: ((SOAPDocument) getOwnerDocument()).getDocument(), aoqi@0: name); aoqi@0: } aoqi@0: aoqi@0: protected SOAPHeaderElement createHeaderElement(QName name) aoqi@0: throws SOAPException { aoqi@0: String uri = name.getNamespaceURI(); aoqi@0: if (uri == null || uri.equals("")) { aoqi@0: log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified"); aoqi@0: throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified"); aoqi@0: } aoqi@0: return new HeaderElement1_2Impl( aoqi@0: ((SOAPDocument) getOwnerDocument()).getDocument(), aoqi@0: name); aoqi@0: } aoqi@0: aoqi@0: public void setEncodingStyle(String encodingStyle) throws SOAPException { aoqi@0: log.severe("SAAJ0409.ver1_2.no.encodingstyle.in.header"); aoqi@0: throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Header"); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addAttribute(Name name, String value) aoqi@0: throws SOAPException { aoqi@0: if (name.getLocalName().equals("encodingStyle") aoqi@0: && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) { aoqi@0: aoqi@0: setEncodingStyle(value); aoqi@0: } aoqi@0: return super.addAttribute(name, value); aoqi@0: } aoqi@0: aoqi@0: public SOAPElement addAttribute(QName name, String value) aoqi@0: throws SOAPException { aoqi@0: if (name.getLocalPart().equals("encodingStyle") aoqi@0: && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) { aoqi@0: aoqi@0: setEncodingStyle(value); aoqi@0: } aoqi@0: return super.addAttribute(name, value); aoqi@0: } aoqi@0: }