0024925: Enabling OCAF persistence without setting environment variables
authorRoman Lygin <roman.lygin@gmail.com>
Thu, 10 Jul 2014 10:47:20 +0000 (14:47 +0400)
committerapn <apn@opencascade.com>
Thu, 10 Jul 2014 10:48:55 +0000 (14:48 +0400)
Add test case bugs/caf/bug24925
Merging with current master IR-2014-07-03

14 files changed:
src/CDF/CDF.cdl
src/CDF/CDF_FWOSDriver.cdl [new file with mode: 0644]
src/CDF/CDF_FWOSDriver.cxx [new file with mode: 0644]
src/CDF/CDF_Session.cxx
src/FWOSDriver/FWOSDriver.cdl
src/FWOSDriver/FWOSDriver_Driver.cdl [deleted file]
src/FWOSDriver/FWOSDriver_Driver.cxx [deleted file]
src/FWOSDriver/FWOSDriver_DriverFactory.cxx
src/Plugin/Plugin.cdl
src/Plugin/Plugin.cxx
src/QABugs/QABugs_19.cxx
src/TDocStd/TDocStd_Application.cdl
src/TDocStd/TDocStd_Application.cxx
tests/bugs/caf/bug24925 [new file with mode: 0644]

index e9ffe73b08706f0531eca6fee734fecdacee3570..d03adbc6fad647df8f3b20b1af117d7229bee501 100644 (file)
@@ -56,6 +56,9 @@ is
 
     deferred class MetaDataDriver;
 
+    class FWOSDriver;
+
+
     exception MetaDataDriverError inherits Failure from Standard;
     ---Purpose: this exception is used in the deferred methods.
     --          Programmer implementing such methods may use this
