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 2007/06/13 01:26:40 UTC

svn commit: r546667 - in /incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo: SDOXMLWriter.cpp SDOXMLWriter.h TypeImpl.cpp TypeImpl.h

Author: robbinspg
Date: Tue Jun 12 16:26:38 2007
New Revision: 546667

URL: http://svn.apache.org/viewvc?view=rev&rev=546667
Log:
TUSCANY-1297 Write open properties in "correct" place
This fix will write any open properties after the declared properties of the first Type in the
extension chain that is an Open Type, then the remaining declared properties.

This handles the case where a Type extends an Open type and is therefore implicitly open itself
but is not explicitly open, i.e. it has no "any" elements in schema terms. Any open properties
should be written before declared properties of the implicitly open type.

I also added some common namespace declarations so when serialising a wsdl document for example
you will now see soap:, wsdl: etc. instead of tns4:, tns5: etc.

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

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=546667&r1=546666&r2=546667
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.cpp Tue Jun 12 16:26:38 2007
@@ -47,7 +47,12 @@
         const SDOXMLString SDOXMLWriter::s_xsiNS("http://www.w3.org/2001/XMLSchema-instance");
         const SDOXMLString SDOXMLWriter::s_xmlns("xmlns");
         const SDOXMLString SDOXMLWriter::s_commonjsdo("commonj.sdo");
-
+        const SDOXMLString SDOXMLWriter::s_wsdluri("http://schemas.xmlsoap.org/wsdl/");
+        const SDOXMLString SDOXMLWriter::s_wsdl("wsdl");
+        const SDOXMLString SDOXMLWriter::s_soapuri("http://schemas.xmlsoap.org/wsdl/soap/");
+        const SDOXMLString SDOXMLWriter::s_soap("soap");
+        const SDOXMLString SDOXMLWriter::s_httpuri("http://schemas.xmlsoap.org/wsdl/http/");
+        const SDOXMLString SDOXMLWriter::s_http("http");
         
         
         SDOXMLWriter::SDOXMLWriter(
@@ -567,7 +572,36 @@
             }
             rc = xmlTextWriterEndElement(writer);
         }
-        
+
+        void SDOXMLWriter::addNamespace(const SDOXMLString& uri, bool tns)
+        {
+            std::map<SDOXMLString,SDOXMLString>::iterator it = namespaceMap.find(uri);
+            if (it == namespaceMap.end())
+            {
+                SDOXMLString prefix = "tns";
+                // Handle some common namespaces
+                if (uri.equals(s_wsdluri))
+                {
+                    prefix = s_wsdl;
+                }
+                else if (uri.equals(s_soapuri))
+                {
+                    prefix = s_soap;
+                }
+                else if (uri.equals(s_httpuri))
+                {
+                    prefix = s_http;
+                }
+                else if (!tns)
+                {
+                    char buf[20];
+                    sprintf(buf,"%d", namespaceMap.size());
+                    prefix += buf;
+                }
+                namespaceMap[uri] = prefix;
+            }
+
+        }
         //////////////////////////////////////////////////////////////////////////
         // Add to namespaces
         //////////////////////////////////////////////////////////////////////////
@@ -579,14 +613,7 @@
             SDOXMLString typeName = dob->getType().getName();
             if (!(uri.equals("commonj.sdo") && typeName.equals("OpenDataObject")))
             {
-                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));
-                }
+                addNamespace(uri);
             }
 
             PropertyList pl = dob->getInstanceProperties();
@@ -635,10 +662,7 @@
                             it = namespaceMap.find(qnameuri);
                             if (it == namespaceMap.end())
                             {
-                                char buf[20];
-                                sprintf(buf,"%d",++spacescount);
-                                SDOXMLString s = SDOXMLString("tns") + buf;
-                                namespaceMap.insert(make_pair(qnameuri,s));
+                                addNamespace(qnameuri);
                             }
                         }
                     }
@@ -699,13 +723,12 @@
                 }
 
                 // For the root element we will now gather all the namespace information
-                namespaceMap[elementURI] = SDOXMLString("tns");
+                addNamespace(elementURI, true);
 
                 // We always add the xsi namespace. TODO we should omit if we can
                 namespaceMap[s_xsiNS] = s_xsi;
 
                 DataObjectImpl* d = (DataObjectImpl*)(DataObject*)dataObject;
-                spacescount = 1;
                 addToNamespaces(d);
             }
             else
@@ -807,7 +830,7 @@
                     rc = xmlTextWriterWriteAttributeNS(writer, s_xmlns, (*it).second, NULL, (*it).first);
                 }
             }
