Tuscany SDO 中的Bug 续

阅读更多

下面是测试用例:

//从schema文件和xml文件反序列化成一个SDO对象

DataObjectPtr generateSDOFromFile(const char* xsdFileUri, const char* xmlFileUri,const char* nameSpace = "")

{    

      DataObjectPtr root=NULL;

      try          

      {            

             DataFactoryPtr mdg=DataFactory::getDataFactory();

             XSDHelperPtr xsdHelper=HelperProvider::getXSDHelper(mdg);

             string rootTypeURI = xsdHelper->defineFile(xsdFileUri);

 

             XMLHelperPtr xmlHelper = HelperProvider::getXMLHelper(mdg);

             XMLDocumentPtr xmlDoc=xmlHelper->loadFile(xmlFileUri,nameSpace);              

             root=xmlDoc->getRootDataObject();          

      }

      catch(SDORuntimeException e)

      {

             cout << "Exception in generateSDOFromFile"<< endl;           

      }

      catch(…)

{

             cout<<”…Exception in generateSDOFromFile”<getDataFactory();

             XSDHelperPtr xsdHelper = HelperProvider::getXSDHelper(mdg);

             TypeList tList = mdg->getTypes( );

 

             cout<<"generateXsdFile: before generateFile"<generateFile(tList,xsdFileUri,targetNamespace);

 

             cout<<"generateXsdFile: before generateFile"<

  

  

             

             

             

             

                                           

             

             

             

 

*/

 

//-------------generatedCompany2.xsd (使用原始的tuscany_sdo.dll)

/*



















 

*/

 

 

//----------company2.xml

/*





ename



*/

//----------generatedCompany2.xml

/*





ename



*/

 

 

 

 

3.4 解决方案

前后两个schema文件不一致的原因是在从shema文件构造SDO对象时,遇到attribute,构造成的propertybisContainment属性没有重置为false,该属性的默认值为true。所以在从这个SDO对象生成schema文件时,property会被构造为element,而不是attribute

在补丁程序中,只要在从attribute构造SDO对象的property时,将其bisContainment属性设为false即可。

下面是更正的方法,只在语句thisProperty.isElement = false;后添加了thisProperty.isContainment = false;语句:

void SDOSchemaSAX2Parser::startAttribute(

            const SDOXMLString& localname,

            const SDOXMLString& prefix,

            const SDOXMLString& URI,

            const SAX2Namespaces& namespaces,

            const SAX2Attributes& attributes)

        {

 

            LOGINFO_1( INFO,"SchemaParser:startAttribute:%s",(const char*)localname);

 

            if (!bInSchema) return;

 

            PropertyDefinitionImpl thisProperty;

           

            thisProperty.isElement = false;

            thisProperty.isContainment = false;   //!!!!!! new added. The default value of isContaintment is true.   !!!!!!

           

            setName(attributes,

                thisProperty.name,

                thisProperty.localname);

 

            thisProperty.namespaceURI = schemaInfo.getTargetNamespaceURI();

 

            setType(thisProperty, attributes, namespaces);

           

            setCurrentProperty(thisProperty);                   

        }

 

使用改正后的tuscany_sdo构造的shcema文件为:

//-------------generatedCompany2.xsd (使用改正后的 tuscany_sdo.dll)

/*



















*/

 

 

 

这就与原来的company2.xsd文件保持一致了。

你可能感兴趣的:(XML)