001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * $Id: HeaderElementImpl.java,v 1.2 2007/07/16 16:41:23 ofung Exp $
022: * $Revision: 1.2 $
023: * $Date: 2007/07/16 16:41:23 $
024: */
025:
026: /*
027: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
028: *
029: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
030: *
031: * The contents of this file are subject to the terms of either the GNU
032: * General Public License Version 2 only ("GPL") or the Common Development
033: * and Distribution License("CDDL") (collectively, the "License"). You
034: * may not use this file except in compliance with the License. You can obtain
035: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
036: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
037: * language governing permissions and limitations under the License.
038: *
039: * When distributing the software, include this License Header Notice in each
040: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
041: * Sun designates this particular file as subject to the "Classpath" exception
042: * as provided by Sun in the GPL Version 2 section of the License file that
043: * accompanied this code. If applicable, add the following below the License
044: * Header, with the fields enclosed by brackets [] replaced by your own
045: * identifying information: "Portions Copyrighted [year]
046: * [name of copyright owner]"
047: *
048: * Contributor(s):
049: *
050: * If you wish your version of this file to be governed by only the CDDL or
051: * only the GPL Version 2, indicate your decision by adding "[Contributor]
052: * elects to include this software in this distribution under the [CDDL or GPL
053: * Version 2] license." If you don't indicate a single choice of license, a
054: * recipient has the option to distribute your version of this file under
055: * either the CDDL, the GPL Version 2 or to extend the choice of license to
056: * its licensees as provided above. However, if you add GPL Version 2 code
057: * and therefore, elected the GPL Version 2 license, then the option applies
058: * only if the new code is made subject to such option by the copyright
059: * holder.
060: */
061: package com.sun.xml.messaging.saaj.soap.impl;
062:
063: import javax.xml.namespace.QName;
064: import javax.xml.soap.*;
065:
066: import com.sun.xml.messaging.saaj.soap.SOAPDocumentImpl;
067: import com.sun.xml.messaging.saaj.soap.name.NameImpl;
068:
069: public abstract class HeaderElementImpl extends ElementImpl implements
070: SOAPHeaderElement {
071:
072: protected static Name RELAY_ATTRIBUTE_LOCAL_NAME = NameImpl
073: .createFromTagName("relay");
074: protected static Name MUST_UNDERSTAND_ATTRIBUTE_LOCAL_NAME = NameImpl
075: .createFromTagName("mustUnderstand");
076:
077: public HeaderElementImpl(SOAPDocumentImpl ownerDoc, Name qname) {
078: super (ownerDoc, qname);
079: }
080:
081: public HeaderElementImpl(SOAPDocumentImpl ownerDoc, QName qname) {
082: super (ownerDoc, qname);
083: }
084:
085: protected abstract NameImpl getActorAttributeName();
086:
087: protected abstract NameImpl getRoleAttributeName();
088:
089: protected abstract NameImpl getMustunderstandAttributeName();
090:
091: protected abstract boolean getMustunderstandAttributeValue(
092: String str);
093:
094: protected abstract String getMustunderstandLiteralValue(boolean mu);
095:
096: protected abstract NameImpl getRelayAttributeName();
097:
098: protected abstract boolean getRelayAttributeValue(String str);
099:
100: protected abstract String getRelayLiteralValue(boolean mu);
101:
102: protected abstract String getActorOrRole();
103:
104: public void setParentElement(SOAPElement element)
105: throws SOAPException {
106: if (!(element instanceof SOAPHeader)) {
107: log
108: .severe("SAAJ0130.impl.header.elem.parent.mustbe.header");
109: throw new SOAPException(
110: "Parent of a SOAPHeaderElement has to be a SOAPHeader");
111: }
112:
113: super .setParentElement(element);
114: }
115:
116: public void setActor(String actorUri) {
117: try {
118: removeAttribute(getActorAttributeName());
119: addAttribute((Name) getActorAttributeName(), actorUri);
120: } catch (SOAPException ex) {
121: }
122: }
123:
124: //SOAP 1.2 supports Role
125: public void setRole(String roleUri) throws SOAPException {
126: // runtime exception thrown if called for SOAP 1.1
127: removeAttribute(getRoleAttributeName());
128: addAttribute((Name) getRoleAttributeName(), roleUri);
129: }
130:
131: Name actorAttNameWithoutNS = NameImpl.createFromTagName("actor");
132:
133: public String getActor() {
134: String actor = getAttributeValue(getActorAttributeName());
135: return actor;
136: }
137:
138: Name roleAttNameWithoutNS = NameImpl.createFromTagName("role");
139:
140: public String getRole() {
141: // runtime exception thrown for 1.1
142: String role = getAttributeValue(getRoleAttributeName());
143: return role;
144: }
145:
146: public void setMustUnderstand(boolean mustUnderstand) {
147: try {
148: removeAttribute(getMustunderstandAttributeName());
149: addAttribute((Name) getMustunderstandAttributeName(),
150: getMustunderstandLiteralValue(mustUnderstand));
151: } catch (SOAPException ex) {
152: }
153: }
154:
155: public boolean getMustUnderstand() {
156: String mu = getAttributeValue(getMustunderstandAttributeName());
157:
158: if (mu != null)
159: return getMustunderstandAttributeValue(mu);
160:
161: return false;
162: }
163:
164: public void setRelay(boolean relay) throws SOAPException {
165: // runtime exception thrown for 1.1
166: removeAttribute(getRelayAttributeName());
167: addAttribute((Name) getRelayAttributeName(),
168: getRelayLiteralValue(relay));
169: }
170:
171: public boolean getRelay() {
172: String mu = getAttributeValue(getRelayAttributeName());
173: if (mu != null)
174: return getRelayAttributeValue(mu);
175:
176: return false;
177: }
178: }
|