You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ed...@apache.org on 2006/05/10 17:40:02 UTC

svn commit: r405782 - in /incubator/tuscany/cpp/sdo/runtime/core: src/commonj/sdo/DataFactoryImpl.cpp src/commonj/sdo/SDOSAX2Parser.cpp src/commonj/sdo/SDOSAX2Parser.h test/sdotest.cpp test/stock_xml.txt test/utils.cpp

Author: edslattery
Date: Wed May 10 08:39:59 2006
New Revision: 405782

URL: http://svn.apache.org/viewcvs?rev=405782&view=rev
Log:
Changes to follow the java specification for loading xml with no xsd

Modified:
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h
    incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp
    incubator/tuscany/cpp/sdo/runtime/core/test/stock_xml.txt
    incubator/tuscany/cpp/sdo/runtime/core/test/utils.cpp

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp?rev=405782&r1=405781&r2=405782&view=diff
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/DataFactoryImpl.cpp Wed May 10 08:39:59 2006
@@ -60,7 +60,7 @@
 
     addType(Type::SDOTypeNamespaceURI,"String");
     addType(Type::SDOTypeNamespaceURI,"DataObject");
-    addType(Type::SDOTypeNamespaceURI,"OpenDataObject", false, true, false, false);
+    addType(Type::SDOTypeNamespaceURI,"OpenDataObject", true, true, false, false);
     addType(Type::SDOTypeNamespaceURI,"Date");
     addType(Type::SDOTypeNamespaceURI,"Double");
     addType(Type::SDOTypeNamespaceURI,"Float");

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp?rev=405782&r1=405781&r2=405782&view=diff
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.cpp Wed May 10 08:39:59 2006
@@ -61,6 +61,7 @@
                 targetNamespaceURI = "";
             }
             rootDataObject = 0;
+            newSequence = true;
         }
         
         SDOSAX2Parser::~SDOSAX2Parser()
@@ -180,7 +181,7 @@
                 }
 
                 const Property& property = (Property&)*pprop;
-                const Type& propertyType = ((TypeImpl&)type).getRealPropertyType(propertyName);
+                //const Type& propertyType = ((TypeImpl&)type).getRealPropertyType(propertyName);
                 if (currentDataObject->getType().isSequencedType())
                 {
                     SequencePtr seq = currentDataObject->getSequence();
@@ -525,24 +526,23 @@
                     // as many valued
                     // could be data object or primitive. All primitives will appear
                     // as bytes.
+                    // UPDATE: Spec says that all elements will appear as DataObjects which 
+                    // are sequenced - the text will come out as text elements in the sequence
+
                     if (!xsitypeName.isNull())
                     {
                         // it has a type from xsi:type
-                        pprop = ((DataObjectImpl*)dob)->defineList(propertyName);
                         newDO = dataFactory->create(xsitypeURI, xsitypeName);
-                        DataObjectList& dol = dob->getList(propertyName);
-                        dol.append(newDO);
-                        setCurrentDataObject(newDO);
-                        setAttributes(tns,namespaces,attributes);
                     }
                     else
                     {
-                        pprop = ((DataObjectImpl*)dob)->defineList(propertyName);
-                        currentPropertySetting = PropertySetting(currentDataObject, propertyName,
-                            bToBeNull);
-                        currentPropertySetting.pendingUnknownType = true;
-                        
+                        newDO = dataFactory->create(Type::SDOTypeNamespaceURI, "OpenDataObject");
                     }
+                    pprop = ((DataObjectImpl*)dob)->defineList(propertyName);
+                    DataObjectList& dol = dob->getList(propertyName);
+                    dol.append(newDO);
+                    setCurrentDataObject(newDO);
+                    setAttributes(tns,namespaces,attributes);
                 }
                 return pprop;
             }
@@ -564,7 +564,9 @@
             LOGENTRY(INFO,"SDOSAX2Parser: startElementNs");
 
             LOGINFO_1(INFO,"SDOSAX2Parser: startElementNs:%s",
-                           (const char*)localname);
+                (const char*)localname);
+
+            newSequence = true;
 
             bool bToBeNull = false;
             // Save the namespace information from the first element
@@ -602,26 +604,7 @@
                 return;
             }
 
