01: /**
02: * Objective Database Abstraction Layer (ODAL)
03: * Copyright (c) 2004, The ODAL Development Group
04: * All rights reserved.
05: * For definition of the ODAL Development Group please refer to LICENCE.txt file
06: *
07: * Distributable under LGPL license.
08: * See terms of license at gnu.org.
09: */package com.completex.objective.components.persistency.meta.impl;
10:
11: import com.completex.objective.components.persistency.meta.MetaModel;
12: import com.completex.objective.components.persistency.meta.ModelStorer;
13:
14: import java.io.File;
15: import java.io.FileNotFoundException;
16: import java.io.FileWriter;
17: import java.io.IOException;
18: import java.io.Writer;
19: import java.util.Map;
20:
21: /**
22: * @author Gennady Krizhevsky
23: */
24: public abstract class FileModelStorerImpl implements ModelStorer {
25: private String outputDir;
26: private String fileName;
27:
28: public FileModelStorerImpl(String outputDir, String fileName) {
29: this .outputDir = outputDir;
30: this .fileName = fileName;
31: }
32:
33: abstract protected Map toMap(MetaModel model);
34:
35: abstract protected void writeModel(Map modelMap, Writer writer)
36: throws IOException;
37:
38: public void store(MetaModel model) throws IOException {
39: File file = new File(outputDir);
40: if (!file.exists()) {
41: mkDirs(outputDir);
42: }
43: FileWriter writer = new FileWriter(outputDir + File.separator
44: + fileName);
45: writeModel(toMap(model), writer);
46:
47: }
48:
49: public void mkDirs(String fileName) throws FileNotFoundException {
50: (new File(fileName)).mkdirs();
51: }
52: }
|