01: /*
02: The contents of this file are subject to the Mozilla Public License Version 1.1
03: (the "License"); you may not use this file except in compliance with the
04: License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
05:
06: Software distributed under the License is distributed on an "AS IS" basis,
07: WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
08: for the specific language governing rights and
09: limitations under the License.
10:
11: The Original Code is "The Columba Project"
12:
13: The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
14: Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
15:
16: All Rights Reserved.
17: */
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: /**
27: Service configuration class. To access the service options use the getOptions
28: accessor.
29:
30: @author Celso Pinto (cpinto@yimports.com)
31: */
32: public class BeanshellConfig {
33:
34: private static final String CORE_MODULE = "core";
35:
36: private static final String COLUMBA_SCRIPT_DIRECTORY = "scripts",
37: 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: this .config = config;
50:
51: // scripts should reside in <config-folder>/scripts/ directory
52: path = new File(config.getConfigDirectory(),
53: COLUMBA_SCRIPT_DIRECTORY);
54: DiskIO.ensureDirectory(path);
55:
56: // scripting.xml configuration file should reside in <config-folder>
57: optionsFile = new File(config.getConfigDirectory(),
58: OPTIONS_FILE);
59:
60: registerPlugin(optionsFile.getName(), new ScriptingXmlConfig(
61: optionsFile));
62:
63: }
64:
65: private String getModuleName() {
66: return CORE_MODULE;
67: }
68:
69: public File getPath() {
70: return path;
71: }
72:
73: public Options getOptions() {
74: return ((ScriptingXmlConfig) getPlugin(optionsFile.getName()))
75: .getOptions();
76: }
77:
78: private void registerPlugin(String id, DefaultXmlConfig plugin) {
79: config.registerPlugin(getModuleName(), id, plugin);
80: }
81:
82: private DefaultXmlConfig getPlugin(String id) {
83: return config.getPlugin(getModuleName(), id);
84: }
85:
86: public static BeanshellConfig getInstance() {
87: if (instance == null)
88: instance = new BeanshellConfig(Config.getInstance());
89:
90: return instance;
91: }
92: }
|