-            // End - namespave information is written
+            // End - namespace information is written
             // --------------------------------------
 
 
@@ -1001,124 +1024,149 @@
             // Non-sequenced DataObject
             else
             {
-                // ------------------------------------------------
-                // Iterate over all the properties to find elements
-                for (i = 0; i < pl.size(); i++)
+                // Write elements for this DataObject
+
+                PropertyList definedProps = dataObjectType.getProperties();
+                unsigned int nDefinedProps = typeImpl.getPropertiesSize();
+                unsigned int nOpenProps = pl.size() - nDefinedProps;
+                unsigned int openPropIndex = nDefinedProps;
+
+                const TypeImpl* doTypeImpl = &typeImpl;
+                if (nOpenProps != 0)
                 {
-                    if (dataObject->isSet(pl[i]))
+                    while(doTypeImpl->isOpenTypeImplicitly())
                     {
-                        SDOXMLString propertyName;
-                        SDOXMLString propertyTypeURI;
+                        doTypeImpl = doTypeImpl->getBaseTypeImpl();
+                    }
+                    openPropIndex = doTypeImpl->getPropertiesSize();
+                }
 
-                        // This call sets the property name and type URI and returns if xsi:type= is required
-                        bool xsiTypeNeeded = determineNamespace(dataObject, pl[i], propertyTypeURI, propertyName);
-                       
-                        const Type& propertyType = pl[i].getType();
-						XSDPropertyInfo* pi = getPropertyInfo(pl[i]);
-                        PropertyDefinitionImpl propdef;
-                        if (pi)
-                        {
-                            propdef = pi->getPropertyDefinition();
-                            if (!(propdef.isElement))
-                            {
-                                continue;
-                            }
-                        }
+                writeDOElements(dataObject, pl, 0, openPropIndex);
+                writeDOElements(dataObject, pl, nDefinedProps, nOpenProps );
+                writeDOElements(dataObject, pl, openPropIndex, nDefinedProps - openPropIndex);
+
+            }
+            // End - non-sequenced DO
+            // ----------------------
+
+            rc = xmlTextWriterEndElement(writer);
+            return rc;
 
