MatrixBerryCore
HashMapXMLMetaData.m
Go to the documentation of this file.
1 classdef HashMapXMLMetaData<mxberry.core.cont.ondisk.AHashMap
2 
3  properties (Constant,GetAccess=protected)
4  XML_EXTENSION='xml';
5  IGNORE_EXTENSIONS={'asv','xml~'};
6  ALLOWED_EXTENSIONS={'xml'};
7  end
8  methods
9  function self=HashMapXMLMetaData(varargin)
11  import mxberry.core.throwerror;
12  import mxberry.core.checkvar;
13  import mxberry.core.parseparext;
14  %
15  [regArgList,~,storageFormat]=parseparext(varargin,...
16  {'storageFormat';'verxml';...
17  'isstring(x)&&ismember(x,{''verxml'',''none''})'});
18  %
19  if ~ismember(storageFormat,{'verxml','none'})
20  throwerror('wrongInput','storage format %s unknown',...
21  storageFormat);
22  end
23  %
24  self=self@mxberry.core.cont.ondisk.AHashMap(regArgList{:},...
25  'storageFormat',storageFormat);
26  %
27  switch lower(self.storageFormat)
28  case 'verxml'
29  self.saveFunc=...
30  @mxberry.core.cont.ondisk.HashMapXMLMetaData.saveFunc;
31  self.loadKeyFunc=@mxberry.xml.xmlload;
32  self.loadValueFunc=@mxberry.xml.xmlload;
33  self.fileExtension=self.XML_EXTENSION;
34  self.isMissingKeyBlamed=true;
35  case 'none'
36  self.saveFunc=@(x,y,z,w)1;
37  self.loadKeyFunc=@(x)1;
38  self.loadValueFunc=@(x)1;
39  self.isMissingKeyBlamed=true;
40  otherwise
41  throwerror('wrongInput',...
42  'storage format %s is unknown',self.storageFormat);
43  end
44  end
45  %
46  end
47  methods (Access=protected, Static)
48  function saveFunc(fileName,valueObjName,keyObjName,varargin)
49  mxberry.xml.xmlsave(fileName,struct(...
50  'valueObj',{evalin('caller',valueObjName)},...
51  'keyStr',{evalin('caller',keyObjName)}),...
52  'on',varargin{:},'insertTimestamp',false);
53  end
54  end
55  methods (Access=protected)
56  function [isPositive,keyStr]=checkKey(self,fileName)
57  isPositive=mxberry.io.isfile(fileName);
58  if (strcmp(self.fileExtension,self.XML_EXTENSION))&&(nargout<2)
59  return;
60  end
61  if isPositive
62  [isPositive,keyStr]=checkKey@mxberry.core.cont.ondisk.AHashMap(...
63  self,fileName);
64  end
65  end
66  function putOne(self,keyStr,valueObj,varargin)
67  import mxberry.core.throwwarn;
68  fullFileName=self.genfullfilename(keyStr);
69  try
70  self.saveFunc(fullFileName,'valueObj','keyStr',varargin{:});
71  catch meObj
72  if mxberry.io.isfile(fullFileName)
73  delete(fullFileName);
74  end
75  %
76  if self.isPutErrorIgnored
77  throwwarn('saveFailure',...
78  'cannot save the key value: %s',...
79  meObj.message);
80  return;
81  else
82  rethrow(meObj);
83  end
84  end
85  end
86  %
87  function [valueObj,metaData]=getOne(self,keyStr)
88  fileName=self.getFileNameByKey(keyStr);
89  [resObj,metaData]=self.loadValueFunc(fileName);
90  valueObj=resObj.valueObj;
91  end
92  end
93 end
function throwerror(in msgTag, in varargin)
THROWERROR works similarly to built-in ERROR function in case when there is no output arguments but s...
function parseparext(in args, in propNameValMat, in varargin)
PARSEPAREXT behaves in the same way as mxberry.core.parseparams but returns property values in a more...
function throwwarn(in msgTag, in varargin)
THROWWARN works similarly to built-in WARNING function in case when there is no output arguments but ...
DISKBASEDHASHMAP represents a hash map for the arbitrary objects on disk with a high level of persist...
Definition: AHashMap.m:6
function isfile(in fileName, in isJavaBased)
ISFILE returns true if a specified name corresponds to an existing file.
function ismember(in leftVec, in rightVec, in varargin)
ISMEMBER - ismember implementation for arrays of any type.