Additional macros and cleanup for cloning
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / impl / SOAPImpl.cpp
index c635f30..f6b5bd6 100644 (file)
@@ -1,23 +1,27 @@
-/*
- *  Copyright 2001-2008 Internet2
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
+ *
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
  * SOAPImpl.cpp
  * 
- * Implementation classes for SOAP 1.1 schema
+ * Implementation classes for SOAP 1.1 schema.
  */
 
 #include "internal.h"
@@ -30,6 +34,9 @@
 #include "soap/SOAP.h"
 #include "util/XMLHelper.h"
 
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/if.hpp>
+#include <boost/lambda/lambda.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace soap11;
@@ -55,22 +62,25 @@ namespace {
         public AbstractXMLObjectMarshaller,
         public AbstractXMLObjectUnmarshaller
     {
-        xmltooling::QName* m_qname;
+        mutable xmltooling::QName* m_qname;
     public:
         virtual ~FaultcodeImpl() {
             delete m_qname;
         }
 
         FaultcodeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
-            : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_qname(NULL) {
+            : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_qname(nullptr) {
         }
             
         FaultcodeImpl(const FaultcodeImpl& src)
-                : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src), m_qname(NULL) {
-            setCode(src.getCode());
+                : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src), m_qname(nullptr) {
+            IMPL_CLONE_ATTRIB(Code);
         }
         
         const xmltooling::QName* getCode() const {
+            if (!m_qname && getDOM() && getDOM()->getTextContent()) {
+                m_qname = XMLHelper::getNodeValueAsQName(getDOM());
+            }
             return m_qname;
         }
         
@@ -80,8 +90,9 @@ namespace {
                 auto_ptr_XMLCh temp(m_qname->toString().c_str());
                 setTextContent(temp.get());
             }
-            else
-                setTextContent(NULL);
+            else {
+                setTextContent(nullptr);
+            }
         }
         
         IMPL_XMLOBJECT_CLONE(Faultcode);
@@ -106,9 +117,7 @@ namespace {
                     AbstractAttributeExtensibleXMLObject(src),
                     AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
-            VectorOf(XMLObject) v=getUnknownXMLObjects();
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i)
-                v.push_back((*i)->clone());
+            IMPL_CLONE_XMLOBJECT_CHILDREN(UnknownXMLObject);
         }
         
         IMPL_XMLOBJECT_CLONE(Detail);