-                        // -------------------------------------------------
-                        // For a many-valued property get the list of values
-                        if (pl[i].isMany())
+        } // End - writeDO
+
+        void SDOXMLWriter::writeDOElements(DataObjectPtr dataObject,
+                                 const PropertyList& pl,
+                                 unsigned int start,
+                                 unsigned int number)
+        {
+            for (unsigned int pi = 0; pi < number; pi++)
+            {
+                unsigned int i = start + pi;
+                if (dataObject->isSet(pl[i]))
+                {
+                    SDOXMLString propertyName;
+                    SDOXMLString propertyTypeURI;
+
+                    // This call sets the property name and type URI and returns if xsi:type= is required
+                    bool xsiTypeNeeded = determineNamespace(dataObject, pl[i], propertyTypeURI, propertyName);
+
+                    const Type& propertyType = pl[i].getType();
+                    XSDPropertyInfo* pi = getPropertyInfo(pl[i]);
+                    PropertyDefinitionImpl propdef;
+                    if (pi)
+                    {
+                        propdef = pi->getPropertyDefinition();
+                        if (!(propdef.isElement))
                         {
-                            DataObjectList& dol = dataObject->getList(pl[i]);
-                            for (unsigned int j = 0; j <dol.size(); j++)
-                            {
-                                // Handle non-containment reference to DataObject
-                                if (pl[i].isReference() )
-                                {
-                                    writeReference(propertyName, dataObject, pl[i], true, dol[j]);
-                                }
-                                else
-                                {    
-                                    writeDO(dol[j], propertyTypeURI, propertyName, xsiTypeNeeded);
-                                }
-                            }
-                        } 
-                        // End - write many valued property
-                        // --------------------------------
+                            continue;
+                        }
+                    }
 
-                        
-                        // -----------------------------
-                        // For a dataobject write the do
-                        else if (!propertyType.isDataType())
+                    // -------------------------------------------------
+                    // For a many-valued property get the list of values
+                    if (pl[i].isMany())
+                    {
+                        DataObjectList& dol = dataObject->getList(pl[i]);
+                        for (unsigned int j = 0; j <dol.size(); j++)
                         {
                             // Handle non-containment reference to DataObject
-                            if (pl[i].isReference())
+                            if (pl[i].isReference() )
                             {
-                                if (pi)
-                                    writeReference(propertyName, dataObject, pl[i], true);
+                                writeReference(propertyName, dataObject, pl[i], true, dol[j]);
                             }
                             else
-                            {
-                                DataObjectPtr propDO = dataObject->getDataObject(pl[i]);                
-                                writeDO(propDO, propertyTypeURI, propertyName, xsiTypeNeeded);
+                            {    
+                                writeDO(dol[j], propertyTypeURI, propertyName, xsiTypeNeeded);
                             }
                         }
-                        // End - write DataObject
-                        // ----------------------
+                    } 
+                    // End - write many valued property
+                    // --------------------------------
 
-                        
-                        // ---------------
-                        // For a primitive
-                        else
+
+                    // -----------------------------
+                    // For a dataobject write the do
+                    else if (!propertyType.isDataType())
+                    {
+                        // Handle non-containment reference to DataObject
+                        if (pl[i].isReference())
                         {
-                            // Only write a primitive as an element if defined by the XSD
                             if (pi)
+                                writeReference(propertyName, dataObject, pl[i], true);
+                        }
+                        else
+                        {
+                            DataObjectPtr propDO = dataObject->getDataObject(pl[i]);                
+                            writeDO(propDO, propertyTypeURI, propertyName, xsiTypeNeeded);
+                        }
+                    }
+                    // End - write DataObject
+                    // ----------------------
+
+
+                    // ---------------
+                    // For a primitive
+                    else
+                    {
+                        // Only write a primitive as an element if defined by the XSD
+                        if (pi)
+                        {
+                            const Type& tp = dataObject->getType();
+                            XSDTypeInfo* typeInfo = (XSDTypeInfo*)
+                                ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo");
+                            if (typeInfo && typeInfo->getTypeDefinition().isExtendedPrimitive)
                             {
-                                const Type& tp = dataObject->getType();
-                                XSDTypeInfo* typeInfo = (XSDTypeInfo*)
-                                    ((DASType*)&tp)->getDASValue("XMLDAS::TypeInfo");
-                                if (typeInfo && typeInfo->getTypeDefinition().isExtendedPrimitive)
-                                {
-                                    xmlTextWriterWriteRaw(
+                                xmlTextWriterWriteRaw(
                                     writer,
                                     SDOXMLString(dataObject->getCString(pl[i])));
+                            }
+                            else
+                            {
+                                xmlTextWriterStartElementNS(writer, NULL, propertyName, NULL);
+                                if (dataObject->isNull(pl[i]))
+                                {
+                                    xmlTextWriterWriteAttributeNS(writer, s_xsi, s_nil, NULL, s_true);
                                 }
                                 else
                                 {
-                                    rc = xmlTextWriterStartElementNS(writer, NULL, propertyName, NULL);
-                                    if (dataObject->isNull(pl[i]))
-                                    {
-                                        rc = xmlTextWriterWriteAttributeNS(writer, s_xsi, s_nil, NULL, s_true);
-                                    }
-                                    else
-                                    {
-                                        writeXMLElement(writer,
-                                            propertyName,
-                                            dataObject->getCString(pl[i]));
-                                    }
-                                    rc = xmlTextWriterEndElement(writer);
+                                    writeXMLElement(writer,
+                                        propertyName,
+                                        dataObject->getCString(pl[i]));
                                 }
+                                xmlTextWriterEndElement(writer);
                             }
                         }
-                        // End - handle primitive
-                        // ----------------------
-
-                    } // end isSet
-                }
-                // End - elements are written
-                // --------------------------
+                    }
+                    // End - handle primitive
+                    // ----------------------
 
+                } // end isSet
             }
-            // End - non-sequenced DO
-            // ----------------------
-
-            rc = xmlTextWriterEndElement(writer);
-            return rc;
-
-        } // End - writeDO
+            // End - elements are written
+            // --------------------------
 
+        }
 
-        
         XSDPropertyInfo* SDOXMLWriter::getPropertyInfo(const Property& property)
         {
             return (XSDPropertyInfo*)((DASProperty*)&property)->getDASValue("XMLDAS::PropertyInfo");       

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.h?view=diff&rev=546667&r1=546666&r2=546667
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOXMLWriter.h Tue Jun 12 16:26:38 2007
@@ -84,7 +84,9 @@
                 ChangeSummaryPtr cs);
 
             void addToNamespaces(DataObjectImpl* dob);
