Refined ElementProxy/ElementExtensible interfaces to match Java.
[shibboleth/cpp-xmltooling.git] / xmltooling / encryption / impl / EncryptionImpl.cpp
index d1256be..c3809d5 100644 (file)
@@ -22,8 +22,8 @@
 
 #include "internal.h"
 #include "AbstractAttributeExtensibleXMLObject.h"
-#include "AbstractChildlessElement.h"
-#include "AbstractElementProxy.h"
+#include "AbstractComplexElement.h"
+#include "AbstractSimpleElement.h"
 #include "exceptions.h"
 #include "encryption/Encryption.h"
 #include "io/AbstractXMLObjectMarshaller.h"
@@ -35,6 +35,8 @@
 using namespace xmlencryption;
 using namespace xmltooling;
 using namespace std;
+using xmlconstants::XMLENC_NS;
+using xmlconstants::XMLSIG_NS;
 
 #if defined (_MSC_VER)
     #pragma warning( push )
@@ -74,26 +76,24 @@ namespace xmlencryption {
             init();
         }
             
-        EncryptionMethodImpl(const EncryptionMethodImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
+        EncryptionMethodImpl(const EncryptionMethodImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
             setAlgorithm(src.getAlgorithm());
             if (src.getKeySize())
                 setKeySize(src.getKeySize()->cloneKeySize());
             if (src.getOAEPparams())
                 setOAEPparams(src.getOAEPparams()->cloneOAEPparams());
-            VectorOf(XMLObject) v=getOtherParameters();
-            for (vector<XMLObject*>::const_iterator i=src.m_OtherParameters.begin(); i!=src.m_OtherParameters.end(); i++) {
-                if (*i) {
-                    v.push_back((*i)->clone());
-                }
-            }
+            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_XMLOBJECT_CLONE(EncryptionMethod);
         IMPL_STRING_ATTRIB(Algorithm);
         IMPL_TYPED_CHILD(KeySize);
         IMPL_TYPED_CHILD(OAEPparams);
-        IMPL_XMLOBJECT_CHILDREN(OtherParameter,m_children.end());
+        IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject,m_children.end());
 
     protected:
         void marshallAttributes(DOMElement* domElement) const {
@@ -101,13 +101,13 @@ namespace xmlencryption {
         }
 
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILD(KeySize,XMLConstants::XMLENC_NS,false);
-            PROC_TYPED_CHILD(OAEPparams,XMLConstants::XMLENC_NS,false);
+            PROC_TYPED_CHILD(KeySize,XMLENC_NS,false);
+            PROC_TYPED_CHILD(OAEPparams,XMLENC_NS,false);
             
             // Unknown child.
             const XMLCh* nsURI=root->getNamespaceURI();
-            if (!XMLString::equals(nsURI,XMLConstants::XMLENC_NS) && nsURI && *nsURI) {
-                getOtherParameters().push_back(childXMLObject);
+            if (!XMLString::equals(nsURI,XMLENC_NS) && nsURI && *nsURI) {
+                getUnknownXMLObjects().push_back(childXMLObject);
                 return;
             }
             
@@ -133,7 +133,8 @@ namespace xmlencryption {
             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
         }
             
-        TransformsImpl(const TransformsImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
+        TransformsImpl(const TransformsImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             VectorOf(xmlsignature::Transform) v=getTransforms();
             for (vector<xmlsignature::Transform*>::const_iterator i=src.m_Transforms.begin(); i!=src.m_Transforms.end(); i++) {
                 if (*i) {
@@ -147,7 +148,7 @@ namespace xmlencryption {
 
     protected:
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_FOREIGN_CHILDREN(Transform,xmlsignature,XMLConstants::XMLSIG_NS,false);
+            PROC_TYPED_FOREIGN_CHILDREN(Transform,xmlsignature,XMLSIG_NS,false);
             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
         }
     };
@@ -174,7 +175,8 @@ namespace xmlencryption {
             init();
         }
             
-        CipherReferenceImpl(const CipherReferenceImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
+        CipherReferenceImpl(const CipherReferenceImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
             setURI(src.getURI());
             if (src.getTransforms())
@@ -191,7 +193,7 @@ namespace xmlencryption {
         }
 
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILD(Transforms,XMLConstants::XMLENC_NS,false);
+            PROC_TYPED_CHILD(Transforms,XMLENC_NS,false);
             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
         }
 
@@ -224,7 +226,8 @@ namespace xmlencryption {
             init();
         }
             
-        CipherDataImpl(const CipherDataImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
+        CipherDataImpl(const CipherDataImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
             if (src.getCipherValue())
                 setCipherValue(src.getCipherValue()->cloneCipherValue());
@@ -238,15 +241,15 @@ namespace xmlencryption {
 
     protected:
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILD(CipherValue,XMLConstants::XMLENC_NS,false);
-            PROC_TYPED_CHILD(CipherReference,XMLConstants::XMLENC_NS,false);
+            PROC_TYPED_CHILD(CipherValue,XMLENC_NS,false);
+            PROC_TYPED_CHILD(CipherReference,XMLENC_NS,false);
             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
         }
     };
 
     class XMLTOOL_DLLLOCAL EncryptionPropertyImpl : public virtual EncryptionProperty,
-        public AbstractElementProxy,
         public AbstractAttributeExtensibleXMLObject,
+        public AbstractComplexElement,
         public AbstractDOMCachingXMLObject,
         public AbstractXMLObjectMarshaller,
         public AbstractXMLObjectUnmarshaller
@@ -267,22 +270,21 @@ namespace xmlencryption {
             
         EncryptionPropertyImpl(const EncryptionPropertyImpl& src)
                 : AbstractXMLObject(src),
-                    AbstractElementProxy(src),
                     AbstractAttributeExtensibleXMLObject(src),
+                    AbstractComplexElement(src),
                     AbstractDOMCachingXMLObject(src) {
             init();
             setId(src.getId());
             setTarget(src.getTarget());
-            for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
-                if (*i) {
-                    getXMLObjects().push_back((*i)->clone());
-                }
-            }
+            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_XMLOBJECT_CLONE(EncryptionProperty);
-        IMPL_STRING_ATTRIB(Id);
+        IMPL_ID_ATTRIB(Id);
         IMPL_STRING_ATTRIB(Target);
+        IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject, m_children.end());
 
         void setAttribute(QName& qualifiedName, const XMLCh* value) {
             if (!qualifiedName.hasNamespaceURI()) {
@@ -302,25 +304,16 @@ namespace xmlencryption {
         void marshallAttributes(DOMElement* domElement) const {
             MARSHALL_ID_ATTRIB(Id,ID,NULL);
             MARSHALL_STRING_ATTRIB(Target,TARGET,NULL);
-
-            // Take care of wildcard.
-            for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
-                DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
-                if (i->first.hasPrefix())
-                    attr->setPrefix(i->first.getPrefix());
-                attr->setNodeValue(i->second);
-                domElement->setAttributeNode(attr);
-            }
+            marshallExtensionAttributes(domElement);
         }
 
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            getXMLObjects().push_back(childXMLObject);
+            getUnknownXMLObjects().push_back(childXMLObject);
         }
 
         void processAttribute(const DOMAttr* attribute) {
             PROC_ID_ATTRIB(Id,ID,NULL);
-            QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
-            setAttribute(q,attribute->getNodeValue());
+            unmarshallExtensionAttribute(attribute);
         }
     };
 
@@ -343,7 +336,8 @@ namespace xmlencryption {
             init();
         }
             
-        EncryptionPropertiesImpl(const EncryptionPropertiesImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
+        EncryptionPropertiesImpl(const EncryptionPropertiesImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
             setId(src.getId());
             VectorOf(EncryptionProperty) v=getEncryptionPropertys();
@@ -355,7 +349,7 @@ namespace xmlencryption {
         }
         
         IMPL_XMLOBJECT_CLONE(EncryptionProperties);
-        IMPL_STRING_ATTRIB(Id);
+        IMPL_ID_ATTRIB(Id);
         IMPL_TYPED_CHILDREN(EncryptionProperty,m_children.end());
 
     protected:
@@ -364,7 +358,7 @@ namespace xmlencryption {
         }
 
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILDREN(EncryptionProperty,XMLConstants::XMLENC_NS,false);
+            PROC_TYPED_CHILDREN(EncryptionProperty,XMLENC_NS,false);
             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
         }
 
@@ -375,7 +369,7 @@ namespace xmlencryption {
     };
 
     class XMLTOOL_DLLLOCAL ReferenceTypeImpl : public virtual ReferenceType,
-        public AbstractElementProxy,
+        public AbstractComplexElement,
         public AbstractDOMCachingXMLObject,
         public AbstractXMLObjectMarshaller,
         public AbstractXMLObjectUnmarshaller
@@ -400,18 +394,17 @@ namespace xmlencryption {
         }
             
         ReferenceTypeImpl(const ReferenceTypeImpl& src)
-                : AbstractXMLObject(src), AbstractElementProxy(src), AbstractDOMCachingXMLObject(src) {
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
             setURI(src.getURI());
-            for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
-                if (*i) {
-                    getXMLObjects().push_back((*i)->clone());
-                }
-            }
+            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_XMLOBJECT_CLONE(ReferenceType);
         IMPL_STRING_ATTRIB(URI);
+        IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject,m_children.end());
 
     protected:
         void marshallAttributes(DOMElement* domElement) const {
@@ -419,7 +412,7 @@ namespace xmlencryption {
         }
 
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            getXMLObjects().push_back(childXMLObject);
+            getUnknownXMLObjects().push_back(childXMLObject);
         }
 
         void processAttribute(const DOMAttr* attribute) {
@@ -473,7 +466,8 @@ namespace xmlencryption {
             : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
         }
             
-        ReferenceListImpl(const ReferenceListImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
+        ReferenceListImpl(const ReferenceListImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {
                 if (*i) {
                     DataReference* data=dynamic_cast<DataReference*>(*i);
@@ -497,8 +491,8 @@ namespace xmlencryption {
 
     protected:
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILDREN(DataReference,XMLConstants::XMLENC_NS,false);
-            PROC_TYPED_CHILDREN(KeyReference,XMLConstants::XMLENC_NS,false);
+            PROC_TYPED_CHILDREN(DataReference,XMLENC_NS,false);
+            PROC_TYPED_CHILDREN(KeyReference,XMLENC_NS,false);
             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
         }
     };
@@ -545,7 +539,8 @@ namespace xmlencryption {
             init();
         }
             
-        EncryptedTypeImpl(const EncryptedTypeImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src) {
+        EncryptedTypeImpl(const EncryptedTypeImpl& src)
+                : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) {
             init();
             setId(src.getId());
             setType(src.getType());
@@ -562,7 +557,7 @@ namespace xmlencryption {
         }
         
         IMPL_XMLOBJECT_CLONE(EncryptedType);
-        IMPL_STRING_ATTRIB(Id);
+        IMPL_ID_ATTRIB(Id);
         IMPL_STRING_ATTRIB(Type);
         IMPL_STRING_ATTRIB(MimeType);
         IMPL_STRING_ATTRIB(Encoding);
@@ -580,10 +575,10 @@ namespace xmlencryption {
         }
 
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILD(EncryptionMethod,XMLConstants::XMLENC_NS,false);
-            PROC_TYPED_FOREIGN_CHILD(KeyInfo,xmlsignature,XMLConstants::XMLSIG_NS,false);
-            PROC_TYPED_CHILD(CipherData,XMLConstants::XMLENC_NS,false);
-            PROC_TYPED_CHILD(EncryptionProperties,XMLConstants::XMLENC_NS,false);
+            PROC_TYPED_CHILD(EncryptionMethod,XMLENC_NS,false);
+            PROC_TYPED_FOREIGN_CHILD(KeyInfo,xmlsignature,XMLSIG_NS,false);
+            PROC_TYPED_CHILD(CipherData,XMLENC_NS,false);
+            PROC_TYPED_CHILD(EncryptionProperties,XMLENC_NS,false);
             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
         }
 
@@ -655,8 +650,8 @@ namespace xmlencryption {
         }
 
         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
-            PROC_TYPED_CHILD(ReferenceList,XMLConstants::XMLENC_NS,false);
-            PROC_TYPED_CHILD(CarriedKeyName,XMLConstants::XMLENC_NS,false);
+            PROC_TYPED_CHILD(ReferenceList,XMLENC_NS,false);
+            PROC_TYPED_CHILD(CarriedKeyName,XMLENC_NS,false);
             EncryptedTypeImpl::processChildElement(childXMLObject,root);
         }