001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Emil Ong
028: */
029:
030: package com.caucho.xml.saaj;
031:
032: import javax.xml.XMLConstants;
033: import javax.xml.namespace.*;
034: import javax.xml.soap.*;
035:
036: import com.caucho.xml.QNode;
037:
038: public class SOAP12HeaderElementImpl extends SOAP11HeaderElementImpl {
039: static final Name ENCODING_STYLE_NAME = new NameImpl(
040: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "encodingStyle",
041: SOAPConstants.SOAP_ENV_PREFIX);
042:
043: static final NameImpl NOT_UNDERSTOOD_NAME = new NameImpl(
044: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "NotUnderstood",
045: SOAPConstants.SOAP_ENV_PREFIX);
046:
047: static final NameImpl SOAP_1_2_UPGRADE_NAME = new NameImpl(
048: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "Upgrade",
049: SOAPConstants.SOAP_ENV_PREFIX);
050:
051: static final NameImpl SOAP_1_2_MUST_UNDERSTAND_NAME = new NameImpl(
052: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "mustUnderstand",
053: SOAPConstants.SOAP_ENV_PREFIX);
054:
055: static final NameImpl RELAY_NAME = new NameImpl(
056: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "relay",
057: SOAPConstants.SOAP_ENV_PREFIX);
058:
059: static final NameImpl ROLE_NAME = new NameImpl(
060: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "role",
061: SOAPConstants.SOAP_ENV_PREFIX);
062:
063: SOAP12HeaderElementImpl(SOAPFactory factory, NameImpl name)
064: throws SOAPException {
065: super (factory, name);
066:
067: _mustUnderstandName = SOAP_1_2_MUST_UNDERSTAND_NAME;
068: }
069:
070: SOAP12HeaderElementImpl(SOAPFactory factory, SOAPElement element)
071: throws SOAPException {
072: this (factory, NameImpl.fromQName(element.getElementQName()));
073:
074: copySOAPElement(element);
075: }
076:
077: // override encoding style so that the namespace is SOAP 1.2
078: public String getEncodingStyle() {
079: return getAttributeValue(ENCODING_STYLE_NAME);
080: }
081:
082: public void setEncodingStyle(String encodingStyle)
083: throws SOAPException {
084: if (!SOAPConstants.URI_NS_SOAP_ENCODING.equals(encodingStyle)
085: && !SOAPConstants.URI_NS_SOAP_1_2_ENCODING
086: .equals(encodingStyle))
087: throw new IllegalArgumentException(
088: "Unknown SOAP Encoding: " + encodingStyle);
089:
090: addAttribute(ENCODING_STYLE_NAME, encodingStyle);
091: }
092:
093: public String getActor() {
094: return getRole();
095: }
096:
097: public void setActor(String actorURI) {
098: try {
099: setRole(actorURI);
100: } catch (SOAPException e) {
101: // as specified by SAAJ
102: throw new IllegalArgumentException(e);
103: }
104: }
105:
106: public boolean getRelay() {
107: return "true"
108: .equalsIgnoreCase(getAttributeValue((Name) RELAY_NAME));
109: }
110:
111: public void setRelay(boolean relay) throws SOAPException {
112: addAttribute((Name) RELAY_NAME, Boolean.toString(relay));
113: }
114:
115: public String getRole() {
116: return getAttributeValue((Name) ROLE_NAME);
117: }
118:
119: public void setRole(String uri) throws SOAPException {
120: addAttribute((Name) ROLE_NAME, uri);
121: }
122:
123: public void setParentElement(SOAPElement parent)
124: throws SOAPException {
125: if (parent == null)
126: throw new IllegalArgumentException();
127:
128: if (parent instanceof SOAP12HeaderImpl)
129: _parent = (SOAP12HeaderImpl) parent;
130: else if (parent instanceof SOAP12HeaderElementImpl)
131: _parent = (SOAP12HeaderElementImpl) parent;
132: else
133: throw new SOAPException("Parent is a " + parent.getClass()
134: + ", not a SOAPHeader or SOAPHeaderElement");
135: }
136: }
|