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.UserDefinedTypeMetaModel;
12: import com.completex.objective.components.persistency.meta.ModelStorerPlugin;
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 FileModelStorerPluginImpl implements
25: ModelStorerPlugin {
26: private String outputDir;
27: private String fileName;
28:
29: public FileModelStorerPluginImpl(String outputDir, String fileName) {
30: this .outputDir = outputDir;
31: this .fileName = fileName;
32: }
33:
34: abstract protected Map toMap(UserDefinedTypeMetaModel model);
35:
36: abstract protected void writeModel(Map modelMap, Writer writer)
37: throws IOException;
38:
39: public void store(UserDefinedTypeMetaModel model)
40: throws IOException {
41: File file = new File(outputDir);
42: if (!file.exists()) {
43: mkDirs(outputDir);
44: }
45: FileWriter writer = new FileWriter(outputDir + File.separator
46: + fileName);
47: writeModel(toMap(model), writer);
48:
49: }
50:
51: public void mkDirs(String fileName) throws FileNotFoundException {
52: (new File(fileName)).mkdirs();
53: }
54: }
|