-            // special case - we may have created an open type, but not been able
-            // to decide on the type. If we find a start element within the open 
-            // type - then we can assume its a data object. We dont have a type,
-            // so create it as an open type data object
-            if (currentPropertySetting.pendingUnknownType)
-            {
-                if (currentDataObject != 0)
-                {
-                    DataObjectPtr newDO = dataFactory->create(
-                    Type::SDOTypeNamespaceURI, "OpenDataObject");
-
-                    DataObjectList& dol = currentDataObject->getList
-                        (currentPropertySetting.name);
-                    dol.append(newDO);
-                    setCurrentDataObject(newDO);
-                    currentPropertySetting = PropertySetting();
-                }
-            }
  
-
             
             if (dealingWithChangeSummary)
             {
@@ -1033,6 +1016,8 @@
 
             LOGENTRY(INFO,"SDOSAX2Parser: endElementNs");
 
+            newSequence = true;
+
             if (localname.equals("changeSummary"))
             {
                 // end of change summary
@@ -1211,6 +1196,15 @@
          
         void SDOSAX2Parser::characters(const SDOXMLString& chars)
         {
+            if (chars.isNull()) return;
+
+            if (!strcmp((const char*)chars,"\r") ||
+                !strcmp((const char*)chars,"\n"))
+            {
+                newSequence = true;
+                return;
+            }
+
             if (dealingWithChangeSummary)
             {
                 if (csbuilder == 0)
@@ -1231,6 +1225,47 @@
                 return;
             }
 
+            // If the current DataObject is a sequenced Type
+            // then add this as text to the sequence
+            if (currentDataObject && currentDataObjectType->isSequencedType())
+            {
+                SequencePtr seq = currentDataObject->getSequence();
+                if (seq)
+                {
+                    if (newSequence == true)
+                    {
+                        seq->addText(chars);
+                        newSequence = false;
+                    }
+                    else
+                    {
+                        for (int k= (int)(seq->size())-1; k>=0 ; k --)
+                        {
+                            if (seq->isText(k))
+                            {
+                                const char * s = seq->getCStringValue(k);
+                               
+                                if (s)
+                                {
+                                    char *combi = 
+                                        new char[strlen(s)+strlen(chars) + 2];
+                                    strcpy(combi,s);
+                                    strcat(combi,chars);
+                                    seq->setText(k,(const char*)combi);
+                                    delete combi;
+                                }
+                                else
+                                {
+                                    seq->setText(k,chars);
+                                }
+                                return;
+                            }
+                        }
+                        seq->addText(chars);
+                    }
+                    return;
+                }
+            }
             
             DataObject* dob = currentDataObject;
             if ((dob != 0)  && ((DataObjectImpl*)dob)->getTypeImpl().isFromList())
@@ -1266,18 +1301,7 @@
                 delete buf;
                 return;
             }
-
-            
-            // If the current DataObject is a sequenced Type
-            // then add this as text to the sequence
-            if (currentDataObject && currentDataObjectType->isSequencedType())
-            {
-                SequencePtr seq = currentDataObject->getSequence();
-                if (seq)
-                {
-                    seq->addText(chars);
-                }
-            }
+           
         }
         
         

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h?rev=405782&r1=405781&r2=405782&view=diff
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSAX2Parser.h Wed May 10 08:39:59 2006
@@ -115,6 +115,7 @@
             
             DataObjectPtr    currentDataObject;
             bool            isDataGraph;
+            bool            newSequence;
             
             void            setCurrentDataObject(DataObjectPtr currentDO);
             const Type*        currentDataObjectType;

Modified: incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp?rev=405782&r1=405781&r2=405782&view=diff
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/sdotest.cpp Wed May 10 08:39:59 2006
@@ -5494,14 +5494,14 @@
         DataObjectList& dl32 = emp2->getList("openintlist");
 
         if (strcmp(emp2->getProperty("openintlist").getType().getName(),
-            "Bytes"))
+            "OpenDataObject"))
         {
-            if (!silent)cout << "OpenLoadNS2 failure - IntegerList not Bytes " <<
+            if (!silent)cout << "OpenLoadNS2 failure - IntegerList not OpenDataObject " <<
                 emp2->getProperty("openintlist").getType().getName() << endl;
             return 0;
         }
 