diff --git a/src/CDF/CDF_FWOSDriver.cdl b/src/CDF/CDF_FWOSDriver.cdl
new file mode 100644 (file)
index 0000000..1bf7d4d
--- /dev/null
@@ -0,0 +1,68 @@
+-- Created on: 1997-01-22
+-- Created by: Mister rmi
+-- Copyright (c) 1997-1999 Matra Datavision
+-- Copyright (c) 1999-2014 OPEN CASCADE SAS
+--
+-- This file is part of Open CASCADE Technology software library.
+--
+-- This library is free software; you can redistribute it and/or modify it under
+-- the terms of the GNU Lesser General Public License version 2.1 as published
+-- by the Free Software Foundation, with special exception defined in the file
+-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+-- distribution for complete text of the license and disclaimer of any warranty.
+--
+-- Alternatively, this file may be used under the terms of Open CASCADE
+-- commercial license or contractual agreement.
+
+class FWOSDriver from CDF  inherits MetaDataDriver from CDF
+uses
+    MetaData from CDM,
+    Document from CDM,
+    ExtendedString from TCollection
+is
+    Create
+    returns FWOSDriver from CDF;
+    ---Purpose: initializes the MetaDatadriver with its specific name.
+
+
+       
+    Find(me: mutable; aFolder, aName, aVersion: ExtendedString from TCollection)
+    returns Boolean from Standard;
+    ---Purpose: indicate whether a file exists corresponding to the folder and the name
+    
+    HasReadPermission(me: mutable; aFolder, aName, aVersion: ExtendedString from TCollection)
+    returns Boolean from Standard;
+
+    
+    MetaData(me: mutable; aFolder, aName, aVersion: ExtendedString from TCollection)
+    returns MetaData from CDM
+    is  private;
+    
+    CreateMetaData(me: mutable; aDocument: Document from CDM;
+                aFileName: ExtendedString from TCollection)
+    returns  MetaData from CDM
+    is  private;
+    
+    FindFolder(me: mutable; aFolder: ExtendedString from TCollection)
+    returns Boolean from Standard;
+
+
+   DefaultFolder(me: mutable) returns ExtendedString from TCollection;
+   
+   BuildFileName(me: mutable; aDocument: Document from CDM)
+   returns ExtendedString from TCollection;
+    
+   Concatenate(myclass; aFolder,aName:  ExtendedString from TCollection)
+   returns ExtendedString from TCollection
+   is private;
+
+
+   BuildMetaData(me: mutable; aFileName: ExtendedString from TCollection)
+   returns MetaData from CDM
+   is  private;
+
+   SetName(me: mutable; aDocument: Document from CDM; aName: ExtendedString from TCollection)
+   returns ExtendedString from TCollection
+   is redefined;
+   
+end FWOSDriver from CDF;
diff --git a/src/CDF/CDF_FWOSDriver.cxx b/src/CDF/CDF_FWOSDriver.cxx
new file mode 100644 (file)
index 0000000..434c6f7
--- /dev/null
@@ -0,0 +1,255 @@
+// Copyright (c) 1999-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+#include <CDF_FWOSDriver.ixx>
+#include <TCollection_ExtendedString.hxx>
+#include <OSD_Path.hxx>
+#include <OSD_Directory.hxx>
+#include <OSD_Protection.hxx>
+#include <OSD_SingleProtection.hxx>
+#include <OSD_File.hxx>
+#include <OSD_FileNode.hxx>
+#include <UTL.hxx>
+#include <TCollection_ExtendedString.hxx>
+#ifdef WNT
+#include <tchar.h>
+#endif  // WNT
+
+
+//==============================================================================
+//function : PutSlash
+//purpose  :
+//==============================================================================
+static void PutSlash (TCollection_ExtendedString& anXSTRING) {
+#ifdef WNT
+  anXSTRING+="\\";
+#else
+  anXSTRING+="/";
+#endif  // WNT
+}
+
+//==============================================================================
+//function : CDF_FWOSDriver
+//purpose  :
+//==============================================================================
+CDF_FWOSDriver::CDF_FWOSDriver() {}
+
+//==============================================================================
+//function : Find
+//purpose  :
+//==============================================================================
+Standard_Boolean CDF_FWOSDriver::Find(const TCollection_ExtendedString& aFolder,
+                                         const TCollection_ExtendedString& aName,
+                                         const TCollection_ExtendedString& /*aVersion*/)
+{
+
+  OSD_Path thePath=UTL::Path(aFolder);
+  OSD_Directory theDirectory(thePath);
+  if(theDirectory.Exists()) {
+    TCollection_ExtendedString f(aFolder);
+    PutSlash(f);
+    f+=aName;
+    OSD_Path p2 = UTL::Path(f);
+    OSD_File theFile(p2);
+    return theFile.Exists();
+  }
+  return Standard_False;
+}
+
+//==============================================================================
+//function : HasReadPermission
+//purpose  :
+//==============================================================================
+Standard_Boolean CDF_FWOSDriver::HasReadPermission(const TCollection_ExtendedString& aFolder,
+                                                      const TCollection_ExtendedString& aName,
+                                                      const TCollection_ExtendedString& /*aVersion*/)
+{
+  OSD_SingleProtection theProtection=OSD_File(UTL::Path(Concatenate(aFolder,aName))).Protection().User();
+  switch (theProtection) {
+    case OSD_None:
+    case OSD_R:
+    case OSD_RW:
+    case OSD_RX:
+    case OSD_WX:
+    case OSD_RWX:
+    case OSD_RD:
+    case OSD_RWD:
+    case OSD_RXD:
+    case OSD_RWXD:
+      return Standard_True;
+    default:
+      return Standard_False;
+    }
+}
+
+//==============================================================================
+//function : MetaData
+//purpose  :
+//==============================================================================
+Handle(CDM_MetaData) CDF_FWOSDriver::MetaData(const TCollection_ExtendedString& aFolder,
+                                                 const TCollection_ExtendedString& aName,
+                                                 const TCollection_ExtendedString& /*aVersion*/)
+{
+  TCollection_ExtendedString p = Concatenate(aFolder,aName);
+  return CDM_MetaData::LookUp(aFolder,aName,p,p,UTL::IsReadOnly(p));
+}
+
+//==============================================================================
+//function : CreateMetaData
+//purpose  :
+//==============================================================================
+Handle(CDM_MetaData) CDF_FWOSDriver::CreateMetaData(const Handle(CDM_Document)& aDocument,
+                                                       const TCollection_ExtendedString& aFileName)
+{
+  return CDM_MetaData::LookUp(aDocument->RequestedFolder(),aDocument->RequestedName(),
+                              Concatenate(aDocument->RequestedFolder(),aDocument->RequestedName()),
+                              aFileName,UTL::IsReadOnly(aFileName));
+}
+
+//==============================================================================
+//function : BuildFileName
+//purpose  :
+//==============================================================================
+TCollection_ExtendedString CDF_FWOSDriver::BuildFileName(const Handle(CDM_Document)& aDocument)
+{
+
+  TCollection_ExtendedString retstr = TCollection_ExtendedString(aDocument->RequestedFolder());
+  PutSlash(retstr);
+  retstr += aDocument->RequestedName();
+  return retstr;
+}
+
+//==============================================================================
+//function : FindFolder
+//purpose  :
+//==============================================================================
+Standard_Boolean CDF_FWOSDriver::FindFolder(const TCollection_ExtendedString& aFolder)
+{
+  
+  OSD_Path thePath=UTL::Path(aFolder);
+  OSD_Directory theDirectory(thePath);
+  return theDirectory.Exists();
+}
+
+//==============================================================================
+//function : Concatenate
+//purpose  :
+//==============================================================================
+TCollection_ExtendedString CDF_FWOSDriver::Concatenate(const TCollection_ExtendedString& aFolder,
+                                                          const TCollection_ExtendedString& aName)
+{
+  TCollection_ExtendedString ff(aFolder);
+  ff = "";
+  ff += aFolder;
+  PutSlash(ff);
+  ff+=aName;
+  return ff;
+}
+
+//==============================================================================
+//function : DefaultFolder
+//purpose  :
+//==============================================================================
+TCollection_ExtendedString CDF_FWOSDriver::DefaultFolder()
+{
+  TCollection_ExtendedString theDefaultFolder;
+  if (theDefaultFolder.Length() == 0) {
+    
+#ifdef WNT
+    TCollection_ExtendedString hd=UTL::xgetenv("HOMEDRIVE");
+    if(hd.Length() != NULL) {
+      theDefaultFolder=hd;
+      theDefaultFolder+=UTL::xgetenv("HOMEPATH");
+    }
+    else {
+      theDefaultFolder=UTL::xgetenv("TEMP");
+      if(theDefaultFolder.Length()==0)
+        Standard_Failure::Raise("cannot determine default folder; HOMEDRIVE and TEMP are undefined");
+    }
+#else
+    TCollection_ExtendedString home=UTL::xgetenv("HOME");
+    if(home.Length() !=0)
+      theDefaultFolder =  home;
+    else
+      theDefaultFolder= TCollection_ExtendedString("/tmp");
+#endif
+  }
+  return theDefaultFolder;
+}
+
+//==============================================================================
+//function : BuildMetaData
+//purpose  :
+//==============================================================================
+Handle(CDM_MetaData) CDF_FWOSDriver::BuildMetaData(const TCollection_ExtendedString& aFileName)
+{
+
+  OSD_Path p = UTL::Path(aFileName);
+  
+  TCollection_ExtendedString f = UTL::Trek(p);
+  TCollection_ExtendedString n = UTL::Name(p);
+  n +=".";
+  n += UTL::Extension(p);
+
+  return CDM_MetaData::LookUp(f,n,aFileName,aFileName,UTL::IsReadOnly(aFileName));
+}
+
+//==============================================================================
+//function : SetName
+//purpose  :
+//==============================================================================
+TCollection_ExtendedString CDF_FWOSDriver::SetName(const Handle(CDM_Document)& aDocument,
+                                                      const TCollection_ExtendedString& aName)
+{
+  
+  TCollection_ExtendedString xn(aName), n(aName);
+
+#ifdef WNT
+  //windows is not case sensitive
+  Standard_ExtCharacter   echar;
+  //make the extension lower case
+  for(int i = 1; i <= xn.Length(); i++)
+  {
+       echar = xn.Value(i);
+       echar = towlower(echar);
+       xn.SetValue(i, echar);
+  }
+#endif
+  
+  TCollection_ExtendedString e (aDocument->FileExtension());
+  TCollection_ExtendedString xe(e);
+  if (e.Length() > 0) {
+#ifdef WNT
+    //windows is not case sensitive
+    Standard_ExtCharacter   echar;
+    //make the extension lower case
+    for(int i = 1; i <= xe.Length(); i++)
+    {
+         echar = xe.Value(i);
+         echar = towlower(echar);
+         xe.SetValue(i, echar);
+    }
+#endif
+    xe.Insert(1, '.');
+    e.Insert(1, '.');
+    Standard_Integer ln = xn.Length();
+    Standard_Integer le = xe.Length();
+    Standard_Boolean ExtensionIsAlreadyThere = Standard_False;
+    if(ln>=le) {
+      Standard_Integer ind=xn.SearchFromEnd(xe);
+      ExtensionIsAlreadyThere = ind+le-1==ln;
+    }
+    if(!ExtensionIsAlreadyThere) n+=e;
+  }
+  return n;
+}
index a2eb1174efe655f65abba27873ddc04491721718..3c0089624ae10efaf994977bc1148dd7399bdeaf 100644 (file)
@@ -17,6 +17,7 @@
 #include <CDF_Session.ixx>
 #include <TCollection_ExtendedString.hxx>
 #include <CDF_MetaDataDriverFactory.hxx>
