0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 function collectedHist = attachStructToDom(objs, dom, parent, collectedHist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % Store the structure shape in the parent node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 parent.setAttribute('structShape', sprintf('%dx%d', size(objs)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 parent.setAttribute('type', class(objs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 if isempty(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % Create structure node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 structNode = dom.createElement('struct');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 structNode.setAttribute('structShape', sprintf('%dx%d', size(objs)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 structNode.setAttribute('shape', sprintf('%dx%d', size(objs)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 structNode.setAttribute('type', 'empty-struct');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % Add to parent node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 parent.appendChild(structNode);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 for oo = 1:numel(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 obj = objs(oo);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 fnames = fieldnames(obj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % Create structure node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 structNode = dom.createElement('struct');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 structNode.setAttribute('structShape', sprintf('%dx%d', size(objs)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 for ff=1:numel(fnames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 val = obj.(fnames{ff});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % Create structure node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 fieldnameNode = dom.createElement(fnames{ff});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 fieldnameNode.setAttribute('shape', sprintf('%dx%d', size(val)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 fieldnameNode.setAttribute('type', class(val));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 if isnumeric(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 utils.xml.attachNumberToDom(val, dom, fieldnameNode);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 elseif islogical(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 content = dom.createTextNode(utils.xml.mat2str(val));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 fieldnameNode.appendChild(content);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 elseif isa(val, 'sym')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 utils.xml.attachSymToDom(val, dom, fieldnameNode);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 elseif ischar(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 utils.xml.attachCharToDom(val, dom, fieldnameNode);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 elseif isa(val, 'ltpda_obj')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 collectedHist = val.attachToDom(dom, fieldnameNode, collectedHist);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 elseif iscell(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 collectedHist = utils.xml.attachCellToDom(val, dom, fieldnameNode, collectedHist);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 elseif isstruct(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 collectedHist = utils.xml.attachStructToDom(val, dom, fieldnameNode, collectedHist);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 elseif isjava(val)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 if strcmp(class(val), 'sun.util.calendar.ZoneInfo')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 content = dom.createTextNode(char(val.getID));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 fieldnameNode.appendChild(content);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 error('### Unknown JAVA class. Can not attach the java class %s to DOM.', class(val));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 error('!!! Please code me up for the class [%s]', class(val));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % Add fieldname node to structure node
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 structNode.appendChild(fieldnameNode);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end % ff=1:numel(fnames)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % Add structure node to parent
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 parent.appendChild(structNode);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 end % oo = 1:numel(objs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 end
|