#include <CDM_Document.hxx>
#include <CDM_MetaData.hxx>
#include <PCDM_Reader.hxx>
-#include <PCDM_ReaderStatus.hxx>
#include <PCDM_ReadWriter.hxx>
#include <PCDM_RetrievalDriver.hxx>
#include <PCDM_StorageDriver.hxx>
#include <Standard_GUID.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_ProgramError.hxx>
-#include <Standard_Type.hxx>
-#include <TCollection_ExtendedString.hxx>
#include <UTL.hxx>
IMPLEMENT_STANDARD_RTTIEXT(CDF_Application,CDM_Application)
else
return PCDM_RS_UnrecognizedFileFormat;
}
- if(!FindReaderFromFormat(theFormat)) return PCDM_RS_NoDriver;
+
+ // check actual availability of the driver
+ try {
+ Handle(PCDM_Reader) aReader = ReaderFromFormat(theFormat);
+ if (aReader.IsNull())
+ return PCDM_RS_NoDriver;
+ }
+ catch (Standard_Failure)
+ {
+ // no need to report error, this was just check for availability
+ }
}
}
return PCDM_RS_OK;
return found;
}
-//=======================================================================
-//function : DefaultExtension
-//purpose :
-//=======================================================================
-Standard_ExtString CDF_Application::DefaultExtension() {
- static TCollection_ExtendedString theDefaultExtension;
- theDefaultExtension="*";
- TColStd_SequenceOfExtendedString theFormats;
- Formats(theFormats);
-
- for (Standard_Integer i=1; i<= theFormats.Length(); i++) {
- TCollection_ExtendedString theResource(theFormats(i));
- theResource+=".FileExtension";
- if(UTL::Find(Resources(),theResource)) {
- theDefaultExtension=UTL::Value(Resources(),theResource);
- return theDefaultExtension.ToExtString();
- }
- }
- return theDefaultExtension.ToExtString();
-}
-
//=======================================================================
//function : Retrieve
//purpose :
if(AlreadyRetrieved) myRetrievableStatus = PCDM_RS_AlreadyRetrieved;
Standard_Boolean Modified=AlreadyRetrieved && aMetaData->Document()->IsModified();
if(Modified) myRetrievableStatus = PCDM_RS_AlreadyRetrievedAndModified;
- if(!AlreadyRetrieved || Modified) {
-
- Handle(PCDM_Reader) theReader=Reader(aMetaData->FileName());
-
-
+ if(!AlreadyRetrieved || Modified)
+ {
+ TCollection_ExtendedString aFormat;
+ if (!Format(aMetaData->FileName(), aFormat))
+ {
+ Standard_SStream aMsg;
+ aMsg << "Could not determine format for the file " << aMetaData->FileName() << (char)0;
+ Standard_NoSuchObject::Raise(aMsg);
+ }
+ Handle(PCDM_Reader) theReader = ReaderFromFormat (aFormat);
+
Handle(CDM_Document) theDocument;
if(Modified) {
return CDF_TOA_New;
}
-
-//=======================================================================
-//function : FindReader
-//purpose :
-//=======================================================================
-Standard_Boolean CDF_Application::FindReader(const TCollection_ExtendedString& aFileName) {
- Standard_GUID voidGUID;
- TCollection_ExtendedString voidResourceName;
- return FindReader(aFileName,voidGUID,voidResourceName);
-}
-
-//=======================================================================
-//function : Reader
-//purpose : code dp
-//=======================================================================
-Handle(PCDM_Reader) CDF_Application::Reader (const TCollection_ExtendedString& aFileName) {
- TCollection_ExtendedString theFormat;
- if (!Format(aFileName,theFormat)) {
- Standard_SStream aMsg;
- aMsg << "Could not found the format" <<(char)0;
- Standard_NoSuchObject::Raise(aMsg);
-
- }
- return ReaderFromFormat (theFormat);
-}
-
//=======================================================================
//function : Read
//purpose :
return aDoc;
}
-//=======================================================================
-//function : FindReaderFromFormat
-//purpose :
-//=======================================================================
-Standard_Boolean CDF_Application::FindReaderFromFormat(const TCollection_ExtendedString& aFormat) {
- Standard_GUID voidGUID;
- TCollection_ExtendedString voidResourceName;
- return FindReaderFromFormat(aFormat,voidGUID,voidResourceName);
-}
-
-
//=======================================================================
//function : ReaderFromFormat
//purpose :
//=======================================================================
-Handle(PCDM_Reader) CDF_Application::ReaderFromFormat(const TCollection_ExtendedString& aFormat) {
- TCollection_ExtendedString UnfoundResourceName;
- Standard_GUID thePluginId;
- if(!FindReaderFromFormat(aFormat,thePluginId,UnfoundResourceName)) {
+Handle(PCDM_Reader) CDF_Application::ReaderFromFormat(const TCollection_ExtendedString& theFormat)
+{
+ // check map of readers
+ Handle(PCDM_RetrievalDriver) aReader;
+ if (myReaders.Find (theFormat, aReader))
+ return aReader;
+
+ // support of legacy method of loading reader as plugin
+ TCollection_ExtendedString aResourceName = theFormat;
+ aResourceName += ".RetrievalPlugin";
+ if (!UTL::Find(Resources(), aResourceName))
+ {
+ myReaders.Bind(theFormat, aReader);
Standard_SStream aMsg;
- aMsg << "Could not found the item:" << UnfoundResourceName <<(char)0;
+ aMsg << "Could not found the item:" << aResourceName <<(char)0;
myRetrievableStatus = PCDM_RS_WrongResource;
Standard_NoSuchObject::Raise(aMsg);
- }
- Handle(PCDM_Reader) R;
+ }
+
+ // Get GUID as a string.
+ TCollection_ExtendedString strPluginId = UTL::Value(Resources(), aResourceName);
+
+ // If the GUID (as a string) contains blanks, remove them.
+ if (strPluginId.Search(' ') != -1)
+ strPluginId.RemoveAll(' ');
+
+ // Convert to GUID.
+ Standard_GUID aPluginId = UTL::GUID(strPluginId);
+
try {
OCC_CATCH_SIGNALS
- R = Handle(PCDM_Reader)::DownCast(Plugin::Load(thePluginId));
+ aReader = Handle(PCDM_RetrievalDriver)::DownCast(Plugin::Load(aPluginId));
}
- catch (Standard_Failure) {
+ catch (Standard_Failure)
+ {
+ myReaders.Bind(theFormat, aReader);
myRetrievableStatus = PCDM_RS_WrongResource;
- Standard_SStream aMsg;
- aMsg << Standard_Failure::Caught() << endl;
- Standard_Failure::Raise(aMsg);
+ Standard_Failure::Caught()->Reraise();
}
- Handle(PCDM_RetrievalDriver) RD = Handle(PCDM_RetrievalDriver)::DownCast(R);
- if (!RD.IsNull()) {
- RD->SetFormat(aFormat);
- return RD;
- } else
+ if (!aReader.IsNull()) {
+ aReader->SetFormat(theFormat);
+ }
+ else
+ {
myRetrievableStatus = PCDM_RS_WrongResource;
- return R;
+ }
+
+ // record in map
+ myReaders.Bind (theFormat, aReader);
+ return aReader;
}
//=======================================================================
-//function : FindReader
+//function : WriterFromFormat
//purpose :
//=======================================================================
-Standard_Boolean CDF_Application::FindReader(const TCollection_ExtendedString& aFileName, Standard_GUID& thePluginId, TCollection_ExtendedString& ResourceName) {
-
- TCollection_ExtendedString theFormat=PCDM_ReadWriter::FileFormat(aFileName);
+Handle(PCDM_StorageDriver) CDF_Application::WriterFromFormat(const TCollection_ExtendedString& theFormat)
+{
+ // check map of writers
+ Handle(PCDM_StorageDriver) aDriver;
+ if (myWriters.Find (theFormat, aDriver))
+ return aDriver;
+
+ // support of legacy method of loading reader as plugin
+ TCollection_ExtendedString aResourceName = theFormat;
+ aResourceName += ".StoragePlugin";
+ if(!UTL::Find(Resources(), aResourceName))
+ {
+ myWriters.Bind (theFormat, aDriver);
+ Standard_SStream aMsg;
+ aMsg << "Could not found the resource definition:" << aResourceName <<(char)0;
+ Standard_NoSuchObject::Raise(aMsg);
+ }
-// It is good if the format is in the file. Otherwise base on the extension.
-
- if(theFormat.Length()==0) {
- ResourceName=UTL::Extension(aFileName);
- ResourceName+=".FileFormat";
+ // Get GUID as a string.
+ TCollection_ExtendedString strPluginId = UTL::Value(Resources(), aResourceName);
- if(UTL::Find(Resources(),ResourceName)) {
- theFormat=UTL::Value(Resources(),ResourceName);
- }
- else
- return Standard_False;
+ // If the GUID (as a string) contains blanks, remove them.
+ if (strPluginId.Search(' ') != -1)
+ strPluginId.RemoveAll(' ');
+
+ // Convert to GUID.
+ Standard_GUID aPluginId = UTL::GUID(strPluginId);
+
+ try {
+ OCC_CATCH_SIGNALS
+ aDriver = Handle(PCDM_StorageDriver)::DownCast(Plugin::Load(aPluginId));
+ }
+ catch (Standard_Failure)
+ {
+ myWriters.Bind (theFormat, aDriver);
+ myRetrievableStatus = PCDM_RS_WrongResource;
+ Standard_Failure::Caught()->Reraise();
+ }
+ if (aDriver.IsNull())
+ {
+ myRetrievableStatus = PCDM_RS_WrongResource;
+ }
+ else
+ {
+ aDriver->SetFormat(theFormat);
}
- return FindReaderFromFormat(theFormat,thePluginId,ResourceName);
+
+ // record in map
+ myWriters.Bind(theFormat, aDriver);
+ return aDriver;
}
//=======================================================================
return Standard_True;
}
-//=======================================================================
-//function : FindReaderFromFormat
-//purpose :
-//=======================================================================
-Standard_Boolean CDF_Application::FindReaderFromFormat(const TCollection_ExtendedString& aFormat, Standard_GUID& thePluginId, TCollection_ExtendedString& ResourceName) {
-
- ResourceName=aFormat;
- ResourceName+=".RetrievalPlugin";
-
- if(UTL::Find(Resources(),ResourceName)) {
- // Get GUID as a string.
- TCollection_ExtendedString strPluginId = UTL::Value(Resources(),ResourceName);
-
- // If the GUID (as a string) contains blanks, remove them.
- if (strPluginId.Search(' ') != -1)
- strPluginId.RemoveAll(' ');
-
- // Convert to GUID.
- thePluginId=UTL::GUID(strPluginId);
- return Standard_True;
- }
- return Standard_False;
-}
-
//=======================================================================
//function : CanRetrieve
//purpose :