+#include <CDF_FWOSDriver.hxx>
 #include <Plugin.hxx>
 #include <Standard_GUID.hxx>
 #include <PCDM.hxx>
@@ -112,5 +113,18 @@ Handle(CDF_MetaDataDriver) CDF_Session::MetaDataDriver() const {
 //purpose  : 
 //=======================================================================
 void CDF_Session::LoadDriver() {
-   myMetaDataDriver=Handle(CDF_MetaDataDriverFactory)::DownCast(Plugin::Load(Standard_GUID("a148e300-5740-11d1-a904-080036aaa103")))->Build();
+  if (myMetaDataDriver.IsNull()) {
+    Handle(CDF_MetaDataDriverFactory) aFactory;
+    try {
+      aFactory = Handle(CDF_MetaDataDriverFactory)::DownCast (
+        Plugin::Load (Standard_GUID ("a148e300-5740-11d1-a904-080036aaa103"),
+                      Standard_False /*theVerbose*/));
+    } catch (const Standard_Failure&) {
+    }
+    if (!aFactory.IsNull()) {
+      myMetaDataDriver = aFactory->Build();
+    } else {
+      myMetaDataDriver = new CDF_FWOSDriver;
+    }
+  }
 }
index 4b1d0679a84c0ac501e93b16ccf5a06f735edf13..5e863ce6b0288c5854c2267f7bc4bf184987ea38 100644 (file)
@@ -20,7 +20,6 @@ uses
     CDM,CDF,TCollection
 
 is
-    class Driver;
     class DriverFactory;
 
     
diff --git a/src/FWOSDriver/FWOSDriver_Driver.cdl b/src/FWOSDriver/FWOSDriver_Driver.cdl
deleted file mode 100644 (file)
index 2887fb3..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
--- Created on: 1997-01-22
--- Created by: Mister rmi
--- Copyright (c) 1997-1999 Matra Datavision
--- Copyright (c) 1999-2014 OPEN CASCADE SAS
---
--- This file is part of Open CASCADE Technology software library.
---
--- This library is free software; you can redistribute it and/or modify it under
--- the terms of the GNU Lesser General Public License version 2.1 as published
--- by the Free Software Foundation, with special exception defined in the file
--- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
--- distribution for complete text of the license and disclaimer of any warranty.
---
--- Alternatively, this file may be used under the terms of Open CASCADE
--- commercial license or contractual agreement.
-
-class Driver from FWOSDriver  inherits MetaDataDriver from CDF
-uses
-    MetaData from CDM,Document from CDM,
-    ExtendedString from TCollection,
-    ExtendedString from TCollection
-is
-    Create
-    returns Driver from FWOSDriver;
-    ---Purpose: initializes the MetaDatadriver with its specific name.
-
-
-       
-    Find(me: mutable; aFolder, aName, aVersion: ExtendedString from TCollection)
-    returns Boolean from Standard;
-    ---Purpose: indicate whether a file exists corresponding to the folder and the name
-    
-    HasReadPermission(me: mutable; aFolder, aName, aVersion: ExtendedString from TCollection)
-    returns Boolean from Standard;
-
-    
-    MetaData(me: mutable; aFolder, aName, aVersion: ExtendedString from TCollection)
-    returns MetaData from CDM
-    is  private;
-    
-    CreateMetaData(me: mutable; aDocument: Document from CDM;
-                aFileName: ExtendedString from TCollection)
-    returns  MetaData from CDM
-    is  private;
-    
-    FindFolder(me: mutable; aFolder: ExtendedString from TCollection)
-    returns Boolean from Standard;
-
-
-   DefaultFolder(me: mutable) returns ExtendedString from TCollection;
-   
-   BuildFileName(me: mutable; aDocument: Document from CDM)
-   returns ExtendedString from TCollection;
-    
-   Concatenate(myclass; aFolder,aName:  ExtendedString from TCollection)
-   returns ExtendedString from TCollection
-   is private;
-
-
-   BuildMetaData(me: mutable; aFileName: ExtendedString from TCollection)
-   returns MetaData from CDM
-   is  private;
-
-   SetName(me: mutable; aDocument: Document from CDM; aName: ExtendedString from TCollection)
-   returns ExtendedString from TCollection
-   is redefined;
-   
-end Driver from FWOSDriver;
diff --git a/src/FWOSDriver/FWOSDriver_Driver.cxx b/src/FWOSDriver/FWOSDriver_Driver.cxx
deleted file mode 100644 (file)
index e4e9150..0000000
+++ /dev/null
@@ -1,255 +0,0 @@
-// Copyright (c) 1999-2014 OPEN CASCADE SAS
-//
-// This file is part of Open CASCADE Technology software library.
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License version 2.1 as published
-// by the Free Software Foundation, with special exception defined in the file
-// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-// distribution for complete text of the license and disclaimer of any warranty.
-//
-// Alternatively, this file may be used under the terms of Open CASCADE
-// commercial license or contractual agreement.
-
-#include <FWOSDriver_Driver.ixx>
-#include <TCollection_ExtendedString.hxx>
-#include <OSD_Path.hxx>
-#include <OSD_Directory.hxx>
-#include <OSD_Protection.hxx>
-#include <OSD_SingleProtection.hxx>
-#include <OSD_File.hxx>
-#include <OSD_FileNode.hxx>
-#include <UTL.hxx>
-#include <TCollection_ExtendedString.hxx>
-#ifdef WNT
-#include <tchar.h>
-#endif  // WNT
-
-
-//==============================================================================
-//function : PutSlash
-//purpose  :
-//==============================================================================
-static void PutSlash (TCollection_ExtendedString& anXSTRING) {
-#ifdef WNT
-  anXSTRING+="\\";
-#else
-  anXSTRING+="/";
-#endif  // WNT
-}
-
-//==============================================================================
-//function : FWOSDriver_Driver
-//purpose  :
-//==============================================================================
-FWOSDriver_Driver::FWOSDriver_Driver() {}
-
-//==============================================================================
-//function : Find
-//purpose  :
-//==============================================================================
-Standard_Boolean FWOSDriver_Driver::Find(const TCollection_ExtendedString& aFolder,
-                                         const TCollection_ExtendedString& aName,
-                                         const TCollection_ExtendedString& /*aVersion*/)
-{
-
-  OSD_Path thePath=UTL::Path(aFolder);
-  OSD_Directory theDirectory(thePath);
-  if(theDirectory.Exists()) {
-    TCollection_ExtendedString f(aFolder);
-    PutSlash(f);
-    f+=aName;
-    OSD_Path p2 = UTL::Path(f);
-    OSD_File theFile(p2);
-    return theFile.Exists();
-  }
-  return Standard_False;
-}
-
-//==============================================================================
-//function : HasReadPermission
-//purpose  :
-//==============================================================================
-Standard_Boolean FWOSDriver_Driver::HasReadPermission(const TCollection_ExtendedString& aFolder,
-                                                      const TCollection_ExtendedString& aName,
-                                                      const TCollection_ExtendedString& /*aVersion*/)
-{
-  OSD_SingleProtection theProtection=OSD_File(UTL::Path(Concatenate(aFolder,aName))).Protection().User();
-  switch (theProtection) {
-    case OSD_None:
-    case OSD_R:
-    case OSD_RW:
-    case OSD_RX:
-    case OSD_WX:
-    case OSD_RWX:
-    case OSD_RD:
-    case OSD_RWD:
-    case OSD_RXD:
-    case OSD_RWXD:
-      return Standard_True;
-    default:
-      return Standard_False;
-    }
-}
-
-//==============================================================================
-//function : MetaData
-//purpose  :
-//==============================================================================
-Handle(CDM_MetaData) FWOSDriver_Driver::MetaData(const TCollection_ExtendedString& aFolder,
-                                                 const TCollection_ExtendedString& aName,
-                                                 const TCollection_ExtendedString& /*aVersion*/)
-{
-  TCollection_ExtendedString p = Concatenate(aFolder,aName);
-  return CDM_MetaData::LookUp(aFolder,aName,p,p,UTL::IsReadOnly(p));
-}
-
-//==============================================================================
-//function : CreateMetaData
-//purpose  :
-//==============================================================================
-Handle(CDM_MetaData) FWOSDriver_Driver::CreateMetaData(const Handle(CDM_Document)& aDocument,
-                                                       const TCollection_ExtendedString& aFileName)
-{
-  return CDM_MetaData::LookUp(aDocument->RequestedFolder(),aDocument->RequestedName(),
-                              Concatenate(aDocument->RequestedFolder(),aDocument->RequestedName()),
-                              aFileName,UTL::IsReadOnly(aFileName));
-}
-
-//==============================================================================
-//function : BuildFileName
-//purpose  :
-//==============================================================================
-TCollection_ExtendedString FWOSDriver_Driver::BuildFileName(const Handle(CDM_Document)& aDocument)
-{
-
-  TCollection_ExtendedString retstr = TCollection_ExtendedString(aDocument->RequestedFolder());
-  PutSlash(retstr);
-  retstr += aDocument->RequestedName();
-  return retstr;
-}
-
-//==============================================================================
-//function : FindFolder
-//purpose  :
-//==============================================================================
-Standard_Boolean FWOSDriver_Driver::FindFolder(const TCollection_ExtendedString& aFolder)
-{
-  
-  OSD_Path thePath=UTL::Path(aFolder);
-  OSD_Directory theDirectory(thePath);
-  return theDirectory.Exists();
-}
-
-//==============================================================================
-//function : Concatenate
-//purpose  :
-//==============================================================================
-TCollection_ExtendedString FWOSDriver_Driver::Concatenate(const TCollection_ExtendedString& aFolder,
-                                                          const TCollection_ExtendedString& aName)
-{
-  TCollection_ExtendedString ff(aFolder);
-  ff = "";
-  ff += aFolder;
-  PutSlash(ff);
-  ff+=aName;
-  return ff;
-}
-
-//==============================================================================
-//function : DefaultFolder
-//purpose  :
-//==============================================================================
-TCollection_ExtendedString FWOSDriver_Driver::DefaultFolder()
-{
-  TCollection_ExtendedString theDefaultFolder;
-  if (theDefaultFolder.Length() == 0) {
-    
-#ifdef WNT
-    TCollection_ExtendedString hd=UTL::xgetenv("HOMEDRIVE");
-    if(hd.Length() != NULL) {
-      theDefaultFolder=hd;
-      theDefaultFolder+=UTL::xgetenv("HOMEPATH");
-    }
-    else {
-      theDefaultFolder=UTL::xgetenv("TEMP");
-      if(theDefaultFolder.Length()==0)
-        Standard_Failure::Raise("cannot determine default folder; HOMEDRIVE and TEMP are undefined");
-    }
-#else
-    TCollection_ExtendedString home=UTL::xgetenv("HOME");
-    if(home.Length() !=0)
-      theDefaultFolder =  home;
-    else
-      theDefaultFolder= TCollection_ExtendedString("/tmp");
-#endif
-  }
-  return theDefaultFolder;
-}
-
-//==============================================================================
-//function : BuildMetaData
-//purpose  :
-//==============================================================================
-Handle(CDM_MetaData) FWOSDriver_Driver::BuildMetaData(const TCollection_ExtendedString& aFileName)
-{
-
-  OSD_Path p = UTL::Path(aFileName);
-  
-  TCollection_ExtendedString f = UTL::Trek(p);
-  TCollection_ExtendedString n = UTL::Name(p);
-  n +=".";
-  n += UTL::Extension(p);
-
-  return CDM_MetaData::LookUp(f,n,aFileName,aFileName,UTL::IsReadOnly(aFileName));
-}
-
-//==============================================================================
-//function : SetName
-//purpose  :
-//==============================================================================
-TCollection_ExtendedString FWOSDriver_Driver::SetName(const Handle(CDM_Document)& aDocument,
-                                                      const TCollection_ExtendedString& aName)
-{
-  
-  TCollection_ExtendedString xn(aName), n(aName);
-
-#ifdef WNT
-  //windows is not case sensitive
-  Standard_ExtCharacter   echar;
-  //make the extension lower case
-  for(int i = 1; i <= xn.Length(); i++)
-  {
-       echar = xn.Value(i);
-       echar = towlower(echar);
-       xn.SetValue(i, echar);
-  }
-#endif
-  
-  TCollection_ExtendedString e (aDocument->FileExtension());
-  TCollection_ExtendedString xe(e);
-  if (e.Length() > 0) {
-#ifdef WNT
-    //windows is not case sensitive
-    Standard_ExtCharacter   echar;
-    //make the extension lower case
-    for(int i = 1; i <= xe.Length(); i++)
-    {
-         echar = xe.Value(i);
-         echar = towlower(echar);
-         xe.SetValue(i, echar);
-    }
-#endif
-    xe.Insert(1, '.');
-    e.Insert(1, '.');
-    Standard_Integer ln = xn.Length();
-    Standard_Integer le = xe.Length();
-    Standard_Boolean ExtensionIsAlreadyThere = Standard_False;
-    if(ln>=le) {
-      Standard_Integer ind=xn.SearchFromEnd(xe);
-      ExtensionIsAlreadyThere = ind+le-1==ln;
-    }
-    if(!ExtensionIsAlreadyThere) n+=e;
-  }
-  return n;
-}
index 6159c2500e19e2deae4060550a5d65a773bf1070..e62548912424d3d778584d5a0df0d1e6d8981961 100644 (file)
 
 #include <FWOSDriver_DriverFactory.ixx>
 
-#include <FWOSDriver_Driver.hxx>
+#include <CDF_FWOSDriver.hxx>
 FWOSDriver_DriverFactory::FWOSDriver_DriverFactory(){}
 
 
 Handle(CDF_MetaDataDriver) FWOSDriver_DriverFactory::Build() const {
-  static Handle(FWOSDriver_Driver) d =  new FWOSDriver_Driver();
+  static Handle(CDF_FWOSDriver) d =  new CDF_FWOSDriver();
   return d;
 }
index 7ab5e4b1b04ca4553719fddc28a001fe60a90cfe..6f1dc9b27a9306beef25f14eb62f29fc1c7aebcf 100644 (file)
@@ -16,7 +16,9 @@
 
 package Plugin
 
-    uses TCollection,OSD
+    uses TCollection,
+         OSD,
+         Resource
 
 is
 
@@ -25,7 +27,23 @@ is
     class MapOfFunctions instantiates DataMap from TCollection(AsciiString from TCollection ,Function from OSD, AsciiString from TCollection);
 
 
-    Load(aGUID: GUID from Standard) returns Transient from Standard
+    Load(aGUID: GUID from Standard; theVerbose: Boolean from Standard = Standard_True)
+    returns Transient from Standard
     raises Failure  from Plugin;
 
+    AdditionalPluginMap
+    returns Manager from Resource;
+    ---C++    : return const &
+    ---Purpose: Returns a global map of {guid, plugin_library} pairs.
+    --          The Load() method will use this map to search for plugins if and only if
+    --          the GUID is not found in the Plugin file specified by the CSF_PluginDefaults
+    --          (or CSF_PluginUserDefaults) environment variable, or if they are not defined.
+    --
+    --          This allows to populate this additional resource manager
+    --          in run-time and to avoid using the above environment variables.
+    --          This map must be populated (using Resource_Manager::SetResource() method)
+    --          following syntax conventions of the Plugin file, for instance:
+    --          const Handle(Resource_Manager)& aPluginMap = Plugin::AdditionalPluginMap();
+    --          aPluginMap->SetResource ("ad696000-5b34-11d1-b5ba-00a0c9064368.Location", "TKStdSchema");
+
 end Plugin;
index 7093fb5f1d4397d16bef3813684a90bc068ab48f..ab5ab0bf2bad5d7fb1a2cfcbfa866bac2ae5a260 100644 (file)
@@ -30,7 +30,8 @@ static Standard_PCharacter thePluginId = tc;
 //function : Load
 //purpose  : 
 //=======================================================================
-Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID) 
+Handle(Standard_Transient) Plugin::Load (const Standard_GUID& aGUID,
+                                         const Standard_Boolean theVerbose)
 {
   
   aGUID.ToCString(thePluginId);
@@ -45,10 +46,14 @@ Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID)
     theResource += ".Location";
 
     if(!PluginResource->Find(theResource.ToCString())) {
-      Standard_SStream aMsg; aMsg << "could not find the resource:";
-      aMsg << theResource.ToCString()<< endl;
-      cout << "could not find the resource:"<<theResource.ToCString()<< endl;
-      Plugin_Failure::Raise(aMsg);
+      PluginResource = AdditionalPluginMap();
+      if (!PluginResource->Find(theResource.ToCString())) {
+        Standard_SStream aMsg; aMsg << "could not find the resource:";
+        aMsg << theResource.ToCString()<< endl;
+        if (theVerbose)
+            cout << "could not find the resource:"<<theResource.ToCString()<< endl;
+        Plugin_Failure::Raise(aMsg);
+      }
     }
     
     TCollection_AsciiString thePluginLibrary("");
