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), mName(name), mPosition(position), mSize(size)
00035 {
00036 }
00037
00038 ProcessingDefinitionAdapter::~ProcessingDefinitionAdapter()
00039 {
00040 }
00041
00042 void ProcessingDefinitionAdapter::StoreOn (Storage & store) const
00043 {
00044 Text nameCopy(mName);
00045 XMLAdapter<Text> nameAdapter( nameCopy, "id");
00046 Text className(mAdaptee->GetClassName());
00047 XMLAdapter<Text> classNameAdapter( className, "type");
00048 store.Store(nameAdapter);
00049 store.Store(classNameAdapter);
00050 if (mPosition!="")
00051 {
00052 Text positionCopy(mPosition);
00053 XMLAdapter<Text> positionAdapter (positionCopy, "position");
00054 store.Store(positionAdapter);
00055 }
00056 if (mSize!="")
00057 {
00058 Text sizeCopy(mSize);
00059 XMLAdapter<Text> sizeAdapter (sizeCopy, "size");
00060 store.Store(sizeAdapter);
00061 }
00062 XMLComponentAdapter configAdapter((ProcessingConfig&)mAdaptee->GetConfig());
00063 store.Store(configAdapter);
00064 }
00065
00066 void ProcessingDefinitionAdapter::LoadFrom (Storage & store)
00067 {
00068 XMLAdapter<Text> nameAdapter( mName, "id");
00069 store.Load(nameAdapter);
00070 Text className("");
00071 XMLAdapter<Text> classNameAdapter( className, "type");
00072 store.Load(classNameAdapter);
00073
00074 XMLAdapter<Text> positionAdapter (mPosition, "position");
00075 store.Load(positionAdapter);
00076 XMLAdapter<Text> sizeAdapter (mSize, "size");
00077 store.Load(sizeAdapter);
00078
00079 try
00080 {
00081 mAdaptee = ProcessingFactory::GetInstance().CreateSafe(className);
00082 } catch (ErrFactory & e)
00083 {
00084 std::string msg =
00085 "Error creating a processing object of type '" +
00086 className + "' which is not available.";
00087 throw XmlStorageErr(msg);
00088 }
00089 ProcessingConfig& cfg = (ProcessingConfig&)mAdaptee->GetConfig();
00090 XMLComponentAdapter configAdapter( cfg );
00091 store.Load(configAdapter);
00092 mAdaptee->Configure(cfg);
00093 }
00094 }
00095