Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "mitkPropertyListDeserializer.h"
00019
00020 #include <tinyxml.h>
00021
00022 mitk::PropertyListDeserializer::PropertyListDeserializer()
00023 {
00024 }
00025
00026 mitk::PropertyListDeserializer::~PropertyListDeserializer()
00027 {
00028 }
00029
00030
00031 bool mitk::PropertyListDeserializer::Deserialize()
00032 {
00033 bool error(false);
00034
00035 TiXmlDocument document( m_Filename );
00036 if (!document.LoadFile())
00037 {
00038 MITK_ERROR << "Could not open/read/parse " << m_Filename << "\nTinyXML reports: " << document.ErrorDesc() << std::endl;
00039 return false;
00040 }
00041
00042
00043 int fileVersion = 1;
00044 TiXmlElement* versionObject = document.FirstChildElement("Version");
00045 if (versionObject)
00046 {
00047 if ( versionObject->QueryIntAttribute( "FileVersion", &fileVersion ) != TIXML_SUCCESS )
00048 {
00049 MITK_ERROR << "Property file " << m_Filename << " does not contain version information! Trying version 1 format." << std::endl;
00050 }
00051 }
00052
00053 std::stringstream propertyListDeserializerClassName;
00054 propertyListDeserializerClassName << "PropertyListDeserializerV" << fileVersion;
00055
00056 std::list<itk::LightObject::Pointer> readers = itk::ObjectFactoryBase::CreateAllInstance(propertyListDeserializerClassName.str().c_str());
00057 if (readers.size() < 1)
00058 {
00059 MITK_ERROR << "No property list reader found for file version " << fileVersion;
00060 }
00061 if (readers.size() > 1)
00062 {
00063 MITK_WARN << "Multiple property list readers found for file version " << fileVersion << ". Using arbitrary first one.";
00064 }
00065
00066 for ( std::list<itk::LightObject::Pointer>::iterator iter = readers.begin();
00067 iter != readers.end();
00068 ++iter )
00069 {
00070 if (PropertyListDeserializer* reader = dynamic_cast<PropertyListDeserializer*>( iter->GetPointer() ) )
00071 {
00072 reader->SetFilename( m_Filename );
00073 bool success = reader->Deserialize();
00074 error |= !success;
00075 m_PropertyList = reader->GetOutput();
00076
00077 if ( error )
00078 {
00079 MITK_ERROR << "There were errors while loding property list file " << m_Filename << ". Your data may be corrupted";
00080 }
00081 break;
00082 }
00083 }
00084
00085 return !error;
00086 }
00087
00088
00089 mitk::PropertyList::Pointer mitk::PropertyListDeserializer::GetOutput()
00090 {
00091 return m_PropertyList;
00092 }
00093
00094