- 
+
+            void addNamespace(const SDOXMLString& uri, bool tns=false);
+
             int writeDO(
                 DataObjectPtr dataObject,
                 const SDOXMLString& elementURI,
@@ -92,6 +94,11 @@
                 bool writeXSIType = false,
                 bool isRoot = false);
 
+            void writeDOElements(DataObjectPtr dataObject,
+                                 const PropertyList& pl,
+                                 unsigned int start,
+                                 unsigned int number);
+
             /**
              * A wrapper for the libxml2 function xmlTextWriterWriteElement
              * it detects CDATA sections before wrting out element contents
@@ -105,7 +112,6 @@
 
             XSDPropertyInfo* getPropertyInfo(const Property& property);
             
-            int spacescount;
             std::map<SDOXMLString,SDOXMLString> namespaceMap;
             SDOXMLString tnsURI;
            
@@ -126,6 +132,12 @@
             static const SDOXMLString s_xsiNS;
             static const SDOXMLString s_xmlns;
             static const SDOXMLString s_commonjsdo;
+            static const SDOXMLString s_wsdl;
+            static const SDOXMLString s_wsdluri;
+            static const SDOXMLString s_soap;
+            static const SDOXMLString s_soapuri;
+            static const SDOXMLString s_http;
+            static const SDOXMLString s_httpuri;
 
         };
     } // End - namespace sdo

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp?view=diff&rev=546667&r1=546666&r2=546667
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp Tue Jun 12 16:26:38 2007
@@ -117,8 +117,7 @@
          bool isRestriction) 
      {
         init(uri,inname,isSeq,isOp, isAbs, isData);
-        baseType = (TypeImpl*)base;
-        brestriction = isRestriction;
+        setBaseType(base, isRestriction);
         bFromList = false;
      }
 
@@ -149,6 +148,7 @@
         changeSummaryType = false;
         isSequenced = isSeq;
         isOpen = isOp;
+        isOpenImplicitly = false;
         isAbstract = isAbs;
         isPrimitive = isData;
         name = new char[strlen(inname)+1];
@@ -238,6 +238,7 @@
     void TypeImpl::setOpen(bool set) 
     {
           isOpen = set;
+          isOpenImplicitly = false; // explicitly set as open
     }
 
     bool TypeImpl::isBaseTypeOf(const Type* type) const
@@ -289,9 +290,10 @@
         isSequenced = baseType->isSequenced; 
 
         // if the base is open then this type must be open too.
-        if (baseType->isOpenType())
+        if (baseType->isOpenType() && !isOpen)
         {
             isOpen = true;
+            isOpenImplicitly = true;
         }
     }
 
@@ -309,6 +311,11 @@
         return (Type*)baseType;
     }
 
+    const TypeImpl* TypeImpl::getBaseTypeImpl() const 
+    {
+        return baseType;
+    }
+
     ///////////////////////////////////////////////////////////////////////////
     // Returns the name of the type.
     ///////////////////////////////////////////////////////////////////////////
@@ -794,6 +801,11 @@
     {
         /* TODO - handle open types */
           return isOpen;
+    }
+ 
+    bool TypeImpl::isOpenTypeImplicitly() const
+    {
+        return isOpenImplicitly;
     }
 
     ///////////////////////////////////////////////////////////////////////////

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.h?view=diff&rev=546667&r1=546666&r2=546667
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.h Tue Jun 12 16:26:38 2007
@@ -214,6 +214,9 @@
     bool isOpenType() const;
     void setOpen(bool set);
 
+    // Returns true if Type is Open only because it's base Type is open
+    bool isOpenTypeImplicitly() const;
+
     ///////////////////////////////////////////////////////////////////////////
     // Indicates if this type may not be instantiated.
     ///////////////////////////////////////////////////////////////////////////
@@ -225,6 +228,7 @@
     ///////////////////////////////////////////////////////////////////////////
     void setBaseType(const Type* tb, bool isRestriction = false);
     const Type* getBaseType() const;
+    const TypeImpl* getBaseTypeImpl() const;
 
 
     ///////////////////////////////////////////////////////////////////////////
@@ -242,7 +246,7 @@
     ///////////////////////////////////////////////////////////////////////////
     void addChangeSummary();
 
-    ///////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////
     // Say if this type is allowed to have a summary
     ///////////////////////////////////////////////////////////////////////////
     bool isChangeSummaryType() const;
@@ -309,6 +313,7 @@
     bool isPrimitive;
     bool isSequenced;
     bool isOpen;
+    bool isOpenImplicitly;
     bool isAbstract;
 
     // baseType properties included



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