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
00019 #include "mitkSerializerMacros.h"
00020 #include "mitkPropertyListDeserializerV1.h"
00021 #include "mitkBasePropertyDeserializer.h"
00022 #include <tinyxml.h>
00023
00024 MITK_REGISTER_SERIALIZER(PropertyListDeserializerV1)
00025
00026 mitk::PropertyListDeserializerV1::PropertyListDeserializerV1()
00027 {
00028 }
00029
00030 mitk::PropertyListDeserializerV1::~PropertyListDeserializerV1()
00031 {
00032 }
00033
00034 bool mitk::PropertyListDeserializerV1::Deserialize()
00035 {
00036 bool error(false);
00037
00038 m_PropertyList = PropertyList::New();
00039
00040 TiXmlDocument document( m_Filename );
00041 if (!document.LoadFile())
00042 {
00043 MITK_ERROR << "Could not open/read/parse " << m_Filename << "\nTinyXML reports: " << document.ErrorDesc() << std::endl;
00044 return false;
00045 }
00046
00047 for( TiXmlElement* propertyElement = document.FirstChildElement("property"); propertyElement != NULL; propertyElement = propertyElement->NextSiblingElement("property") )
00048 {
00049 const char* keya = propertyElement->Attribute("key");
00050 std::string key( keya ? keya : "");
00051
00052 const char* typea = propertyElement->Attribute("type");
00053 std::string type( typea ? typea : "");
00054
00055
00056 std::stringstream propertyDeserializerClassName;
00057 propertyDeserializerClassName << type << "Deserializer";
00058
00059 std::list<itk::LightObject::Pointer> readers = itk::ObjectFactoryBase::CreateAllInstance(propertyDeserializerClassName.str().c_str());
00060 if (readers.size() < 1)
00061 {
00062 MITK_ERROR << "No property reader found for " << type;
00063 error = true;
00064 }
00065 if (readers.size() > 1)
00066 {
00067 MITK_WARN << "Multiple property readers found for " << type << ". Using arbitrary first one.";
00068 }
00069
00070 for ( std::list<itk::LightObject::Pointer>::iterator iter = readers.begin();
00071 iter != readers.end();
00072 ++iter )
00073 {
00074 if (BasePropertyDeserializer* reader = dynamic_cast<BasePropertyDeserializer*>( iter->GetPointer() ) )
00075 {
00076 BaseProperty::Pointer property = reader->Deserialize( propertyElement->FirstChildElement() );
00077 if (property.IsNotNull())
00078 {
00079 m_PropertyList->ReplaceProperty(key, property);
00080 }
00081 else
00082 {
00083 MITK_ERROR << "There were errors while loding property '" << key << "' of type " << type << ". Your data may be corrupted";
00084 error = true;
00085 }
00086 break;
00087 }
00088 }
00089 }
00090 return !error;
00091 }