|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| package org.apache.xindice.server; |
|
21 |
| |
|
22 |
| import org.apache.commons.logging.Log; |
|
23 |
| import org.apache.commons.logging.LogFactory; |
|
24 |
| import org.apache.xindice.core.Database; |
|
25 |
| import org.apache.xindice.util.Configuration; |
|
26 |
| import org.apache.xindice.util.XindiceException; |
|
27 |
| import org.apache.xindice.xml.dom.DOMParser; |
|
28 |
| |
|
29 |
| import java.io.File; |
|
30 |
| import java.io.FileInputStream; |
|
31 |
| import java.io.IOException; |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| public class ManagedServer { |
|
44 |
| |
|
45 |
| private static final Log log = LogFactory.getLog(ManagedServer.class); |
|
46 |
| |
|
47 |
| private Database db; |
|
48 |
| private boolean running; |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
0
| public synchronized void start() throws Exception {
|
|
54 |
0
| if (!running) {
|
|
55 |
0
| configure();
|
|
56 |
0
| running = true;
|
|
57 |
| } else { |
|
58 |
0
| log.warn("Start called on a running server, ignored");
|
|
59 |
| } |
|
60 |
| } |
|
61 |
| |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
0
| public synchronized void stop() throws Exception {
|
|
66 |
0
| if (running) {
|
|
67 |
0
| db.close();
|
|
68 |
0
| db = null;
|
|
69 |
0
| running = false;
|
|
70 |
| } else { |
|
71 |
0
| log.warn("Stop called on a stopped server, ignored");
|
|
72 |
| } |
|
73 |
| } |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
0
| public synchronized void configure() throws IOException, XindiceException {
|
|
79 |
0
| db = Database.getDatabase(loadConfiguration());
|
|
80 |
0
| if (log.isInfoEnabled()) {
|
|
81 |
0
| log.info("Database name: '" + db.getName() + "'");
|
|
82 |
| } |
|
83 |
| } |
|
84 |
| |
|
85 |
0
| protected Configuration loadConfiguration() throws IOException, XindiceException {
|
|
86 |
0
| Configuration config;
|
|
87 |
0
| String configDir = null;
|
|
88 |
0
| String configFile = System.getProperty(Xindice.PROP_XINDICE_CONFIGURATION);
|
|
89 |
0
| if (configFile != null && !configFile.equals("")) {
|
|
90 |
0
| if (log.isInfoEnabled()) {
|
|
91 |
0
| log.info("Specified configuration file: '" + configFile + "'");
|
|
92 |
| } |
|
93 |
0
| FileInputStream configXMLFile = new FileInputStream(new File(configFile));
|
|
94 |
| |
|
95 |
0
| config = new Configuration(DOMParser.toDocument(configXMLFile), false);
|
|
96 |
0
| configDir = new File(configFile).getAbsoluteFile().getParent();
|
|
97 |
| } else { |
|
98 |
0
| if (log.isInfoEnabled()) {
|
|
99 |
0
| log.info("No configuration file specified, going with the default configuration");
|
|
100 |
| } |
|
101 |
| |
|
102 |
0
| config = new Configuration(DOMParser.toDocument(Xindice.DEFAULT_CONFIGURATION), false);
|
|
103 |
| } |
|
104 |
| |
|
105 |
0
| config = config.getChild("root-collection", false);
|
|
106 |
| |
|
107 |
0
| String dbRoot = config.getAttribute(Database.DBROOT, Database.DBROOT_DEFAULT);
|
|
108 |
0
| if (!new File(dbRoot).isAbsolute()) {
|
|
109 |
| |
|
110 |
0
| String home = System.getProperty(Xindice.PROP_XINDICE_DB_HOME);
|
|
111 |
0
| if (home != null) {
|
|
112 |
0
| dbRoot = new File(home + File.separator + dbRoot).getCanonicalPath();
|
|
113 |
0
| } else if (configDir != null) {
|
|
114 |
0
| dbRoot = configDir + File.separator + dbRoot;
|
|
115 |
| } else { |
|
116 |
0
| dbRoot = new File("." + File.separator + dbRoot).getCanonicalPath();
|
|
117 |
0
| log.warn("The database configuration file is not specified and there was no "
|
|
118 |
| + Xindice.PROP_XINDICE_DB_HOME + " property set, " |
|
119 |
| + "so Xindice was unable to determine a database location. " |
|
120 |
| + "Database will be created relative to the current directory."); |
|
121 |
| } |
|
122 |
0
| config.setAttribute(Database.DBROOT, dbRoot);
|
|
123 |
| } |
|
124 |
| |
|
125 |
0
| return config;
|
|
126 |
| } |
|
127 |
| } |