-        if (dl32.getInteger(0) != 45)
+        if (atoi(dl32.getDataObject(0)->getSequence()->getCStringValue(0)) != 45)
         {
             if (!silent)cout << "OpenLoadNS2 failure - Integer value is" << 
                 dl32.getInteger(0) << endl;
@@ -5557,10 +5557,13 @@
 
         DataObjectList& dl3 = emp->getList("openlist");
 
+        // change to match spec - now an open data object
+        // the list should contain a single data object with a sequence of three text elements
+
         if (strcmp(emp->getProperty("openlist").getType().getName(),
-            "Bytes"))
+            "OpenDataObject"))
         {
-            if (!silent)cout << "OpenManyLoad failure - BytesList not Bytes " <<
+            if (!silent)cout << "OpenManyLoad failure - BytesList not OpenDataObject " <<
                 emp->getProperty("openlist").getType().getName() << endl;
             return 0;
         }
@@ -5572,9 +5575,14 @@
             return 0;
         }
 
-        if (strcmp(dl3.getCString(0),"Three member")) return 0;
-        if (strcmp(dl3.getCString(1),"Open bytes")) return 0;
-        if (strcmp(dl3.getCString(2),"List is complete")) return 0;
+        SequencePtr sq = dl3[0]->getSequence();
+        if (strcmp(sq->getCStringValue(0),"Three member")) return 0;
+
+        SequencePtr sq2 = dl3[1]->getSequence();
+        if (strcmp(sq2->getCStringValue(0),"Open bytes")) return 0;
+
+        SequencePtr sq3 = dl3[2]->getSequence();
+        if (strcmp(sq3->getCStringValue(0),"List is complete")) return 0;
 
         return 1;
     }

