01: /*
02:
03: This software is OSI Certified Open Source Software.
04: OSI Certified is a certification mark of the Open Source Initiative.
05:
06: The license (Mozilla version 1.0) can be read at the MMBase site.
07: See http://www.MMBase.org/license
08:
09: */
10:
11: package org.mmbase.model;
12:
13: import org.mmbase.util.*;
14: import org.mmbase.util.logging.*;
15: import java.util.*;
16: import java.io.*;
17:
18: /**
19: * @javadoc
20: */
21: public class CloudModel {
22:
23: private static Logger log = Logging
24: .getLoggerInstance(CloudModel.class);
25: private String path;
26: private Map<String, CloudModelBuilder> builders = new HashMap<String, CloudModelBuilder>();
27:
28: public CloudModel(String name) {
29: }
30:
31: public CloudModelBuilder addBuilder(String buildername, String path) {
32: CloudModelBuilder cmb = new CloudModelBuilder(buildername);
33: cmb.setPath(path);
34: builders.put(buildername, cmb);
35: return cmb;
36: }
37:
38: public void setPath(String path) {
39: this .path = path;
40: }
41:
42: public CloudModelBuilder getModelBuilder(String name) {
43: return builders.get(name);
44: }
45:
46: public boolean writeToFile(String filepath) {
47: InputStream in = ResourceLoader.getConfigurationRoot()
48: .getResourceAsStream(path);
49: if (in != null) {
50: try {
51: FileOutputStream out = new FileOutputStream(filepath);
52: byte[] buf = new byte[1024];
53: int len;
54: while ((len = in.read(buf)) > 0) {
55: out.write(buf, 0, len);
56: }
57: in.close();
58: out.flush();
59: out.close();
60: } catch (Exception e) {
61: e.printStackTrace();
62: return false;
63: }
64: } else {
65: log.info("Resource not found : " + path);
66: }
67: return true;
68: }
69:
70: }
|