1 /* 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 /** 27 * 28 * @author SAAJ RI Development Team 29 */ 30 package com.sun.xml.internal.messaging.saaj.soap.ver1_2; 31 32 import java.util.logging.Logger; 33 import java.util.logging.Level; 34 35 import javax.xml.namespace.QName; 36 import javax.xml.soap.*; 37 38 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; 39 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument; 40 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; 41 import com.sun.xml.internal.messaging.saaj.soap.impl.HeaderImpl; 42 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; 43 import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants; 44 45 46 public class Header1_2Impl extends HeaderImpl { 47 48 protected static final Logger log = 49 Logger.getLogger( 50 LogDomainConstants.SOAP_VER1_2_DOMAIN, 51 "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings"); 52 53 public Header1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) { 54 super(ownerDocument, NameImpl.createHeader1_2Name(prefix)); 55 } 56 57 protected NameImpl getNotUnderstoodName() { 58 return NameImpl.createNotUnderstood1_2Name(null); 59 } 60 61 protected NameImpl getUpgradeName() { 62 return NameImpl.createUpgrade1_2Name(null); 63 } 64 65 protected NameImpl getSupportedEnvelopeName() { 66 return NameImpl.createSupportedEnvelope1_2Name(null); 67 } 68 69 public SOAPHeaderElement addNotUnderstoodHeaderElement(final QName sourceName) 70 throws SOAPException { 71 72 if (sourceName == null) { 73 log.severe("SAAJ0410.ver1_2.no.null.to.addNotUnderstoodHeader"); 74 throw new SOAPException("Cannot pass NULL to addNotUnderstoodHeaderElement"); 75 } 76 if ("".equals(sourceName.getNamespaceURI())) { 77 log.severe("SAAJ0417.ver1_2.qname.not.ns.qualified"); 78 throw new SOAPException("The qname passed to addNotUnderstoodHeaderElement must be namespace-qualified"); 79 } 80 String prefix = sourceName.getPrefix(); 81 if ("".equals(prefix)) { 82 prefix = "ns1"; 83 } 84 Name notunderstoodName = getNotUnderstoodName(); 85 SOAPHeaderElement notunderstoodHeaderElement = 86 (SOAPHeaderElement) addChildElement(notunderstoodName); 87 notunderstoodHeaderElement.addAttribute( 88 NameImpl.createFromUnqualifiedName("qname"), 89 getQualifiedName( 90 new QName( 91 sourceName.getNamespaceURI(), 92 sourceName.getLocalPart(), 93 prefix))); 94 notunderstoodHeaderElement.addNamespaceDeclaration( 95 prefix, 96 sourceName.getNamespaceURI()); 97 return notunderstoodHeaderElement; 98 } 99 100 public SOAPElement addTextNode(String text) throws SOAPException { 101 log.log( 102 Level.SEVERE, 103 "SAAJ0416.ver1_2.adding.text.not.legal", 104 getElementQName()); 105 throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Header is not legal"); 106 } 107 108 protected SOAPHeaderElement createHeaderElement(Name name) 109 throws SOAPException { 110 String uri = name.getURI(); 111 if (uri == null || uri.equals("")) { 112 log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified"); 113 throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified"); 114 } 115 return new HeaderElement1_2Impl( 116 ((SOAPDocument) getOwnerDocument()).getDocument(), 117 name); 118 } 119 120 protected SOAPHeaderElement createHeaderElement(QName name) 121 throws SOAPException { 122 String uri = name.getNamespaceURI(); 123 if (uri == null || uri.equals("")) { 124 log.severe("SAAJ0413.ver1_2.header.elems.must.be.ns.qualified"); 125 throw new SOAPExceptionImpl("SOAP 1.2 header elements must be namespace qualified"); 126 } 127 return new HeaderElement1_2Impl( 128 ((SOAPDocument) getOwnerDocument()).getDocument(), 129 name); 130 } 131 132 public void setEncodingStyle(String encodingStyle) throws SOAPException { 133 log.severe("SAAJ0409.ver1_2.no.encodingstyle.in.header"); 134 throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Header"); 135 } 136 137 public SOAPElement addAttribute(Name name, String value) 138 throws SOAPException { 139 if (name.getLocalName().equals("encodingStyle") 140 && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) { 141 142 setEncodingStyle(value); 143 } 144 return super.addAttribute(name, value); 145 } 146 147 public SOAPElement addAttribute(QName name, String value) 148 throws SOAPException { 149 if (name.getLocalPart().equals("encodingStyle") 150 && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) { 151 152 setEncodingStyle(value); 153 } 154 return super.addAttribute(name, value); 155 } 156 }