tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gw...@apache.org
Subject svn commit: r492097 - in /incubator/tuscany/cpp/sdo/runtime/core: src/commonj/sdo/ParserErrorSetter.h src/commonj/sdo/SDOSchemaSAX2Parser.cpp src/commonj/sdo/SDOSchemaSAX2Parser.h src/commonj/sdo/XSDHelperImpl.cpp test/order2.txt
Date Wed, 03 Jan 2007 10:26:04 GMT
Author: gwinn
Date: Wed Jan  3 02:26:04 2007
New Revision: 492097

URL: http://svn.apache.org/viewvc?view=rev&rev=492097
Log:
TUSCANY-990

Modified:
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/ParserErrorSetter.h
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h
    incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp
    incubator/tuscany/cpp/sdo/runtime/core/test/order2.txt

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/ParserErrorSetter.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/ParserErrorSetter.h?view=diff&rev=492097&r1=492096&r2=492097
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/ParserErrorSetter.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/ParserErrorSetter.h Wed Jan  3
02:26:04 2007
@@ -27,10 +27,28 @@
 #include "commonj/sdo/disable_warn.h"
 
 #include <vector>
+#include <map>
+#include "libxml/xmlstring.h"
 
 namespace commonj{
 namespace sdo{
 
+template<class _Kty>
+struct HashCompare
+{
+    bool operator()(const _Kty& _Keyval1, const _Kty& _Keyval2) const
+    {
+        return strcmp((char*)_Keyval1, (char*)_Keyval2) < 0;
+    }
+};
+
+class SDOSchemaSAX2Parser;
+typedef std::map<xmlChar*, SDOSchemaSAX2Parser*, HashCompare<xmlChar*> > LocationParserMap;
+struct ParsedLocations: public LocationParserMap
+{
+    virtual ~ParsedLocations();
+};
+
 /**
  * The ParserErrorSetter builds a list of all the errors which 
  * occurred during a parse, so they can be displayed for the
@@ -43,6 +61,10 @@
     virtual ~ParserErrorSetter();
     virtual void setError(const char* message) = 0;
     virtual void clearErrors() = 0;
+
+    SDOSchemaSAX2Parser* parseIfNot(const void* location, bool loadImportNamespace = false,
const void* base=0);
+protected:
+    ParsedLocations parsedLocations;
 };
 };
 };

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp?view=diff&rev=492097&r1=492096&r2=492097
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.cpp Wed Jan
 3 02:26:04 2007
@@ -532,70 +532,37 @@
 
         }
         
-        // ============================================================================
-        // used by startInclude to try to locate the file 
-        // ============================================================================
-
-        int SDOSchemaSAX2Parser::startSecondaryParse(
-                                SDOSchemaSAX2Parser& schemaParser,
-                                SDOXMLString& schemaLocation)
+        void SDOSchemaSAX2Parser::free(xmlChar* absoluteUri)
         {
-            int i,j,k;
-            SDOXMLString sl = getCurrentFile();
-          
-            i = sl.lastIndexOf('/');
-            j = sl.lastIndexOf('\\');
-            if ((j > i) || (i < 0))i=j;
-            if (i>=0)
-            {
-                sl = sl.substring(0,i+1) + schemaLocation;
-                try {
-                     if (-1 != schemaParser.parse((const char *)sl))
-                         return 1;
-                }
-                catch (SDORuntimeException e)
-                {
-                }
-                k = schemaLocation.lastIndexOf('/');
-                j = schemaLocation.lastIndexOf('\\');
-                if ((j > k) || (k < 0))k=j;
-                if (k>=0)
-                {
-                    sl = sl.substring(0,i+1) + schemaLocation.substring(0,k+1);
-                    try {
-                        if (-1 != schemaParser.parse((const char *)sl))
-                             return 1;
-                    }
-                    catch (SDORuntimeException e)
-                    {
-                    }
-                }
-            }
-            try {
-                if (-1 != schemaParser.parse((const char *)schemaLocation))
-                    return 1;
-            }
-            catch (SDORuntimeException e)
-            {
-            }
-            k = schemaLocation.lastIndexOf('/');
-            j = schemaLocation.lastIndexOf('\\');
-            if ((j > k) || (k < 0))k=j;
-            if (k>=0)
+            delete &schemaInfo;
+            delete this;
+            xmlFree(absoluteUri);
+        }
+        ParsedLocations::~ParsedLocations()
+        {
+            for( iterator iter = begin(); iter != end(); iter++ )
+                iter->second->free(iter->first);
+        }
+        SDOSchemaSAX2Parser* ParserErrorSetter::parseIfNot(const void* location, bool loadImportNamespace,
const void* base)
+        {
+            xmlChar*const absoluteUri = xmlBuildURI((xmlChar*)location, (xmlChar*)base);
+            LocationParserMap::iterator iter = parsedLocations.find(absoluteUri);
+            if (parsedLocations.end() == iter)
             {
-                sl = schemaLocation.substring(0,k+1);
-                try {
-                    if (-1 != schemaParser.parse((const char *)sl))
-                        return 1;
-                }
-                catch (SDORuntimeException e)
-                {
-                }
+                SDOSchemaSAX2Parser*const schemaParser = new SDOSchemaSAX2Parser(*new SchemaInfo(),
this, loadImportNamespace);
+			    try {
+				    if (0 == schemaParser->parse((char*)absoluteUri))
+                        return parsedLocations[ absoluteUri ] = schemaParser;
+                }
+			    catch (SDORuntimeException e)
+			    {}
+                schemaParser->free(absoluteUri);
+                return 0;
             }
-            return 0;
+            xmlFree(absoluteUri);
+            return iter->second;
         }
 
-
         // ============================================================================
         // startInclude
         // ============================================================================
@@ -610,24 +577,16 @@
 
             if (!bInSchema) return;
 
-            SchemaInfo schemaInf;
-            SDOSchemaSAX2Parser schemaParser(schemaInf, (ParserErrorSetter*)setter);
-            
             TypeDefinitionsImpl* typedefs;
 
-            SDOXMLString schemaLocation = attributes.getValue("schemaLocation");
             SDOXMLString importNamespace = attributes.getValue("namespace");
+            SDOXMLString schemaLocation = attributes.getValue("schemaLocation");
             if (!schemaLocation.isNull())
             {
-                if (startSecondaryParse(schemaParser,schemaLocation) == 0)
-                {
-                    //
-                    // we were not able to start the parse
+                SDOSchemaSAX2Parser*const schemaParser = setter->parseIfNot((const char*)schemaLocation,
false, getCurrentFile());
+                if (!schemaParser)
                     return;
-                }
-
-                typedefs = &schemaParser.getTypeDefinitions();
-
+                typedefs = &schemaParser->getTypeDefinitions();
             }
             else
             {
@@ -636,17 +595,10 @@
                     && localname.equalsIgnoreCase("import")
                     && !importNamespace.isNull())
                 {
-                    try
-                    {
-                        SDOSchemaSAX2Parser sp(schemaInf, 0);
-
-                        sp.parse(importNamespace);
-                        typedefs = &sp.getTypeDefinitions();
-                    }
-                    catch (SDORuntimeException&)
-                    {
+                    SDOSchemaSAX2Parser*const sp = setter->parseIfNot((const char*)importNamespace);
+                    if (!sp)
                         return;
-                    }
+                    typedefs = &sp->getTypeDefinitions();
                 }
                 else
                 {

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h?view=diff&rev=492097&r1=492096&r2=492097
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDOSchemaSAX2Parser.h Wed Jan 
3 02:26:04 2007
@@ -84,6 +84,7 @@
             friend std::istream& operator>>(std::istream& input, SDOSchemaSAX2Parser&
parser);
             friend std::istringstream& operator>>(std::istringstream& input,
SDOSchemaSAX2Parser& parser);
 
+            void free(xmlChar* absoluteUri);
 
         private:
 
@@ -118,10 +119,6 @@
                                 const SDOXMLString& URI
                                 );
 
-            virtual int    startSecondaryParse(
-                                SDOSchemaSAX2Parser& schemaParser,
-                                SDOXMLString& schemaLocation);
-
             virtual void startInclude(
                 const SDOXMLString& localname,
                 const SDOXMLString& prefix,
@@ -213,7 +210,6 @@
             
             
             SchemaInfo& schemaInfo;
-            
             
             PropertyDefinitionImpl currentProperty;
             std::stack<PropertyDefinitionImpl>    propertyStack;

Modified: incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp?view=diff&rev=492097&r1=492096&r2=492097
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/XSDHelperImpl.cpp Wed Jan  3 02:26:04
2007
@@ -79,27 +79,18 @@
 
         const char* XSDHelperImpl::defineFile(const char* schema, bool loadImportNamespace)
         {
-
-            SDOSchemaSAX2Parser schemaParser(schemaInfo, this, loadImportNamespace);
             clearErrors();
-            if (schemaParser.parse(schema) == 0)
+            SDOSchemaSAX2Parser*const schemaParser = parseIfNot(schema, loadImportNamespace);
+            if (schemaParser)
             {
-                defineTypes(schemaParser.getTypeDefinitions());
-                return schemaInfo.getTargetNamespaceURI();
+                defineTypes(schemaParser->getTypeDefinitions());
+                return schemaParser->getTargetNamespaceURI();
             }
             return 0;
         }
         const char* XSDHelperImpl::defineFile(const SDOString& schema, bool loadImportNamespace)
         {
-
-            SDOSchemaSAX2Parser schemaParser(schemaInfo, this, loadImportNamespace);
-            clearErrors();
-            if (schemaParser.parse(schema.c_str()) == 0)
-            {
-                defineTypes(schemaParser.getTypeDefinitions());
-                return schemaInfo.getTargetNamespaceURI();
-            }
-            return 0;
+            return defineFile(schema.c_str(), loadImportNamespace);
         }
         
         const char*  XSDHelperImpl::define(std::istream& schema, bool loadImportNamespace)

Modified: incubator/tuscany/cpp/sdo/runtime/core/test/order2.txt
URL: http://svn.apache.org/viewvc/incubator/tuscany/cpp/sdo/runtime/core/test/order2.txt?view=diff&rev=492097&r1=492096&r2=492097
==============================================================================
--- incubator/tuscany/cpp/sdo/runtime/core/test/order2.txt (original)
+++ incubator/tuscany/cpp/sdo/runtime/core/test/order2.txt Wed Jan  3 02:26:04 2007
@@ -11,7 +11,6 @@
 Property:value
 Property:zip
 Type:#fullpersoninfo
-Property:value
 Property:address
 Property:city
 Property:country



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


Mime
View raw message