@@ -135,14 +144,14 @@ namespace {
         public AbstractXMLObjectUnmarshaller
     {
         void init() {
-            m_Faultcode=NULL;
-            m_Faultstring=NULL;
-            m_Faultactor=NULL;
-            m_Detail=NULL;
-            m_children.push_back(NULL);
-            m_children.push_back(NULL);
-            m_children.push_back(NULL);
-            m_children.push_back(NULL);
+            m_Faultcode=nullptr;
+            m_Faultstring=nullptr;
+            m_Faultactor=nullptr;
+            m_Detail=nullptr;
+            m_children.push_back(nullptr);
+            m_children.push_back(nullptr);
+            m_children.push_back(nullptr);
+            m_children.push_back(nullptr);
             m_pos_Faultcode=m_children.begin();
             m_pos_Faultstring=m_pos_Faultcode;
             ++m_pos_Faultstring;
@@ -151,6 +160,7 @@ namespace {
             m_pos_Detail=m_pos_Faultactor;
             ++m_pos_Detail;
         }
+
     protected:
         FaultImpl() {
             init();
@@ -167,14 +177,10 @@ namespace {
         FaultImpl(const FaultImpl& src)
                 : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getFaultcode())
-                setFaultcode(src.getFaultcode()->cloneFaultcode());
-            if (src.getFaultstring())
-                setFaultstring(src.getFaultstring()->cloneFaultstring());
-            if (src.getFaultactor())
-                setFaultactor(src.getFaultactor()->cloneFaultactor());
-            if (src.getDetail())
-                setDetail(src.getDetail()->cloneDetail());
+            IMPL_CLONE_TYPED_CHILD(Faultcode);
+            IMPL_CLONE_TYPED_CHILD(Faultstring);
+            IMPL_CLONE_TYPED_CHILD(Faultactor);
+            IMPL_CLONE_TYPED_CHILD(Detail);
         }
         
         IMPL_XMLOBJECT_CLONE(Fault);
@@ -185,10 +191,10 @@ namespace {
 
     protected:
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILD(Faultcode,NULL,false);
-            PROC_TYPED_CHILD(Faultstring,NULL,false);
-            PROC_TYPED_CHILD(Faultactor,NULL,false);
-            PROC_TYPED_CHILD(Detail,NULL,false);
+            PROC_TYPED_CHILD(Faultcode,nullptr,false);
+            PROC_TYPED_CHILD(Faultstring,nullptr,false);
+            PROC_TYPED_CHILD(Faultactor,nullptr,false);
+            PROC_TYPED_CHILD(Detail,nullptr,false);
             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
         }
     };
@@ -213,9 +219,7 @@ namespace {
                     AbstractAttributeExtensibleXMLObject(src),
                     AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
-            VectorOf(XMLObject) v=getUnknownXMLObjects();
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i)
-                v.push_back((*i)->clone());
+            IMPL_CLONE_XMLOBJECT_CHILDREN(UnknownXMLObject);
         }
         
         IMPL_XMLOBJECT_CLONE(Body);
@@ -255,9 +259,7 @@ namespace {
                     AbstractAttributeExtensibleXMLObject(src),
                     AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
-            VectorOf(XMLObject) v=getUnknownXMLObjects();
-            for (vector<XMLObject*>::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i)
-                v.push_back((*i)->clone());
+            IMPL_CLONE_XMLOBJECT_CHILDREN(UnknownXMLObject);
         }
         
         IMPL_XMLOBJECT_CLONE(Header);
@@ -285,14 +287,15 @@ namespace {
         public AbstractXMLObjectUnmarshaller
     {
         void init() {
-            m_Header=NULL;
-            m_Body=NULL;
-            m_children.push_back(NULL);
-            m_children.push_back(NULL);
+            m_Header=nullptr;
+            m_Body=nullptr;
+            m_children.push_back(nullptr);
+            m_children.push_back(nullptr);
             m_pos_Header=m_children.begin();
             m_pos_Body=m_pos_Header;
             ++m_pos_Body;
         }
+
     public:
         virtual ~EnvelopeImpl() {}
 
@@ -302,18 +305,15 @@ namespace {
         }
             
         EnvelopeImpl(const EnvelopeImpl& src)
-                : AbstractXMLObject(src), AbstractAttributeExtensibleXMLObject(src),
-                    AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
+                : AbstractXMLObject(src), AbstractAttributeExtensibleXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
-            if (src.getHeader())
-                setHeader(src.getHeader()->cloneHeader());
-            if (src.getBody())
-                setBody(src.getBody()->cloneBody());
+            IMPL_CLONE_TYPED_CHILD(Header);
+            IMPL_CLONE_TYPED_CHILD(Body);
         }
         
+        IMPL_XMLOBJECT_CLONE(Envelope);
         IMPL_TYPED_CHILD(Header);
         IMPL_TYPED_CHILD(Body);
-        IMPL_XMLOBJECT_CLONE(Envelope);
 
     protected:
         void marshallAttributes(DOMElement* domElement) const {
@@ -358,9 +358,9 @@ const XMLCh Envelope::LOCAL_NAME[] =                    UNICODE_LITERAL_8(E,n,v,
 const XMLCh Envelope::TYPE_NAME[] =                     UNICODE_LITERAL_8(E,n,v,e,l,o,p,e);
 const XMLCh Fault::LOCAL_NAME[] =                       UNICODE_LITERAL_5(F,a,u,l,t);
 const XMLCh Fault::TYPE_NAME[] =                        UNICODE_LITERAL_5(F,a,u,l,t);
-const XMLCh Faultactor::LOCAL_NAME[] =                  UNICODE_LITERAL_10(F,a,u,l,t,a,c,t,o,r);
-const XMLCh Faultcode::LOCAL_NAME[] =                   UNICODE_LITERAL_9(F,a,u,l,t,c,o,d,e);
-const XMLCh Faultstring::LOCAL_NAME[] =                 UNICODE_LITERAL_11(F,a,u,l,t,s,t,r,i,n,g);
+const XMLCh Faultactor::LOCAL_NAME[] =                  UNICODE_LITERAL_10(f,a,u,l,t,a,c,t,o,r);
+const XMLCh Faultcode::LOCAL_NAME[] =                   UNICODE_LITERAL_9(f,a,u,l,t,c,o,d,e);
+const XMLCh Faultstring::LOCAL_NAME[] =                 UNICODE_LITERAL_11(f,a,u,l,t,s,t,r,i,n,g);
 const XMLCh Header::LOCAL_NAME[] =                      UNICODE_LITERAL_6(H,e,a,d,e,r);
 const XMLCh Header::TYPE_NAME[] =                       UNICODE_LITERAL_6(H,e,a,d,e,r);
 const XMLCh Header::ACTOR_ATTRIB_NAME[] =               UNICODE_LITERAL_5(a,c,t,o,r);