1 package org.catacomb.numeric.data;
2
3 import org.catacomb.interlish.structure.Attribute;
4 import org.catacomb.interlish.structure.Element;
5 import org.catacomb.interlish.structure.Factory;
6 import org.catacomb.report.E;
7
8
9
10
11 public class NumDataSetFactory implements Factory {
12
13
14 public String makes;
15
16
17
18
19 public Object make(String s) {
20 NumDataSet dset = new NumDataSet(s);
21
22 return dset;
23 }
24
25
26 private NumDataSet makeDataSet(Element elt) {
27 NumDataSet ds = new NumDataSet(elt.getName());
28 populate(ds, elt);
29 return ds;
30 }
31
32
33
34 public void populate(Object obj, Element popelt) {
35 NumDataSet ds = (NumDataSet)obj;
36 populate(ds, popelt);
37 }
38
39
40 private void populate(NumDataSet ds, Element popelt) {
41 Attribute[] atta = popelt.getAttributeArray();
42 for (int i = 0; i < atta.length; i++) {
43 Attribute att = atta[i];
44 if (att.getName().equals("name")) {
45 ds.setName(att.getValue());
46 } else {
47 ds.addVectorOrScalar(att.getName(), att.getValue());
48 }
49 }
50
51
52 Element[] elta = popelt.getElementArray();
53 for (int i = 0; i < elta.length; i++) {
54 Element elt = elta[i];
55
56 if (elt.getName().equals("VectorSet")) {
57 VectorSet vset = makeVectorSet(elt);
58 ds.addVectorSet(vset);
59
60 } else if (elt.hasElements() || elt.hasAttributes()) {
61 NumDataSet cds = makeDataSet(elt);
62 ds.addDataSet(cds);
63
64 } else {
65 ds.addVectorOrScalar(elt.getName(), elt.getText());
66 }
67 }
68 }
69
70
71
72 private VectorSet makeVectorSet(Element popelt) {
73 VectorSet vset = new VectorSet();
74 vset.setNames(popelt.getAttribute("names"));
75 Element[] elta = popelt.getElementArray();
76 for (int i = 0; i < elta.length; i++) {
77 Element elt = elta[i];
78 if (elt.getName().equals("row")) {
79 vset.addRow(new FloatRow(elt.getText()));
80
81 } else {
82 E.error("only row elements allowed in a vector set, not " + elt.getName());
83 }
84 }
85 return vset;
86 }
87
88
89 }