1 /* 2 * Copyright (c) 1997, 2017, 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 package com.sun.xml.internal.messaging.saaj.soap.impl; 27 28 import javax.xml.namespace.QName; 29 import javax.xml.soap.*; 30 31 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; 32 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; 33 34 public abstract class HeaderElementImpl 35 extends ElementImpl 36 implements SOAPHeaderElement { 37 38 protected static Name RELAY_ATTRIBUTE_LOCAL_NAME = 39 NameImpl.createFromTagName("relay"); 40 protected static Name MUST_UNDERSTAND_ATTRIBUTE_LOCAL_NAME = 41 NameImpl.createFromTagName("mustUnderstand"); 42 43 public HeaderElementImpl(SOAPDocumentImpl ownerDoc, Name qname) { 44 super(ownerDoc, qname); 45 } 46 public HeaderElementImpl(SOAPDocumentImpl ownerDoc, QName qname) { 47 super(ownerDoc, qname); 48 } 49 50 protected abstract NameImpl getActorAttributeName(); 51 protected abstract NameImpl getRoleAttributeName(); 52 protected abstract NameImpl getMustunderstandAttributeName(); 53 protected abstract boolean getMustunderstandAttributeValue(String str); 54 protected abstract String getMustunderstandLiteralValue(boolean mu); 55 protected abstract NameImpl getRelayAttributeName(); 56 protected abstract boolean getRelayAttributeValue(String str); 57 protected abstract String getRelayLiteralValue(boolean mu); 58 protected abstract String getActorOrRole(); 59 60 61 @Override 62 public void setParentElement(SOAPElement element) throws SOAPException { 63 if (!(element instanceof SOAPHeader)) { 64 log.severe("SAAJ0130.impl.header.elem.parent.mustbe.header"); 65 throw new SOAPException("Parent of a SOAPHeaderElement has to be a SOAPHeader"); 66 } 67 68 super.setParentElement(element); 69 } 70 71 @Override 72 public void setActor(String actorUri) { 73 try { 74 removeAttribute(getActorAttributeName()); 75 addAttribute((Name) getActorAttributeName(), actorUri); 76 } catch (SOAPException ex) { 77 } 78 } 79 80 //SOAP 1.2 supports Role 81 @Override 82 public void setRole(String roleUri) throws SOAPException { 83 // runtime exception thrown if called for SOAP 1.1 84 removeAttribute(getRoleAttributeName()); 85 addAttribute((Name) getRoleAttributeName(), roleUri); 86 } 87 88 89 Name actorAttNameWithoutNS = NameImpl.createFromTagName("actor"); 90 91 @Override 92 public String getActor() { 93 String actor = getAttributeValue(getActorAttributeName()); 94 return actor; 95 } 96 97 Name roleAttNameWithoutNS = NameImpl.createFromTagName("role"); 98 99 @Override 100 public String getRole() { 101 // runtime exception thrown for 1.1 102 String role = getAttributeValue(getRoleAttributeName()); 103 return role; 104 } 105 106 @Override 107 public void setMustUnderstand(boolean mustUnderstand) { 108 try { 109 removeAttribute(getMustunderstandAttributeName()); 110 addAttribute( 111 (Name) getMustunderstandAttributeName(), 112 getMustunderstandLiteralValue(mustUnderstand)); 113 } catch (SOAPException ex) { 114 } 115 } 116 117 @Override 118 public boolean getMustUnderstand() { 119 String mu = getAttributeValue(getMustunderstandAttributeName()); 120 121 if (mu != null) 122 return getMustunderstandAttributeValue(mu); 123 124 return false; 125 } 126 127 @Override 128 public void setRelay(boolean relay) throws SOAPException { 129 // runtime exception thrown for 1.1 130 removeAttribute(getRelayAttributeName()); 131 addAttribute( 132 (Name) getRelayAttributeName(), 133 getRelayLiteralValue(relay)); 134 } 135 136 @Override 137 public boolean getRelay() { 138 String mu = getAttributeValue(getRelayAttributeName()); 139 if (mu != null) 140 return getRelayAttributeValue(mu); 141 142 return false; 143 } 144 }