ProcessingDefinitionAdapter.cxx
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
00020
00021
00022
00023 #include "ProcessingDefinitionAdapter.hxx"
00024 #include "Assert.hxx"
00025 #include "Processing.hxx"
00026 #include "ProcessingConfig.hxx"
00027 #include "ProcessingFactory.hxx"
00028 #include "XMLAdapter.hxx"
00029 #include "XmlStorageErr.hxx"
00030
00031 namespace CLAM
00032 {
00033 ProcessingDefinitionAdapter::ProcessingDefinitionAdapter( Processing * adaptee, const std::string & name, const std::string & position, const std::string & size )
00034 : mAdaptee(adaptee)
00035 , mConfiguration(0)
00036 , mName(name)
00037 , mPosition(position)
00038 , mSize(size)
00039 {
00040 }
00041
00042 ProcessingDefinitionAdapter::~ProcessingDefinitionAdapter()
00043 {
00044 if (mConfiguration) delete mConfiguration;
00045 }
00046
00047 void ProcessingDefinitionAdapter::StoreOn (Storage & store) const
00048 {
00049 Text nameCopy(mName);
00050 XMLAdapter<Text> nameAdapter( nameCopy, "id");
00051 Text className(mAdaptee->GetClassName());
00052 XMLAdapter<Text> classNameAdapter( className, "type");
00053 store.Store(nameAdapter);
00054 store.Store(classNameAdapter);
00055 if (mPosition!="")
00056 {
00057 Text positionCopy(mPosition);
00058 XMLAdapter<Text> positionAdapter (positionCopy, "position");
00059 store.Store(positionAdapter);
00060 }
00061 if (mSize!="")
00062 {
00063 Text sizeCopy(mSize);
00064 XMLAdapter<Text> sizeAdapter (sizeCopy, "size");
00065 store.Store(sizeAdapter);
00066 }
00067 XMLComponentAdapter configAdapter((ProcessingConfig&)mAdaptee->GetConfig());
00068 store.Store(configAdapter);
00069 }
00070
00071 void ProcessingDefinitionAdapter::LoadFrom (Storage & store)
00072 {
00073 XMLAdapter<Text> nameAdapter( mName, "id");
00074 if (!store.Load(nameAdapter))
00075 throw XmlStorageErr("Processing without id attribute");
00076 Text className;
00077 XMLAdapter<Text> classNameAdapter( className, "type");
00078 if (!store.Load(classNameAdapter))
00079 throw XmlStorageErr("Processing without type attribute");
00080
00081 XMLAdapter<Text> positionAdapter (mPosition, "position");
00082 store.Load(positionAdapter);
00083 XMLAdapter<Text> sizeAdapter (mSize, "size");
00084 store.Load(sizeAdapter);
00085
00086 try
00087 {
00088 mAdaptee = ProcessingFactory::GetInstance().CreateSafe(className);
00089 } catch (ErrFactory & e)
00090 {
00091 std::string msg =
00092 "Error creating a processing object of type '" +
00093 className + "' which is not available.";
00094 throw XmlStorageErr(msg);
00095 }
00096 Component * cfg = mAdaptee->GetConfig().DeepCopy();
00097 XMLComponentAdapter configAdapter( *cfg );
00098 store.Load(configAdapter);
00099 mConfiguration = dynamic_cast<ProcessingConfig *>(cfg);
00100 CLAM_ASSERT(mConfiguration, "Retrieved config fails to cast as a ProcessingConfig");
00101 }
00102 }
00103