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 java.util.*;
033:
034: import javax.xml.XMLConstants;
035: import javax.xml.namespace.*;
036: import javax.xml.soap.*;
037:
038: public class SOAP12HeaderImpl extends SOAP11HeaderImpl {
039: private static final Name ENCODING_STYLE_NAME = new NameImpl(
040: SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "encodingStyle",
041: SOAPConstants.SOAP_ENV_PREFIX);
042:
043: private static final NameImpl QNAME_NAME = new NameImpl("qname");
044:
045: SOAP12HeaderImpl(SOAPFactory factory, NameImpl name)
046: throws SOAPException {
047: super (factory, name);
048:
049: _supportedEnvelopeName = SOAP_1_2_SUPPORTED_ENVELOPE_NAME;
050: _upgradeName = SOAP12HeaderElementImpl.SOAP_1_2_UPGRADE_NAME;
051: }
052:
053: public SOAPElement addTextNode(String text) throws SOAPException {
054: if (text.indexOf('<') >= 0)
055: throw new SOAPException(
056: "Child tags not allowed in the Text nodes of SOAP 1.2 headers");
057:
058: appendChild(new TextImpl(_factory, text));
059:
060: return this ;
061: }
062:
063: public SOAPElement addAttribute(Name name, String value)
064: throws SOAPException {
065: if (name.equals(ENCODING_STYLE_NAME))
066: throw new SOAPException(
067: "encodingStyle illegal for this element");
068:
069: return super .addAttribute(name, value);
070: }
071:
072: public SOAPElement addAttribute(QName qname, String value)
073: throws SOAPException {
074: if (qname.equals(ENCODING_STYLE_NAME))
075: throw new SOAPException(
076: "encodingStyle illegal for this element");
077:
078: return super .addAttribute(qname, value);
079: }
080:
081: public String getEncodingStyle() {
082: // optimization
083: return null;
084: }
085:
086: public void setEncodingStyle(String encodingStyle)
087: throws SOAPException {
088: throw new SOAPException(
089: "encodingStyle illegal for this element");
090: }
091:
092: public SOAPElement addChildElement(SOAPElement element)
093: throws SOAPException {
094: SOAPElement child = element;
095:
096: if (!(element instanceof SOAPHeaderElement))
097: element = new SOAP12HeaderElementImpl(_factory, element);
098:
099: return super .addChildElement(element);
100: }
101:
102: public SOAPHeaderElement addHeaderElement(Name name)
103: throws SOAPException {
104: SOAPHeaderElement child = new SOAP12HeaderElementImpl(_factory,
105: NameImpl.fromName(name));
106:
107: appendChild(child);
108:
109: return child;
110: }
111:
112: public SOAPHeaderElement addNotUnderstoodHeaderElement(QName name)
113: throws SOAPException {
114: // NotUnderstood elements look like:
115: // <soapenv:NotUnderstood qname="abc:Extension" xmlns:abc="http://ns/"/>
116: //
117: SOAPHeaderElement element = createHeaderElement(SOAP12HeaderElementImpl.NOT_UNDERSTOOD_NAME);
118:
119: if (name.getPrefix() == null)
120: throw new SOAPException(
121: "No prefix given with NotUnderstood header");
122: else if (name.getNamespaceURI() == null)
123: throw new SOAPException(
124: "No namespace given with NotUnderstood header");
125:
126: element.addAttribute((Name) QNAME_NAME, name.getPrefix() + ':'
127: + name.getLocalPart());
128: element.addNamespaceDeclaration(name.getPrefix(), name
129: .getNamespaceURI());
130:
131: addChildElement(element);
132:
133: return element;
134: }
135:
136: protected SOAPHeaderElement createHeaderElement(NameImpl name)
137: throws SOAPException {
138: return new SOAP12HeaderElementImpl(_factory, name);
139: }
140: }
|