@@ -72,7 +77,8 @@ Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID)
       aMsg << PluginResource->Value(theResource.ToCString());
       aMsg << "; reason:";
       aMsg << error.ToCString();
-      cout << "could not open: "  << PluginResource->Value(theResource.ToCString())<< " ; reason: "<< error.ToCString() << endl;
+      if (theVerbose)
+        cout << "could not open: "  << PluginResource->Value(theResource.ToCString())<< " ; reason: "<< error.ToCString() << endl;
       Plugin_Failure::Raise(aMsg);
     }
     f = theSharedLibrary.DlSymb("PLUGINFACTORY");
@@ -95,3 +101,10 @@ Handle(Standard_Transient) Plugin::Load(const Standard_GUID& aGUID)
   
 }
 
+const Handle(Resource_Manager)& Plugin::AdditionalPluginMap()
+{
+  static Handle(Resource_Manager) aMap;
+  if (aMap.IsNull())
+    aMap = new Resource_Manager ("" /*theName*/, Standard_False /*theVerbose*/);
+  return aMap;
+}
index ba819ad531bb732de7324355062c7f3478fb7705..aa5c34d64b42446d50113f48b132140ce30a1461 100755 (executable)
@@ -2542,6 +2542,105 @@ static Standard_Integer OCC25004 (Draw_Interpretor& theDI,
   return 0;
 }
 
