01: package com.xoetrope.xbb.modules;
02:
03: import com.xoetrope.service.ModelHelper;
04: import java.util.Hashtable;
05: import net.xoetrope.optional.data.XOptionalDataSource;
06: import net.xoetrope.xml.XmlElement;
07: import net.xoetrope.xml.XmlSource;
08: import net.xoetrope.xui.XProject;
09: import net.xoetrope.xui.XProjectManager;
10:
11: public class ModuleManager {
12:
13: private static ModuleManager instance;
14: private Hashtable modules;
15: private XProject project;
16:
17: private ModuleManager() {
18: project = XProjectManager.getCurrentProject();
19: modules = new Hashtable();
20: //loadModule( "LoanCalc", "com.xoetrope.loancalc.MetroModule" );
21: }
22:
23: public static ModuleManager getInstance() {
24: if (instance == null)
25: instance = new ModuleManager();
26: return instance;
27: }
28:
29: private void loadModule(String moduleName, String className) {
30: try {
31: Module module = (Module) Class.forName(className)
32: .newInstance();
33: modules.put(moduleName, module);
34: loadModuleDatasets(module);
35: } catch (Exception ex) {
36: ex.printStackTrace();
37: }
38: }
39:
40: private void loadModuleDatasets(Module module) {
41: String[] files = module.getDatasets();
42: XOptionalDataSource dataSource = ModelHelper
43: .getDataSource(project);
44: for (int i = 0; i < files.length; i++) {
45: try {
46: XmlElement src = XmlSource.read(project
47: .getBufferedReader(files[i]));
48: dataSource.loadTable(src, project.getModel());
49: } catch (Exception ex) {
50: ex.printStackTrace();
51: }
52: }
53: }
54:
55: }
|