1 18 package org.columba.core.scripting.config; 19 20 import java.io.File ; 21 22 import org.columba.core.config.Config; 23 import org.columba.core.config.DefaultXmlConfig; 24 import org.columba.core.io.DiskIO; 25 26 32 public class BeanshellConfig 33 { 34 35 private static final String CORE_MODULE = "core"; 36 37 private static final String COLUMBA_SCRIPT_DIRECTORY = "scripts", OPTIONS_FILE = "scripting.xml"; 38 39 protected Config config; 40 41 protected File path; 42 43 protected File optionsFile; 44 45 private static BeanshellConfig instance; 46 47 private BeanshellConfig(Config config) 48 { 49 50 this.config = config; 51 52 path = new File (config.getConfigDirectory(), COLUMBA_SCRIPT_DIRECTORY); 54 DiskIO.ensureDirectory(path); 55 56 optionsFile = new File (config.getConfigDirectory(), OPTIONS_FILE); 58 59 registerPlugin(optionsFile.getName(), new ScriptingXmlConfig(optionsFile)); 60 61 } 62 63 private String getModuleName() 64 { 65 return CORE_MODULE; 66 } 67 68 public File getPath() 69 { 70 return path; 71 } 72 73 public Options getOptions() 74 { 75 return ((ScriptingXmlConfig) getPlugin(optionsFile.getName())) 76 .getOptions(); 77 } 78 79 private void registerPlugin(String id, DefaultXmlConfig plugin) 80 { 81 config.registerPlugin(getModuleName(), id, plugin); 82 } 83 84 private DefaultXmlConfig getPlugin(String id) 85 { 86 return config.getPlugin(getModuleName(), id); 87 } 88 89 public static BeanshellConfig getInstance() 90 { 91 if (instance == null) instance = new BeanshellConfig(Config.getInstance()); 92 93 return instance; 94 } 95 } 96 | Popular Tags |