+#include <OSD_Environment.hxx>
+#include <Plugin.hxx>
+#include <Plugin_Macro.hxx>
+#include <Resource_Manager.hxx>
+
+#define THE_QATEST_DOC_FORMAT       "My Proprietary Format"
+
+#define QA_CHECK(theDesc, theExpr, theValue) \
+{\
+  const bool isTrue = !!(theExpr); \
+  std::cout << theDesc << (isTrue ? " TRUE  " : " FALSE ") << (isTrue == theValue ? " is OK\n" : " is FAIL\n"); \
+}
+
+class Test_TDocStd_Application : public TDocStd_Application
+{
+public:
+
+  static void initGlobalPluginMap (const TCollection_AsciiString& thePlugin,
+                                   const TCollection_AsciiString& theSaver,
+                                   const TCollection_AsciiString& theLoader)
+  {
+    const Handle(Resource_Manager)& aManager = Plugin::AdditionalPluginMap();
+    aManager->SetResource ((theSaver  + ".Location").ToCString(), thePlugin.ToCString());
+    aManager->SetResource ((theLoader + ".Location").ToCString(), thePlugin.ToCString());
+  }
+
+  Test_TDocStd_Application (const TCollection_AsciiString& thePlugin,
+                            const TCollection_AsciiString& theSaver,
+                            const TCollection_AsciiString& theLoader)
+  {
+    initGlobalPluginMap (thePlugin, theSaver, theLoader);
+
+    // explicitly initialize resource manager
+    myResources = new Resource_Manager ("");
+    myResources->SetResource ("xml.FileFormat", THE_QATEST_DOC_FORMAT);
+    myResources->SetResource (THE_QATEST_DOC_FORMAT ".Description",     "Test XML Document");
+    myResources->SetResource (THE_QATEST_DOC_FORMAT ".FileExtension",   "xml");
+    myResources->SetResource (THE_QATEST_DOC_FORMAT ".StoragePlugin",   theSaver.ToCString());
+    myResources->SetResource (THE_QATEST_DOC_FORMAT ".RetrievalPlugin", theLoader.ToCString());
+  }
+
+  virtual Standard_CString ResourcesName() { return ""; }
+  virtual void Formats (TColStd_SequenceOfExtendedString& theFormats) { theFormats.Clear(); }
+};
+
+//=======================================================================
+//function : OCC24925
+//purpose  :
+//=======================================================================
+static Standard_Integer OCC24925 (Draw_Interpretor& theDI,
+                                  Standard_Integer  theArgNb,
+                                  const char**      theArgVec)
+{
+  if (theArgNb != 2
+   && theArgNb != 5)
+  {
+    std::cout << "Error: wrong syntax! See usage:\n";
+    theDI.PrintHelp (theArgVec[0]);
+    return 1;
+  }
+
+  Standard_Integer anArgIter = 1;
+  TCollection_ExtendedString aFileName = theArgVec[anArgIter++];
+  TCollection_AsciiString    aPlugin   = "TKXml";
+  TCollection_AsciiString    aSaver    = "03a56820-8269-11d5-aab2-0050044b1af1"; // XmlStorageDriver   in XmlDrivers.cxx
+  TCollection_AsciiString    aLoader   = "03a56822-8269-11d5-aab2-0050044b1af1"; // XmlRetrievalDriver in XmlDrivers.cxx
+  if (anArgIter < theArgNb)
+  {
+    aPlugin = theArgVec[anArgIter++];
+    aSaver  = theArgVec[anArgIter++];
+    aLoader = theArgVec[anArgIter++];
+  }
+
+  PCDM_StoreStatus  aSStatus = PCDM_SS_Failure;
+  PCDM_ReaderStatus aRStatus = PCDM_RS_OpenError;
+
+  Handle(TDocStd_Application) anApp = new Test_TDocStd_Application (aPlugin, aSaver, aLoader);
+  {
+    Handle(TDocStd_Document) aDoc;
+    anApp->NewDocument (THE_QATEST_DOC_FORMAT, aDoc);
+    TDF_Label aLab = aDoc->Main();
+    TDataStd_Integer::Set (aLab, 0);
+    TDataStd_Name::Set (aLab, "QABugs_19.cxx");
+
+    aSStatus = anApp->SaveAs (aDoc, aFileName);
+    anApp->Close (aDoc);
+  }
+  QA_CHECK ("SaveAs()", aSStatus == PCDM_SS_OK, true);
+
+  {
+    Handle(TDocStd_Document) aDoc;
+    aRStatus = anApp->Open (aFileName, aDoc);
+    anApp->Close (aDoc);
+  }
+  QA_CHECK ("Open()  ", aRStatus == PCDM_RS_OK, true);
+  return 0;
+}
+
+/*****************************************************************************/
 
 void QABugs::Commands_19(Draw_Interpretor& theCommands) {
   const char *group = "QABugs";
@@ -2590,5 +2689,9 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
   theCommands.Add ("OCC24945", "OCC24945", __FILE__, OCC24945, group);
   theCommands.Add ("OCC23950", "OCC23950", __FILE__, OCC23950, group);
   theCommands.Add ("OCC25004", "OCC25004", __FILE__, OCC25004, group);
+  theCommands.Add ("OCC24925",
+                   "OCC24925 filename [pluginLib=TKXml storageGuid retrievalGuid]"
+                   "\nOCAF persistence without setting environment variables",
+                   __FILE__, OCC24925, group);
   return;
 }
