Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 127   Methods: 4
NCLOC: 74   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ManagedServer.java 0% 0% 0% 0%
coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: ManagedServer.java 564998 2007-08-12 02:51:49Z vgritsenko $
 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    * Creates an registers a database instance for use of the managed driver. This class
 35    * may be used to create the database the managed driver uses (as is the case in the test
 36    * cases) but it is not required. Any method may be used to create the database instance
 37    * that the managed driver talks to. As long as the instance name exists when the driver
 38    * fires up all will be good.
 39    *
 40    * @author <a href="mailto:kevin@rocketred.com.au">Kevin O'Neill</a>
 41    * @version $Revision: 564998 $, $Date: 2007-08-11 19:51:49 -0700 (Sat, 11 Aug 2007) $
 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    * (Optionally configure and) start the server
 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    * Stop the server, close database
 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    * Configure and load database
 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    // Let's see if the property was specified.
 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    }