|
1 /* |
|
2 * $Id: Envelope1_2Impl.java,v 1.26 2006/01/27 12:49:47 vj135062 Exp $ |
|
3 */ |
|
4 |
|
5 /* |
|
6 * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved. |
|
7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
8 * |
|
9 * This code is free software; you can redistribute it and/or modify it |
|
10 * under the terms of the GNU General Public License version 2 only, as |
|
11 * published by the Free Software Foundation. Sun designates this |
|
12 * particular file as subject to the "Classpath" exception as provided |
|
13 * by Sun in the LICENSE file that accompanied this code. |
|
14 * |
|
15 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
18 * version 2 for more details (a copy is included in the LICENSE file that |
|
19 * accompanied this code). |
|
20 * |
|
21 * You should have received a copy of the GNU General Public License version |
|
22 * 2 along with this work; if not, write to the Free Software Foundation, |
|
23 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
24 * |
|
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
26 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
27 * have any questions. |
|
28 */ |
|
29 |
|
30 /** |
|
31 * |
|
32 * @author SAAJ RI Development Team |
|
33 */ |
|
34 package com.sun.xml.internal.messaging.saaj.soap.ver1_2; |
|
35 |
|
36 import java.util.logging.Logger; |
|
37 import java.util.logging.Level; |
|
38 |
|
39 import javax.xml.namespace.QName; |
|
40 import javax.xml.soap.*; |
|
41 |
|
42 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; |
|
43 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl; |
|
44 import com.sun.xml.internal.messaging.saaj.soap.impl.EnvelopeImpl; |
|
45 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl; |
|
46 |
|
47 public class Envelope1_2Impl extends EnvelopeImpl { |
|
48 |
|
49 protected static Logger log = |
|
50 Logger.getLogger(Envelope1_2Impl.class.getName(), |
|
51 "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings"); |
|
52 |
|
53 public Envelope1_2Impl(SOAPDocumentImpl ownerDoc, String prefix) { |
|
54 super(ownerDoc, NameImpl.createEnvelope1_2Name(prefix)); |
|
55 } |
|
56 |
|
57 public Envelope1_2Impl( |
|
58 SOAPDocumentImpl ownerDoc, |
|
59 String prefix, |
|
60 boolean createHeader, |
|
61 boolean createBody) |
|
62 throws SOAPException { |
|
63 super( |
|
64 ownerDoc, |
|
65 NameImpl.createEnvelope1_2Name(prefix), |
|
66 createHeader, |
|
67 createBody); |
|
68 } |
|
69 |
|
70 protected NameImpl getBodyName(String prefix) { |
|
71 return NameImpl.createBody1_2Name(prefix); |
|
72 } |
|
73 |
|
74 protected NameImpl getHeaderName(String prefix) { |
|
75 return NameImpl.createHeader1_2Name(prefix); |
|
76 } |
|
77 |
|
78 /* |
|
79 * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle |
|
80 * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1) |
|
81 */ |
|
82 public void setEncodingStyle(String encodingStyle) throws SOAPException { |
|
83 log.severe("SAAJ0404.ver1_2.no.encodingStyle.in.envelope"); |
|
84 throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Envelope"); |
|
85 } |
|
86 |
|
87 /* |
|
88 * Override addAttribute of ElementImpl to restrict adding encodingStyle |
|
89 * attribute to SOAP Envelope (SOAP 1.2 spec, part 1, section 5.1.1) |
|
90 */ |
|
91 public SOAPElement addAttribute(Name name, String value) |
|
92 throws SOAPException { |
|
93 if (name.getLocalName().equals("encodingStyle") |
|
94 && name.getURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) { |
|
95 setEncodingStyle(value); |
|
96 } |
|
97 return super.addAttribute(name, value); |
|
98 } |
|
99 |
|
100 public SOAPElement addAttribute(QName name, String value) |
|
101 throws SOAPException { |
|
102 if (name.getLocalPart().equals("encodingStyle") |
|
103 && name.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) { |
|
104 setEncodingStyle(value); |
|
105 } |
|
106 return super.addAttribute(name, value); |
|
107 } |
|
108 |
|
109 |
|
110 /* |
|
111 * Override addChildElement method to ensure that no element |
|
112 * is added after body in SOAP 1.2. |
|
113 */ |
|
114 public SOAPElement addChildElement(Name name) throws SOAPException { |
|
115 // check if body already exists |
|
116 if (getBody() != null) { |
|
117 log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope"); |
|
118 throw new SOAPExceptionImpl( |
|
119 "Body must be the last element in" + " SOAP Envelope"); |
|
120 } |
|
121 return super.addChildElement(name); |
|
122 } |
|
123 |
|
124 public SOAPElement addChildElement(QName name) throws SOAPException { |
|
125 // check if body already exists |
|
126 if (getBody() != null) { |
|
127 log.severe("SAAJ0405.ver1_2.body.must.last.in.envelope"); |
|
128 throw new SOAPExceptionImpl( |
|
129 "Body must be the last element in" + " SOAP Envelope"); |
|
130 } |
|
131 return super.addChildElement(name); |
|
132 } |
|
133 |
|
134 |
|
135 /* |
|
136 * Ideally we should be overriding other addChildElement() methods as well |
|
137 * but we are not adding them here since internally all those call the |
|
138 * method addChildElement(Name name). |
|
139 * In future, if this behaviour changes, then we would need to override |
|
140 * all the rest of them as well. |
|
141 * |
|
142 */ |
|
143 |
|
144 public SOAPElement addTextNode(String text) throws SOAPException { |
|
145 log.log( |
|
146 Level.SEVERE, |
|
147 "SAAJ0416.ver1_2.adding.text.not.legal", |
|
148 getElementQName()); |
|
149 throw new SOAPExceptionImpl("Adding text to SOAP 1.2 Envelope is not legal"); |
|
150 } |
|
151 } |