index 8d6add75fe7e8ceb98e1ffa826b4c5122c62df3f..700360d068b48d766351e18893e2c9d3cccc5e26 100644 (file)
@@ -236,8 +236,8 @@ is
 
 fields
 
-    myResources      : Manager from Resource;
-    myIsDriverLoaded : Boolean from Standard;
+    myResources      : Manager from Resource is protected;
+    myIsDriverLoaded : Boolean from Standard is protected;
 
 friends
     class Document from TDocStd
index 789db749024237983bc551e6b68bcd4e47b2a9de..349c3d77dde420471996d7a8e7a09fc691fdd09f 100644 (file)
@@ -152,6 +152,11 @@ void TDocStd_Application::InitDocument(const Handle(TDocStd_Document)& /*aDoc*/)
 
 void TDocStd_Application::Close(const Handle(TDocStd_Document)& aDoc)
 {
+  if (aDoc.IsNull())
+  {
+    return;
+  }
+
   Handle(TDocStd_Owner) Owner;
   if (aDoc->Main().Root().FindAttribute(TDocStd_Owner::GetID(),Owner)) {
     Handle(TDocStd_Document) emptyDoc;
diff --git a/tests/bugs/caf/bug24925 b/tests/bugs/caf/bug24925
new file mode 100644 (file)
index 0000000..fe7f7d1
--- /dev/null
@@ -0,0 +1,38 @@
+puts "==========="
+puts "OCC24925 Enabling OCAF persistence without setting environment variables"
+puts "==========="
+
+pload QAcommands
+
+set THE_PLUGIN      "TKXml"
+set THE_SAVE_DRIVER "03a56820-8269-11d5-aab2-0050044b1af1"
+set THE_LOAD_DRIVER "03a56822-8269-11d5-aab2-0050044b1af1"
+
+set aFileName "$imagedir/${casename}_doc.xml"
+if { [file exists "$aFileName"] == 1} {
+  file delete $aFileName
+}
+
+# corrupt environment variable to Plugin file
+set anEnvOld [dgetenv CSF_PluginDefaults]
+dsetenv "CSF_PluginDefaults"
+set anEnvNow [dgetenv CSF_PluginDefaults]
+puts "Unset environment variable CSF_PluginDefaults (old='${anEnvOld}', new='${anEnvNow}')"
+
+OCC24925 "$aFileName" $THE_PLUGIN $THE_SAVE_DRIVER $THE_LOAD_DRIVER
+
+if { [file isfile "$aFileName"] == 1} {
+  set aFile     [open "$aFileName" r]
+  set aFileData [read $aFile]
+  close $aFile
+  if { [string first "My Proprietary Format" "$aFileData"] == -1} {
+    puts "Error: XML file does not contain 'My Proprietary Format'!"
+  }
+  if { [string first "QABugs_19.cxx" "$aFileData"] == -1} {
+    puts "Error: XML file does not contain 'QABugs_19.cxx'!"
+  }
+} else {
+  puts "Error: file is not created!"
+}
+
+#dsetenv "CSF_PluginDefaults" "anEnvOld"