KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > model > CloudModel


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9  */

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 public class CloudModel {
19
20     private static Logger log = Logging.getLoggerInstance(CloudModel.class);
21     private String JavaDoc name;
22     private String JavaDoc path;
23     private HashMap builders = new HashMap();
24
25     public CloudModel(String JavaDoc name) {
26     this.name = name;
27     }
28   
29     public CloudModelBuilder addBuilder(String JavaDoc buildername,String JavaDoc path) {
30     CloudModelBuilder cmb = new CloudModelBuilder(buildername);
31     cmb.setPath(path);
32     builders.put(buildername,cmb);
33     return cmb;
34     }
35
36     public void setPath(String JavaDoc path) {
37     this.path = path;
38     }
39
40     public CloudModelBuilder getModelBuilder(String JavaDoc name) {
41     return (CloudModelBuilder)builders.get(name);
42     }
43
44
45     public boolean writeToFile(String JavaDoc filepath) {
46             InputStream in = ResourceLoader.getConfigurationRoot().getResourceAsStream(path);
47         if (in!=null) {
48                 try {
49             FileOutputStream out = new FileOutputStream(filepath);
50                 byte[] buf = new byte[1024];
51                 int len;
52                 while ((len = in.read(buf)) > 0) {
53                         out.write(buf, 0, len);
54                 }
55                 in.close();
56                         out.flush();
57                 out.close();
58                     } catch(Exception JavaDoc e) {
59                        e.printStackTrace();
60                return false;
61                     }
62         } else {
63             log.info("Resource not found : "+path);
64         }
65     return true;
66     }
67
68 }
69
Popular Tags