4ac87535c29530f832aa4f04b16645a2aa66ff31
[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 "AbstractChildlessElement.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         protected AbstractSimpleElement,
51         public AbstractChildlessElement,
52         public AbstractDOMCachingXMLObject,
53         public AbstractXMLObjectMarshaller,
54         public AbstractXMLObjectUnmarshaller
55     {
56         QName* m_qname;
57     public:
58         virtual ~FaultcodeImpl() {
59             delete m_qname;
60         }
61
62         FaultcodeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
63             : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_qname(NULL) {
64         }
65             
66         FaultcodeImpl(const FaultcodeImpl& src)
67                 : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src), m_qname(NULL) {
68             setCode(src.getCode());
69         }
70         
71         QName* getCode() const {
72             return m_qname;
73         }
74         
75         void setCode(const QName* qname) {
76             m_qname=prepareForAssignment(m_qname,qname);
77             if (m_qname) {
78                 auto_ptr_XMLCh temp(m_qname->toString().c_str());
79                 setTextContent(temp.get());
80             }
81             else
82                 setTextContent(NULL);
83         }
84         
85         IMPL_XMLOBJECT_CLONE(Faultcode);
86         IMPL_XMLOBJECT_CONTENT;
87     };
88
89     class XMLTOOL_DLLLOCAL DetailImpl : public virtual Detail,
90         public AbstractElementProxy,
91         public AbstractAttributeExtensibleXMLObject,
92         public AbstractDOMCachingXMLObject,
93         public AbstractXMLObjectMarshaller,
94         public AbstractXMLObjectUnmarshaller
95     {
96     public:
97         virtual ~DetailImpl() {}
98
99         DetailImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
100             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
101         }
102             
103         DetailImpl(const DetailImpl& src)
104                 : AbstractXMLObject(src),
105                     AbstractElementProxy(src),
106                     AbstractAttributeExtensibleXMLObject(src),
107                     AbstractDOMCachingXMLObject(src) {
108             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
109                 if (*i) {
110                     getXMLObjects().push_back((*i)->clone());
111                 }
112             }
113         }
114         
115         IMPL_XMLOBJECT_CLONE(Detail);
116
117     protected:
118         void marshallAttributes(DOMElement* domElement) const {
119             marshallExtensionAttributes(domElement);
120         }
121
122         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
123             getXMLObjects().push_back(childXMLObject);
124         }
125
126         void processAttribute(const DOMAttr* attribute) {
127             unmarshallExtensionAttribute(attribute);
128         }
129     };
130
131     class XMLTOOL_DLLLOCAL FaultImpl : public virtual Fault,
132         public AbstractComplexElement,
133         public AbstractDOMCachingXMLObject,
134         public AbstractXMLObjectMarshaller,
135         public AbstractXMLObjectUnmarshaller
136     {
137         void init() {
138             m_Faultcode=NULL;
139             m_Faultstring=NULL;
140             m_Faultactor=NULL;
141             m_Detail=NULL;
142             m_children.push_back(NULL);
143             m_children.push_back(NULL);
144             m_children.push_back(NULL);
145             m_children.push_back(NULL);
146             m_pos_Faultcode=m_children.begin();
147             m_pos_Faultstring=m_pos_Faultcode;
148             ++m_pos_Faultstring;
149             m_pos_Faultactor=m_pos_Faultstring;
150             ++m_pos_Faultactor;
151             m_pos_Detail=m_pos_Faultactor;
152             ++m_pos_Detail;
153         }
154     protected:
155         FaultImpl() {
156             init();
157         }
158         
159     public:
160         virtual ~FaultImpl() {}
161
162         FaultImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
163                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
164             init();
165         }
166             
167         FaultImpl(const FaultImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
168             init();
169             if (src.getFaultcode())
170                 setFaultcode(src.getFaultcode()->cloneFaultcode());
171             if (src.getFaultstring())
172                 setFaultstring(src.getFaultstring()->cloneFaultstring());
173             if (src.getFaultactor())
174                 setFaultactor(src.getFaultactor()->cloneFaultactor());
175             if (src.getDetail())
176                 setDetail(src.getDetail()->cloneDetail());
177         }
178         
179         IMPL_XMLOBJECT_CLONE(Fault);
180         IMPL_TYPED_CHILD(Faultcode);
181         IMPL_TYPED_CHILD(Faultstring);
182         IMPL_TYPED_CHILD(Faultactor);
183         IMPL_TYPED_CHILD(Detail);
184
185     protected:
186         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
187             PROC_TYPED_CHILD(Faultcode,XMLConstants::SOAP11ENV_NS,false);
188             PROC_TYPED_CHILD(Faultstring,XMLConstants::SOAP11ENV_NS,false);
189             PROC_TYPED_CHILD(Faultactor,XMLConstants::SOAP11ENV_NS,false);
190             PROC_TYPED_CHILD(Detail,XMLConstants::SOAP11ENV_NS,false);
191             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
192         }
193     };
194
195     class XMLTOOL_DLLLOCAL BodyImpl : public virtual Body,
196         public AbstractElementProxy,
197         public AbstractAttributeExtensibleXMLObject,
198         public AbstractDOMCachingXMLObject,
199         public AbstractXMLObjectMarshaller,
200         public AbstractXMLObjectUnmarshaller
201     {
202         void init() {
203             m_EncodingStyle=NULL;
204         }
205     public:
206         virtual ~BodyImpl() {
207             XMLString::release(&m_EncodingStyle);
208         }
209
210         BodyImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
211             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
212             init();
213         }
214             
215         BodyImpl(const BodyImpl& src)
216                 : AbstractXMLObject(src),
217                     AbstractElementProxy(src),
218                     AbstractAttributeExtensibleXMLObject(src),
219                     AbstractDOMCachingXMLObject(src) {
220             init();
221             setEncodingStyle(src.getEncodingStyle());
222             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
223                 if (*i) {
224                     getXMLObjects().push_back((*i)->clone());
225                 }
226             }
227         }
228         
229         IMPL_XMLOBJECT_CLONE(Body);
230         IMPL_STRING_ATTRIB(EncodingStyle);
231
232         void setAttribute(QName& qualifiedName, const XMLCh* value) {
233             if (qualifiedName.hasNamespaceURI() && XMLString::equals(qualifiedName.getNamespaceURI(),XMLConstants::SOAP11ENV_NS)) {
234                 if (XMLString::equals(qualifiedName.getLocalPart(),ENCODINGSTYLE_ATTRIB_NAME)) {
235                     setEncodingStyle(value);
236                     return;
237                 }
238             }
239             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value);
240         }
241
242     protected:
243         void marshallAttributes(DOMElement* domElement) const {
244             MARSHALL_STRING_ATTRIB(EncodingStyle,ENCODINGSTYLE,XMLConstants::SOAP11ENV_NS);
245             marshallExtensionAttributes(domElement);
246         }
247
248         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
249             getXMLObjects().push_back(childXMLObject);
250         }
251
252         void processAttribute(const DOMAttr* attribute) {
253             unmarshallExtensionAttribute(attribute);
254         }
255     };
256
257     class XMLTOOL_DLLLOCAL HeaderImpl : public virtual Header,
258         public AbstractElementProxy,
259         public AbstractAttributeExtensibleXMLObject,
260         public AbstractDOMCachingXMLObject,
261         public AbstractXMLObjectMarshaller,
262         public AbstractXMLObjectUnmarshaller
263     {
264         void init() {
265             m_Actor=NULL;
266             m_MustUnderstand=XMLConstants::XML_BOOL_NULL;
267         }
268     public:
269         virtual ~HeaderImpl() {
270             XMLString::release(&m_Actor);
271         }
272
273         HeaderImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
274             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
275             init();
276         }
277             
278         HeaderImpl(const HeaderImpl& src)
279                 : AbstractXMLObject(src),
280                     AbstractElementProxy(src),
281                     AbstractAttributeExtensibleXMLObject(src),
282                     AbstractDOMCachingXMLObject(src) {
283             init();
284             setActor(src.getActor());
285             MustUnderstand(m_MustUnderstand);
286             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
287                 if (*i) {
288                     getXMLObjects().push_back((*i)->clone());
289                 }
290             }
291         }
292         
293         IMPL_XMLOBJECT_CLONE(Header);
294         IMPL_STRING_ATTRIB(Actor);
295         IMPL_BOOLEAN_ATTRIB(MustUnderstand);
296
297         void setAttribute(QName& qualifiedName, const XMLCh* value) {
298             if (qualifiedName.hasNamespaceURI() && XMLString::equals(qualifiedName.getNamespaceURI(),XMLConstants::SOAP11ENV_NS)) {
299                 if (XMLString::equals(qualifiedName.getLocalPart(),MUSTUNDERSTAND_ATTRIB_NAME)) {
300                     setMustUnderstand(value);
301                     return;
302                 }
303                 else if (XMLString::equals(qualifiedName.getLocalPart(),ACTOR_ATTRIB_NAME)) {
304                     setActor(value);
305                     return;
306                 }
307             }
308             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value);
309         }
310
311     protected:
312         void marshallAttributes(DOMElement* domElement) const {
313             MARSHALL_STRING_ATTRIB(Actor,ACTOR,XMLConstants::SOAP11ENV_NS);
314             MARSHALL_BOOLEAN_ATTRIB(MustUnderstand,MUSTUNDERSTAND,XMLConstants::SOAP11ENV_NS);
315             marshallExtensionAttributes(domElement);
316         }
317
318         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
319             getXMLObjects().push_back(childXMLObject);
320         }
321
322         void processAttribute(const DOMAttr* attribute) {
323             unmarshallExtensionAttribute(attribute);
324         }
325     };
326
327     class XMLTOOL_DLLLOCAL EnvelopeImpl : public virtual Envelope,
328         public AbstractAttributeExtensibleXMLObject,
329         public AbstractComplexElement,
330         public AbstractDOMCachingXMLObject,
331         public AbstractXMLObjectMarshaller,
332         public AbstractXMLObjectUnmarshaller
333     {
334         void init() {
335             m_Header=NULL;
336             m_Body=NULL;
337             m_children.push_back(NULL);
338             m_children.push_back(NULL);
339             m_pos_Header=m_children.begin();
340             m_pos_Body=m_pos_Header;
341             ++m_pos_Body;
342         }
343     public:
344         virtual ~EnvelopeImpl() {}
345
346         EnvelopeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
347             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
348             init();
349         }
350             
351         EnvelopeImpl(const EnvelopeImpl& src)
352                 : AbstractXMLObject(src), 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);