Multi-line svn commit, see body.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / impl / SOAPImpl.cpp
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * SOAPImpl.cpp
19  * 
20  * Implementation classes for SOAP schema
21  */
22
23 #include "internal.h"
24 #include "AbstractAttributeExtensibleXMLObject.h"
25 #include "AbstractSimpleElement.h"
26 #include "AbstractElementProxy.h"
27 #include "exceptions.h"
28 #include "io/AbstractXMLObjectMarshaller.h"
29 #include "io/AbstractXMLObjectUnmarshaller.h"
30 #include "soap/SOAP.h"
31 #include "util/XMLHelper.h"
32
33 #include <xercesc/util/XMLUniDefs.hpp>
34
35 using namespace soap11;
36 using namespace xmltooling;
37 using namespace std;
38
39 #if defined (_MSC_VER)
40     #pragma warning( push )
41     #pragma warning( disable : 4250 4251 )
42 #endif
43
44 namespace {
45
46     DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,Faultstring);
47     DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,Faultactor);
48
49     class XMLTOOL_DLLLOCAL FaultcodeImpl : public virtual Faultcode,
50         public AbstractSimpleElement,
51         public AbstractDOMCachingXMLObject,
52         public AbstractXMLObjectMarshaller,
53         public AbstractXMLObjectUnmarshaller
54     {
55         QName* m_qname;
56     public:
57         virtual ~FaultcodeImpl() {
58             delete m_qname;
59         }
60
61         FaultcodeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
62             : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_qname(NULL) {
63         }
64             
65         FaultcodeImpl(const FaultcodeImpl& src)
66                 : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src), m_qname(NULL) {
67             setCode(src.getCode());
68         }
69         
70         QName* getCode() const {
71             return m_qname;
72         }
73         
74         void setCode(const QName* qname) {
75             m_qname=prepareForAssignment(m_qname,qname);
76             if (m_qname) {
77                 auto_ptr_XMLCh temp(m_qname->toString().c_str());
78                 setTextContent(temp.get());
79             }
80             else
81                 setTextContent(NULL);
82         }
83         
84         IMPL_XMLOBJECT_CLONE(Faultcode);
85     };
86
87     class XMLTOOL_DLLLOCAL DetailImpl : public virtual Detail,
88         public AbstractElementProxy,
89         public AbstractAttributeExtensibleXMLObject,
90         public AbstractDOMCachingXMLObject,
91         public AbstractXMLObjectMarshaller,
92         public AbstractXMLObjectUnmarshaller
93     {
94     public:
95         virtual ~DetailImpl() {}
96
97         DetailImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
98             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
99         }
100             
101         DetailImpl(const DetailImpl& src)
102                 : AbstractXMLObject(src),
103                     AbstractElementProxy(src),
104                     AbstractAttributeExtensibleXMLObject(src),
105                     AbstractDOMCachingXMLObject(src) {
106             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
107                 if (*i) {
108                     getXMLObjects().push_back((*i)->clone());
109                 }
110             }
111         }
112         
113         IMPL_XMLOBJECT_CLONE(Detail);
114
115     protected:
116         void marshallAttributes(DOMElement* domElement) const {
117             marshallExtensionAttributes(domElement);
118         }
119
120         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
121             getXMLObjects().push_back(childXMLObject);
122         }
123
124         void processAttribute(const DOMAttr* attribute) {
125             unmarshallExtensionAttribute(attribute);
126         }
127     };
128
129     class XMLTOOL_DLLLOCAL FaultImpl : public virtual Fault,
130         public AbstractComplexElement,
131         public AbstractDOMCachingXMLObject,
132         public AbstractXMLObjectMarshaller,
133         public AbstractXMLObjectUnmarshaller
134     {
135         void init() {
136             m_Faultcode=NULL;
137             m_Faultstring=NULL;
138             m_Faultactor=NULL;
139             m_Detail=NULL;
140             m_children.push_back(NULL);
141             m_children.push_back(NULL);
142             m_children.push_back(NULL);
143             m_children.push_back(NULL);
144             m_pos_Faultcode=m_children.begin();
145             m_pos_Faultstring=m_pos_Faultcode;
146             ++m_pos_Faultstring;
147             m_pos_Faultactor=m_pos_Faultstring;
148             ++m_pos_Faultactor;
149             m_pos_Detail=m_pos_Faultactor;
150             ++m_pos_Detail;
151         }
152     protected:
153         FaultImpl() {
154             init();
155         }
156         
157     public:
158         virtual ~FaultImpl() {}
159
160         FaultImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
161                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
162             init();
163         }
164             
165         FaultImpl(const FaultImpl& src)
166                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
167             init();
168             if (src.getFaultcode())
169                 setFaultcode(src.getFaultcode()->cloneFaultcode());
170             if (src.getFaultstring())
171                 setFaultstring(src.getFaultstring()->cloneFaultstring());
172             if (src.getFaultactor())
173                 setFaultactor(src.getFaultactor()->cloneFaultactor());
174             if (src.getDetail())
175                 setDetail(src.getDetail()->cloneDetail());
176         }
177         
178         IMPL_XMLOBJECT_CLONE(Fault);
179         IMPL_TYPED_CHILD(Faultcode);
180         IMPL_TYPED_CHILD(Faultstring);
181         IMPL_TYPED_CHILD(Faultactor);
182         IMPL_TYPED_CHILD(Detail);
183
184     protected:
185         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
186             PROC_TYPED_CHILD(Faultcode,XMLConstants::SOAP11ENV_NS,false);
187             PROC_TYPED_CHILD(Faultstring,XMLConstants::SOAP11ENV_NS,false);
188             PROC_TYPED_CHILD(Faultactor,XMLConstants::SOAP11ENV_NS,false);
189             PROC_TYPED_CHILD(Detail,XMLConstants::SOAP11ENV_NS,false);
190             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
191         }
192     };
193
194     class XMLTOOL_DLLLOCAL BodyImpl : public virtual Body,
195         public AbstractElementProxy,
196         public AbstractAttributeExtensibleXMLObject,
197         public AbstractDOMCachingXMLObject,
198         public AbstractXMLObjectMarshaller,
199         public AbstractXMLObjectUnmarshaller
200     {
201         void init() {
202             m_EncodingStyle=NULL;
203         }
204     public:
205         virtual ~BodyImpl() {
206             XMLString::release(&m_EncodingStyle);
207         }
208
209         BodyImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
210             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
211             init();
212         }
213             
214         BodyImpl(const BodyImpl& src)
215                 : AbstractXMLObject(src),
216                     AbstractElementProxy(src),
217                     AbstractAttributeExtensibleXMLObject(src),
218                     AbstractDOMCachingXMLObject(src) {
219             init();
220             setEncodingStyle(src.getEncodingStyle());
221             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
222                 if (*i) {
223                     getXMLObjects().push_back((*i)->clone());
224                 }
225             }
226         }
227         
228         IMPL_XMLOBJECT_CLONE(Body);
229         IMPL_STRING_ATTRIB(EncodingStyle);
230
231         void setAttribute(QName& qualifiedName, const XMLCh* value) {
232             if (qualifiedName.hasNamespaceURI() && XMLString::equals(qualifiedName.getNamespaceURI(),XMLConstants::SOAP11ENV_NS)) {
233                 if (XMLString::equals(qualifiedName.getLocalPart(),ENCODINGSTYLE_ATTRIB_NAME)) {
234                     setEncodingStyle(value);
235                     return;
236                 }
237             }
238             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value);
239         }
240
241     protected:
242         void marshallAttributes(DOMElement* domElement) const {
243             MARSHALL_STRING_ATTRIB(EncodingStyle,ENCODINGSTYLE,XMLConstants::SOAP11ENV_NS);
244             marshallExtensionAttributes(domElement);
245         }
246
247         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
248             getXMLObjects().push_back(childXMLObject);
249         }
250
251         void processAttribute(const DOMAttr* attribute) {
252             unmarshallExtensionAttribute(attribute);
253         }
254     };
255
256     class XMLTOOL_DLLLOCAL HeaderImpl : public virtual Header,
257         public AbstractElementProxy,
258         public AbstractAttributeExtensibleXMLObject,
259         public AbstractDOMCachingXMLObject,
260         public AbstractXMLObjectMarshaller,
261         public AbstractXMLObjectUnmarshaller
262     {
263         void init() {
264             m_Actor=NULL;
265             m_MustUnderstand=XMLConstants::XML_BOOL_NULL;
266         }
267     public:
268         virtual ~HeaderImpl() {
269             XMLString::release(&m_Actor);
270         }
271
272         HeaderImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
273             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
274             init();
275         }
276             
277         HeaderImpl(const HeaderImpl& src)
278                 : AbstractXMLObject(src),
279                     AbstractElementProxy(src),
280                     AbstractAttributeExtensibleXMLObject(src),
281                     AbstractDOMCachingXMLObject(src) {
282             init();
283             setActor(src.getActor());
284             MustUnderstand(m_MustUnderstand);
285             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
286                 if (*i) {
287                     getXMLObjects().push_back((*i)->clone());
288                 }
289             }
290         }
291         
292         IMPL_XMLOBJECT_CLONE(Header);
293         IMPL_STRING_ATTRIB(Actor);
294         IMPL_BOOLEAN_ATTRIB(MustUnderstand);
295
296         void setAttribute(QName& qualifiedName, const XMLCh* value) {
297             if (qualifiedName.hasNamespaceURI() && XMLString::equals(qualifiedName.getNamespaceURI(),XMLConstants::SOAP11ENV_NS)) {
298                 if (XMLString::equals(qualifiedName.getLocalPart(),MUSTUNDERSTAND_ATTRIB_NAME)) {
299                     setMustUnderstand(value);
300                     return;
301                 }
302                 else if (XMLString::equals(qualifiedName.getLocalPart(),ACTOR_ATTRIB_NAME)) {
303                     setActor(value);
304                     return;
305                 }
306             }
307             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value);
308         }
309
310     protected:
311         void marshallAttributes(DOMElement* domElement) const {
312             MARSHALL_STRING_ATTRIB(Actor,ACTOR,XMLConstants::SOAP11ENV_NS);
313             MARSHALL_BOOLEAN_ATTRIB(MustUnderstand,MUSTUNDERSTAND,XMLConstants::SOAP11ENV_NS);
314             marshallExtensionAttributes(domElement);
315         }
316
317         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
318             getXMLObjects().push_back(childXMLObject);
319         }
320
321         void processAttribute(const DOMAttr* attribute) {
322             unmarshallExtensionAttribute(attribute);
323         }
324     };
325
326     class XMLTOOL_DLLLOCAL EnvelopeImpl : public virtual Envelope,
327         public AbstractAttributeExtensibleXMLObject,
328         public AbstractComplexElement,
329         public AbstractDOMCachingXMLObject,
330         public AbstractXMLObjectMarshaller,
331         public AbstractXMLObjectUnmarshaller
332     {
333         void init() {
334             m_Header=NULL;
335             m_Body=NULL;
336             m_children.push_back(NULL);
337             m_children.push_back(NULL);
338             m_pos_Header=m_children.begin();
339             m_pos_Body=m_pos_Header;
340             ++m_pos_Body;
341         }
342     public:
343         virtual ~EnvelopeImpl() {}
344
345         EnvelopeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
346             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
347             init();
348         }
349             
350         EnvelopeImpl(const EnvelopeImpl& src)
351                 : AbstractXMLObject(src), AbstractComplexElement(src),
352                     AbstractAttributeExtensibleXMLObject(src), AbstractDOMCachingXMLObject(src) {
353             init();
354             if (src.getHeader())
355                 setHeader(src.getHeader()->cloneHeader());
356             if (src.getBody())
357                 setBody(src.getBody()->cloneBody());
358         }
359         
360         IMPL_TYPED_CHILD(Header);
361         IMPL_TYPED_CHILD(Body);
362         IMPL_XMLOBJECT_CLONE(Envelope);
363
364     protected:
365         void marshallAttributes(DOMElement* domElement) const {
366             marshallExtensionAttributes(domElement);
367         }
368
369         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
370             PROC_TYPED_CHILD(Header,XMLConstants::SOAP11ENV_NS,false);
371             PROC_TYPED_CHILD(Body,XMLConstants::SOAP11ENV_NS,false);
372             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
373         }
374
375         void processAttribute(const DOMAttr* attribute) {
376             unmarshallExtensionAttribute(attribute);
377         }
378     };
379 };
380
381 #if defined (_MSC_VER)
382     #pragma warning( pop )
383 #endif
384
385 // Builder Implementations
386
387 IMPL_XMLOBJECTBUILDER(Body);
388 IMPL_XMLOBJECTBUILDER(Detail);
389 IMPL_XMLOBJECTBUILDER(Envelope);
390 IMPL_XMLOBJECTBUILDER(Fault);
391 IMPL_XMLOBJECTBUILDER(Faultactor);
392 IMPL_XMLOBJECTBUILDER(Faultcode);
393 IMPL_XMLOBJECTBUILDER(Faultstring);
394 IMPL_XMLOBJECTBUILDER(Header);
395
396 // Unicode literals
397
398 const XMLCh Body::LOCAL_NAME[] =                        UNICODE_LITERAL_4(B,o,d,y);
399 const XMLCh Body::TYPE_NAME[] =                         UNICODE_LITERAL_4(B,o,d,y);
400 const XMLCh Body::ENCODINGSTYLE_ATTRIB_NAME[] =         UNICODE_LITERAL_13(e,n,c,o,d,i,n,g,S,t,y,l,e);
401 const XMLCh Detail::LOCAL_NAME[] =                      UNICODE_LITERAL_6(d,e,t,a,i,l);
402 const XMLCh Detail::TYPE_NAME[] =                       UNICODE_LITERAL_6(d,e,t,a,i,l);
403 const XMLCh Envelope::LOCAL_NAME[] =                    UNICODE_LITERAL_8(E,n,v,e,l,o,p,e);
404 const XMLCh Envelope::TYPE_NAME[] =                     UNICODE_LITERAL_8(E,n,v,e,l,o,p,e);
405 const XMLCh Fault::LOCAL_NAME[] =                       UNICODE_LITERAL_5(F,a,u,l,t);
406 const XMLCh Fault::TYPE_NAME[] =                        UNICODE_LITERAL_5(F,a,u,l,t);
407 const XMLCh Faultactor::LOCAL_NAME[] =                  UNICODE_LITERAL_10(F,a,u,l,t,a,c,t,o,r);
408 const XMLCh Faultcode::LOCAL_NAME[] =                   UNICODE_LITERAL_9(F,a,u,l,t,c,o,d,e);
409 const XMLCh Faultstring::LOCAL_NAME[] =                 UNICODE_LITERAL_11(F,a,u,l,t,s,t,r,i,n,g);
410 const XMLCh Header::LOCAL_NAME[] =                      UNICODE_LITERAL_6(H,e,a,d,e,r);
411 const XMLCh Header::TYPE_NAME[] =                       UNICODE_LITERAL_6(H,e,a,d,e,r);
412 const XMLCh Header::ACTOR_ATTRIB_NAME[] =               UNICODE_LITERAL_5(a,c,t,o,r);
413 const XMLCh Header::MUSTUNDERSTAND_ATTRIB_NAME[] =      UNICODE_LITERAL_14(m,u,s,t,U,n,d,e,r,s,t,a,n,d);