Handle IDness during (un)marshalling, move more work to base class.
authorScott Cantor <cantor.2@osu.edu>
Fri, 8 Sep 2006 03:24:20 +0000 (03:24 +0000)
committerScott Cantor <cantor.2@osu.edu>
Fri, 8 Sep 2006 03:24:20 +0000 (03:24 +0000)
xmltooling/AbstractAttributeExtensibleXMLObject.cpp
xmltooling/AbstractAttributeExtensibleXMLObject.h
xmltooling/AttributeExtensibleXMLObject.h
xmltooling/encryption/impl/EncryptionImpl.cpp
xmltooling/impl/AnyElement.cpp
xmltooling/soap/impl/SOAPImpl.cpp

index 7b7fd32..3ebf6c5 100644 (file)
@@ -76,3 +76,26 @@ void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedNa
         } \r
     }\r
 }\r
+\r
+void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute)\r
+{\r
+    QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix());\r
+    bool ID = isRegisteredIDAttribute(q); \r
+    setAttribute(q,attribute->getNodeValue(),ID);\r
+    if (ID) {\r
+        attribute->getOwnerElement()->setIdAttributeNode(attribute);\r
+    }\r
+}\r
+\r
+void AbstractAttributeExtensibleXMLObject::marshallExtensionAttributes(DOMElement* domElement) const\r
+{\r
+    for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {\r
+        DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());\r
+        if (i->first.hasPrefix())\r
+            attr->setPrefix(i->first.getPrefix());\r
+        attr->setNodeValue(i->second);\r
+        domElement->setAttributeNode(attr);\r
+        if (m_idAttribute==i)\r
+            domElement->setIdAttributeNode(attr);\r
+    }\r
+}\r
index e2e65ea..9480cff 100644 (file)
@@ -67,6 +67,21 @@ namespace xmltooling {
         /** Copy constructor. */\r
         AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject& src);\r
 \r
+        /**\r
+         * Assists in the unmarshalling of extension attributes.\r
+         * \r
+         * @param attribute the DOM attribute node being unmarshalled\r
+         */\r
+        void unmarshallExtensionAttribute(const DOMAttr* attribute);\r
+\r
+        /**\r
+         * Assists in the marshalling of extension attributes.\r
+         * \r
+         * @param domElement    the DOM element against which to marshall the attributes\r
+         */\r
+        void marshallExtensionAttributes(DOMElement* domElement) const;\r
+    \r
+    private:\r
         /** Map of arbitrary attributes. */\r
         std::map<QName,XMLCh*> m_attributeMap;\r
         \r
index 8ba087b..87bc6d3 100644 (file)
@@ -78,6 +78,15 @@ namespace xmltooling {
         static const std::set<QName>& getRegisteredIDAttributes() {\r
             return m_idAttributeSet;\r
         }\r
+        \r
+        /**\r
+         * Tests whether an XML attribute is registered as an XML ID.\r
+         * \r
+         * @return true iff the attribute name matches a registered XML ID attribute \r
+         */\r
+        static bool isRegisteredIDAttribute(const QName& name) {\r
+            return m_idAttributeSet.find(name)!=m_idAttributeSet.end();\r
+        }\r
     \r
         /**\r
          * Registers a new attribute as being of XML ID type.\r
index d1256be..cc9a9ab 100644 (file)
@@ -281,7 +281,7 @@ namespace xmlencryption {
         }
         
         IMPL_XMLOBJECT_CLONE(EncryptionProperty);
-        IMPL_STRING_ATTRIB(Id);
+        IMPL_ID_ATTRIB(Id);
         IMPL_STRING_ATTRIB(Target);
 
         void setAttribute(QName& qualifiedName, const XMLCh* value) {
@@ -302,15 +302,7 @@ 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) {
@@ -319,8 +311,7 @@ namespace xmlencryption {
 
         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);
         }
     };
 
@@ -355,7 +346,7 @@ namespace xmlencryption {
         }
         
         IMPL_XMLOBJECT_CLONE(EncryptionProperties);
-        IMPL_STRING_ATTRIB(Id);
+        IMPL_ID_ATTRIB(Id);
         IMPL_TYPED_CHILDREN(EncryptionProperty,m_children.end());
 
     protected:
@@ -562,7 +553,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);
index 0b95d34..a19060d 100644 (file)
@@ -52,13 +52,7 @@ AnyElementImpl::AnyElementImpl(const AnyElementImpl& src) : AbstractXMLObject(sr
 }       
 
 void AnyElementImpl::marshallAttributes(DOMElement* domElement) const {
-    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 AnyElementImpl::marshallElementContent(DOMElement* domElement) const {
@@ -72,8 +66,7 @@ void AnyElementImpl::processChildElement(XMLObject* childXMLObject, const DOMEle
 }
 
 void AnyElementImpl::processAttribute(const DOMAttr* attribute) {
-    QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
-    setAttribute(q,attribute->getNodeValue());
+    unmarshallExtensionAttribute(attribute);
 }
 
 void AnyElementImpl::processElementContent(const XMLCh* elementContent) {
index 1f4ec07..4ac8753 100644 (file)
@@ -116,14 +116,7 @@ namespace {
 
     protected:
         void marshallAttributes(DOMElement* domElement) const {
-            // 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) {
@@ -131,8 +124,7 @@ namespace {
         }
 
         void processAttribute(const DOMAttr* attribute) {
-            QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
-            setAttribute(q,attribute->getNodeValue());
+            unmarshallExtensionAttribute(attribute);
         }
     };
 
@@ -250,15 +242,7 @@ namespace {
     protected:
         void marshallAttributes(DOMElement* domElement) const {
             MARSHALL_STRING_ATTRIB(EncodingStyle,ENCODINGSTYLE,XMLConstants::SOAP11ENV_NS);
-
-            // 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) {
@@ -266,8 +250,7 @@ namespace {
         }
 
         void processAttribute(const DOMAttr* attribute) {
-            QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
-            setAttribute(q,attribute->getNodeValue());
+            unmarshallExtensionAttribute(attribute);
         }
     };
 
@@ -329,15 +312,7 @@ namespace {
         void marshallAttributes(DOMElement* domElement) const {
             MARSHALL_STRING_ATTRIB(Actor,ACTOR,XMLConstants::SOAP11ENV_NS);
             MARSHALL_BOOLEAN_ATTRIB(MustUnderstand,MUSTUNDERSTAND,XMLConstants::SOAP11ENV_NS);
-
-            // 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) {
@@ -345,8 +320,7 @@ namespace {
         }
 
         void processAttribute(const DOMAttr* attribute) {
-            QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
-            setAttribute(q,attribute->getNodeValue());
+            unmarshallExtensionAttribute(attribute);
         }
     };
 
@@ -389,14 +363,7 @@ namespace {
 
     protected:
         void marshallAttributes(DOMElement* domElement) const {
-            // 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) {
@@ -406,8 +373,7 @@ namespace {
         }
 
         void processAttribute(const DOMAttr* attribute) {
-            QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); 
-            setAttribute(q,attribute->getNodeValue());
+            unmarshallExtensionAttribute(attribute);
         }
     };
 };