KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > scripting > config > BeanshellConfig


1 /*
2   The contents of this file are subject to the Mozilla Public License Version 1.1
3   (the "License"); you may not use this file except in compliance with the
4   License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5   
6   Software distributed under the License is distributed on an "AS IS" basis,
7   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8   for the specific language governing rights and
9   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 JavaDoc;
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
35     private static final String JavaDoc CORE_MODULE = "core";
36
37     private static final String JavaDoc COLUMBA_SCRIPT_DIRECTORY = "scripts", OPTIONS_FILE = "scripting.xml";
38
39     protected Config config;
40
41     protected File JavaDoc path;
42
43     protected File JavaDoc optionsFile;
44
45     private static BeanshellConfig instance;
46
47     private BeanshellConfig(Config config)
48     {
49
50         this.config = config;
51         
52         // scripts should reside in <config-folder>/scripts/ directory
53
path = new File JavaDoc(config.getConfigDirectory(), COLUMBA_SCRIPT_DIRECTORY);
54         DiskIO.ensureDirectory(path);
55
56         // scripting.xml configuration file should reside in <config-folder>
57
optionsFile = new File JavaDoc(config.getConfigDirectory(), OPTIONS_FILE);
58         
59         registerPlugin(optionsFile.getName(), new ScriptingXmlConfig(optionsFile));
60
61     }
62
63     private String JavaDoc getModuleName()
64     {
65         return CORE_MODULE;
66     }
67
68     public File JavaDoc 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 JavaDoc id, DefaultXmlConfig plugin)
80     {
81         config.registerPlugin(getModuleName(), id, plugin);
82     }
83
84     private DefaultXmlConfig getPlugin(String JavaDoc 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