You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ro...@apache.org on 2006/11/21 16:42:32 UTC

svn commit: r477701 - /incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp

Author: robbinspg
Date: Tue Nov 21 07:42:32 2006
New Revision: 477701

URL: http://svn.apache.org/viewvc?view=rev&rev=477701
Log:
TUSCANY-919 - Apply Sebastiens patch with ammendment

Modified:
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp?view=diff&rev=477701&r1=477700&r2=477701
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp Tue Nov 21 07:42:32 2006
@@ -572,14 +572,17 @@
         {
             std::map<SDOXMLString,SDOXMLString>::iterator it;
             SDOXMLString uri = dob->getType().getURI();
-    
-            it = namespaceMap.find(uri);
-            if (it == namespaceMap.end())
+            SDOXMLString typeName = dob->getType().getName();
+            if (!(uri.equals("commonj.sdo") && typeName.equals("OpenDataObject")))
             {
-                char buf[20];
-                sprintf(buf,"%d",++spacescount);
-                SDOXMLString s = SDOXMLString("tns") + buf;
-                namespaceMap.insert(make_pair(uri,s));
+                it = namespaceMap.find(uri);
+                if (it == namespaceMap.end())
+                {
+                    char buf[20];
+                    sprintf(buf,"%d",++spacescount);
+                    SDOXMLString s = SDOXMLString("tns") + buf;
+                    namespaceMap.insert(make_pair(uri,s));
+                }
             }
 
             PropertyList pl = dob->getInstanceProperties();
@@ -639,14 +642,18 @@
         //////////////////////////////////////////////////////////////////////////
         void SDOXMLWriter::writeXmlnsXsi()
         {
+			return;
             SDOXMLString xsins("http://www.w3.org/2001/XMLSchema-instance");
 
             std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(xsins);
             if (it == namespaceMap.end())
             {               
-                SDOXMLString prefix("xmlns:xsi");
-                xmlTextWriterWriteAttribute(writer,
-                prefix, xsins);
+                namespaceMap.insert(make_pair(
+                    SDOXMLString("http://www.w3.org/2001/XMLSchema-instance"),
+                    SDOXMLString("xsi")));
+//                SDOXMLString prefix("xmlns:xsi");
+//                xmlTextWriterWriteAttribute(writer,
+//                prefix, xsins);
             }
         }
         
@@ -667,7 +674,26 @@
             if (dataObject == 0)
                 return 0;
 
-
+            // Don't write the element URI if the element is a child of an open type
+            // and not one of the declared properties
+            SDOXMLString uri = elementURI;
+            if (!isRoot && !writeXSIType)
+            {
+                DataObject* dob = dataObject;
+                DataObjectImpl* cont = 
+                         ((DataObjectImpl*)dob)->getContainerImpl();
+                if (cont != 0)
+                {
+                    if (cont->getType().isOpenType())
+                    {
+                        if (cont->getTypeImpl().getPropertyImpl(elementName) == 0)
+                        {
+                            uri = "";
+                        }
+                    }
+                }
+            }
+            
             //SDOXMLString uri;
             //if (!elementURI.equals(namespaceUriStack.top()))
             //{
@@ -685,7 +711,7 @@
                 if (dataObject->isNull(""))
                 {
                     rc = xmlTextWriterStartElementNS(writer, 
-                        NULL, elementName, elementURI);
+                        NULL, elementName, uri);
                     if (rc < 0) 
                     {
                         SDO_THROW_EXCEPTION("writeDO", 
@@ -721,13 +747,13 @@
 
             if (isRoot)
             {
-                tnsURI=elementURI;
-                if (elementURI.equals("")) {
+                tnsURI=uri;
+                if (uri.equals("")) {
                     rc = xmlTextWriterStartElementNS(writer, NULL, elementName, NULL);
                 }
                 else
                 {
-                    rc = xmlTextWriterStartElementNS(writer, NULL, elementName, elementURI);
+                    rc = xmlTextWriterStartElementNS(writer, NULL, elementName, uri);
                 }
                 if (rc < 0) {
                     SDO_THROW_EXCEPTION("writeDO", SDOXMLParserException, "xmlTextWriterStartElementNS failed");
@@ -739,9 +765,9 @@
 
                 SDOXMLString theName=elementName;
 
-                if (!elementURI.isNull() && !elementURI.equals(tnsURI) && !elementURI.equals(""))
+                if (!uri.isNull() && !uri.equals(tnsURI) && !uri.equals(""))
                 {
-                    std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI);
+                    std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(uri);
                     if (it != namespaceMap.end())
                     {
                         theName = (*it).second;
@@ -780,12 +806,19 @@
 
             if (isRoot)
             {
-                std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(elementURI);
+                std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(uri);
                 if (it == namespaceMap.end())
                 {
                     SDOXMLString s = SDOXMLString("tns");
                     namespaceMap.insert(make_pair(elementURI,s));
                 }
+                it = namespaceMap.find(SDOXMLString("http://www.w3.org/2001/XMLSchema-instance"));
+                if (it == namespaceMap.end())
+                {
+                    namespaceMap.insert(make_pair(
+                        SDOXMLString("http://www.w3.org/2001/XMLSchema-instance"),
+                        SDOXMLString("xsi")));
+                }
                 DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dataObject;
                 spacescount = 1;
                 addToNamespaces(d);
@@ -837,7 +870,7 @@
 
 
             //////////////////////////////////////////////////////////////////////////
-            // write out the type if the xsi:type if the containing type is open
+            // write out the type if the xsi:type of the containing type is open
             // and the property is not one of the declared properties
              //////////////////////////////////////////////////////////////////////////
             if (!writeXSIType)
@@ -863,9 +896,25 @@
                         //{
                         if (cont->getTypeImpl().getPropertyImpl(elementName) == 0)
                         {
+                            const SDOXMLString& typeURI = dataObject->getType().getURI(); 
+                            const SDOXMLString& typeName = dataObject->getType().getName();
+                            
+                            SDOXMLString theName=typeName;
+            
+                            if (!typeURI.isNull() && !typeURI.equals(tnsURI) && !typeURI.equals(""))
+                            {
+                                std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(typeURI);
+                                if (it != namespaceMap.end())
+                                {
+                                    theName = (*it).second;
+                                    theName += ":";
+                                    theName += typeName;
+                                }
+                            }
+                            
                             rc = xmlTextWriterWriteAttribute(writer, 
                             (const unsigned char*)"xsi:type", 
-                            (const unsigned char*)dataObject->getType().getName());
+                            (const unsigned char*)theName);
 
                             writeXmlnsXsi();
                         }
@@ -1155,6 +1204,7 @@
                     }
                 }
             }
+            
             rc = xmlTextWriterEndElement(writer);
             return rc;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org