Modified: incubator/tuscany/cpp/sdo/runtime/core/test/stock_xml.txt
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sdo/runtime/core/test/stock_xml.txt?rev=405782&r1=405781&r2=405782&view=diff
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/stock_xml.txt (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/stock_xml.txt Wed May 10 08:39:59 2006
@@ -47,49 +47,81 @@
 *******************************END TYPES******************
 ===== DataObject contents =====
 GetQuotesResult:dataObject
-===== DataObject contents =====
-StockQuotes: list dataObject[0]=
-===== DataObject contents =====
-StockQuote: list dataObject[0]=
-===== DataObject contents =====
-Symbol: list bytes[0]=IBM
-
-Price: list bytes[0]=<big><b>82.72</b></big>
-
-Time: list bytes[0]=11:41AM ET
-
-Change: list bytes[0]=<img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/down_r.gif" alt="Down">&nbsp;<b style="color:#cc0000;">0.17 (0.21%)</b>
-
-PrevClose: list bytes[0]=82.89
-
-Open: list bytes[0]=82.49
-
-Bid: list bytes[0]=N/A
-
-Ask: list bytes[0]=N/A
-
-YearTarget: list bytes[0]=95.94
-
-DayRange: list bytes[0]=82.40 - 82.80
-
-YearRange: list bytes[0]=72.50 - 89.94
-
-Volume: list bytes[0]=1,568,200
-
-AvgVol: list bytes[0]=5,301,380
-
-MarketCap: list bytes[0]=128.25B
-
-PE: list bytes[0]=16.15
-
-EPS: list bytes[0]=5.12
-
-DivYield: list bytes[0]=1.20 (1.40%)
-
-===== End DataObject =====
-
-===== End DataObject =====
-
-===== End DataObject =====
+===== Sequenced DataObject contents =====
+Setting of DO property StockQuotes[0]=
+===== Sequenced DataObject contents =====
+Setting of DO property StockQuote[0]=
+===== Sequenced DataObject contents =====
+Setting of DO property Symbol[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:IBM
+===== End Sequenced DataObject contents =
+Setting of DO property Price[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:<big><b>82.72</b></big>
+===== End Sequenced DataObject contents =
+Setting of DO property Time[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:11:41AM ET
+===== End Sequenced DataObject contents =
+Setting of DO property Change[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:<img width="10" height="14" border="0" src="http://us.i1.yimg.com/us.yimg.com/i/us/fi/03rd/down_r.gif" alt="Down">&nbsp;<b style="color:#cc0000;">0.17 (0.21%)</b>
+===== End Sequenced DataObject contents =
+Setting of DO property PrevClose[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:82.89
+===== End Sequenced DataObject contents =
+Setting of DO property Open[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:82.49
+===== End Sequenced DataObject contents =
+Setting of DO property Bid[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:N/A
+===== End Sequenced DataObject contents =
+Setting of DO property Ask[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:N/A
+===== End Sequenced DataObject contents =
+Setting of DO property YearTarget[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:95.94
+===== End Sequenced DataObject contents =
+Setting of DO property DayRange[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:82.40 - 82.80
+===== End Sequenced DataObject contents =
+Setting of DO property YearRange[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:72.50 - 89.94
+===== End Sequenced DataObject contents =
+Setting of DO property Volume[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:1,568,200
+===== End Sequenced DataObject contents =
+Setting of DO property AvgVol[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:5,301,380
+===== End Sequenced DataObject contents =
+Setting of DO property MarketCap[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:128.25B
+===== End Sequenced DataObject contents =
+Setting of DO property PE[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:16.15
+===== End Sequenced DataObject contents =
+Setting of DO property EPS[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:5.12
+===== End Sequenced DataObject contents =
+Setting of DO property DivYield[0]=
+===== Sequenced DataObject contents =====
+TEXT ELEMENT:1.20 (1.40%)
+===== End Sequenced DataObject contents =
+===== End Sequenced DataObject contents =
+===== End Sequenced DataObject contents =
+===== End Sequenced DataObject contents =
 
 ===== End DataObject =====

Modified: incubator/tuscany/cpp/sdo/runtime/core/test/utils.cpp
URL: http://svn.apache.org/viewcvs/incubator/tuscany/cpp/sdo/runtime/core/test/utils.cpp?rev=405782&r1=405781&r2=405782&view=diff
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/utils.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/utils.cpp Wed May 10 08:39:59 2006
@@ -297,23 +297,78 @@
 
 void sdotest::printDataObject(FILE *f, DataObjectPtr dol)
 {
-    fprintf(f,"===== DataObject contents =====\n");
-    PropertyList pl = dol->getInstanceProperties();
+    if (dol == 0) return;
 
-    for (int j=0;j< pl.size(); j++)
+    if (dol->getType().isSequencedType())
     {
-        fprintf(f,"%s:",pl[j].getName());
-        // this could be a many-valued property, and could be one which is
-        // a data object or a data type...
-        if (pl[j].isMany()) 
+        fprintf(f,"===== Sequenced DataObject contents =====\n");
+        SequencePtr sq = dol->getSequence();
+        if (sq != 0)
         {
-            printList(f, dol,pl[j]);
+            for (unsigned int k=0;k<sq->size();k++)
+            {
+                if (sq->isText(k))
+                {
+                    fprintf(f,"TEXT ELEMENT:%s\n",sq->getCStringValue(k));
+                }
+                else
+                {
+                    const Property& p = sq->getProperty(k);
+                    if (p.isMany())
+                    {
+                        unsigned int index = sq->getListIndex(k);
+                        DataObjectList& dl = dol->getList(p);
+                        if (p.getType().isDataType())
+                        {
+                            fprintf(f,"Setting of property %s[%d]=%s\n",
+                                p.getName(),index,dl.getCString(index));
+                        }
+                        else
+                        {
+                            fprintf(f,"Setting of DO property %s[%d]=\n",
+                                p.getName(),index);
+                            printDataObject(f,dl.getDataObject(index));
+                        }
+                    }
+                    else
+                    {
+                        if (p.getType().isDataType())
+                        {
+                            fprintf(f,"Setting of property %s=%s\n",
+                                p.getName(),dol->getCString(p));
+                        }
+                        else
+                        {
+                            fprintf(f,"Setting of DO property %s=\n",
+                                p.getName());
+                            printDataObject(f,dol->getDataObject(p));
+                        }
+                    }
+                }
+            }
         }
-        else {
-            printValue(f, dol,pl[j]);
+        fprintf(f,"===== End Sequenced DataObject contents =\n");
+    }
+    else
+    {
+        fprintf(f,"===== DataObject contents =====\n");
+        PropertyList pl = dol->getInstanceProperties();
+
+        for (int j=0;j< pl.size(); j++)
+        {
+            fprintf(f,"%s:",pl[j].getName());
+            // this could be a many-valued property, and could be one which is
+            // a data object or a data type...
+            if (pl[j].isMany()) 
+            {
+                printList(f, dol,pl[j]);
+            }
+            else {
+                printValue(f, dol,pl[j]);
+            }
         }
+        fprintf(f,"===== End DataObject =====\n");
     }
-    fprintf(f,"===== End DataObject =====\n");
 }