1 package org.catacomb.serial.om;
2
3 import java.io.File;
4
5 import org.catacomb.report.E;
6 import org.catacomb.serial.Archivist;
7 import org.catacomb.serial.Deserializer;
8 import org.catacomb.util.FileUtil;
9
10
11 public class OmFileWriter extends OmWriter {
12
13 protected File file;
14
15
16 public OmFileWriter(File f) {
17 file = f;
18 }
19
20
21 public File getFile() {
22 return file;
23 }
24
25 public File getResourceDir() {
26
27
28
29
30
31
32
33
34
35
36
37
38 return file.getParentFile();
39 }
40
41
42
43 public void writeResource(Object oext, String resnm) {
44 File fres = new File(getResourceDir(), resnm);
45 Archivist.storeXMLOnly(oext, fres);
46 }
47
48
49
50 public Object readResource(String resnm) {
51 Object ret = null;
52
53 File f = new File(getResourceDir(), resnm);
54 if (f.exists()) {
55
56 String ftxt = FileUtil.readStringFromFile(f);
57 ret = Deserializer.deserialize(ftxt);
58
59 } else {
60 E.error("no such resource file " + f);
61 }
62 return ret;
63 }
64
65 }