001: /*
002: * $Id: HeaderElementImpl.java,v 1.26 2006/01/27 12:49:35 vj135062 Exp $
003: * $Revision: 1.26 $
004: * $Date: 2006/01/27 12:49:35 $
005: */
006:
007: /*
008: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
009: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
010: *
011: * This code is free software; you can redistribute it and/or modify it
012: * under the terms of the GNU General Public License version 2 only, as
013: * published by the Free Software Foundation. Sun designates this
014: * particular file as subject to the "Classpath" exception as provided
015: * by Sun in the LICENSE file that accompanied this code.
016: *
017: * This code is distributed in the hope that it will be useful, but WITHOUT
018: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
019: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
020: * version 2 for more details (a copy is included in the LICENSE file that
021: * accompanied this code).
022: *
023: * You should have received a copy of the GNU General Public License version
024: * 2 along with this work; if not, write to the Free Software Foundation,
025: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
026: *
027: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
028: * CA 95054 USA or visit www.sun.com if you need additional information or
029: * have any questions.
030: */
031: package com.sun.xml.internal.messaging.saaj.soap.impl;
032:
033: import javax.xml.namespace.QName;
034: import javax.xml.soap.*;
035:
036: import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
037: import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
038:
039: public abstract class HeaderElementImpl extends ElementImpl implements
040: SOAPHeaderElement {
041:
042: protected static Name RELAY_ATTRIBUTE_LOCAL_NAME = NameImpl
043: .createFromTagName("relay");
044: protected static Name MUST_UNDERSTAND_ATTRIBUTE_LOCAL_NAME = NameImpl
045: .createFromTagName("mustUnderstand");
046:
047: public HeaderElementImpl(SOAPDocumentImpl ownerDoc, Name qname) {
048: super (ownerDoc, qname);
049: }
050:
051: public HeaderElementImpl(SOAPDocumentImpl ownerDoc, QName qname) {
052: super (ownerDoc, qname);
053: }
054:
055: protected abstract NameImpl getActorAttributeName();
056:
057: protected abstract NameImpl getRoleAttributeName();
058:
059: protected abstract NameImpl getMustunderstandAttributeName();
060:
061: protected abstract boolean getMustunderstandAttributeValue(
062: String str);
063:
064: protected abstract String getMustunderstandLiteralValue(boolean mu);
065:
066: protected abstract NameImpl getRelayAttributeName();
067:
068: protected abstract boolean getRelayAttributeValue(String str);
069:
070: protected abstract String getRelayLiteralValue(boolean mu);
071:
072: protected abstract String getActorOrRole();
073:
074: public void setParentElement(SOAPElement element)
075: throws SOAPException {
076: if (!(element instanceof SOAPHeader)) {
077: log
078: .severe("SAAJ0130.impl.header.elem.parent.mustbe.header");
079: throw new SOAPException(
080: "Parent of a SOAPHeaderElement has to be a SOAPHeader");
081: }
082:
083: super .setParentElement(element);
084: }
085:
086: public void setActor(String actorUri) {
087: try {
088: removeAttribute(getActorAttributeName());
089: addAttribute((Name) getActorAttributeName(), actorUri);
090: } catch (SOAPException ex) {
091: }
092: }
093:
094: //SOAP 1.2 supports Role
095: public void setRole(String roleUri) throws SOAPException {
096: // runtime exception thrown if called for SOAP 1.1
097: removeAttribute(getRoleAttributeName());
098: addAttribute((Name) getRoleAttributeName(), roleUri);
099: }
100:
101: Name actorAttNameWithoutNS = NameImpl.createFromTagName("actor");
102:
103: public String getActor() {
104: String actor = getAttributeValue(getActorAttributeName());
105: return actor;
106: }
107:
108: Name roleAttNameWithoutNS = NameImpl.createFromTagName("role");
109:
110: public String getRole() {
111: // runtime exception thrown for 1.1
112: String role = getAttributeValue(getRoleAttributeName());
113: return role;
114: }
115:
116: public void setMustUnderstand(boolean mustUnderstand) {
117: try {
118: removeAttribute(getMustunderstandAttributeName());
119: addAttribute((Name) getMustunderstandAttributeName(),
120: getMustunderstandLiteralValue(mustUnderstand));
121: } catch (SOAPException ex) {
122: }
123: }
124:
125: public boolean getMustUnderstand() {
126: String mu = getAttributeValue(getMustunderstandAttributeName());
127:
128: if (mu != null)
129: return getMustunderstandAttributeValue(mu);
130:
131: return false;
132: }
133:
134: public void setRelay(boolean relay) throws SOAPException {
135: // runtime exception thrown for 1.1
136: removeAttribute(getRelayAttributeName());
137: addAttribute((Name) getRelayAttributeName(),
138: getRelayLiteralValue(relay));
139: }
140:
141: public boolean getRelay() {
142: String mu = getAttributeValue(getRelayAttributeName());
143: if (mu != null)
144: return getRelayAttributeValue(mu);
145:
146: return false;
147: }
148: }
|