Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 89   Methods: 3
NCLOC: 46   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Shutdown.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: Shutdown.java 593003 2007-11-08 03:12:23Z natalia $
 18    */
 19   
 20    package org.apache.xindice.tools.command;
 21   
 22    import org.apache.xindice.client.xmldb.services.DatabaseInstanceManager;
 23    import org.apache.xindice.tools.XMLTools;
 24   
 25    import org.xmldb.api.DatabaseManager;
 26    import org.xmldb.api.base.Collection;
 27   
 28    /**
 29    * Shutdown.java is designed to let the user shutdown
 30    * the Database.
 31    *
 32    * @version $Revision: 593003 $, $Date: 2007-11-08 03:12:23 +0000 (Thu, 08 Nov 2007) $
 33    */
 34    public class Shutdown extends Command {
 35   
 36    //public boolean execute(Hashtable table, Database db)
 37  0 public boolean execute(XMLTools.Config table) throws Exception {
 38   
 39  0 if (table.getString(XMLTools.COLLECTION) == null) {
 40  0 System.out.println("ERROR : Collection context required ");
 41  0 return false;
 42    }
 43   
 44  0 Collection col = null;
 45  0 try {
 46    // Collection name can be incorrect, use database name instead
 47  0 String context = table.getString(XMLTools.COLLECTION);
 48  0 String db = getDbName(context);
 49   
 50    // Get a Collection reference to pass on to individual commands
 51  0 String colstring = normalizeCollectionURI(db, table.getBoolean(XMLTools.LOCAL));
 52  0 col = DatabaseManager.getCollection(colstring);
 53   
 54  0 if (col != null) {
 55  0 DatabaseInstanceManager man =
 56    (DatabaseInstanceManager) col.getService("DatabaseInstanceManager", XMLDBAPIVERSION);
 57   
 58    // Shutdown the server
 59  0 man.shutdown();
 60    }
 61    } finally {
 62  0 if (col != null) {
 63  0 col.close();
 64    }
 65    }
 66   
 67  0 return true;
 68    }
 69   
 70  0 private String getDbName(String context) {
 71  0 int i = context.indexOf("://");
 72  0 i = i < 0 ? 0 : i + 3;
 73   
 74  0 int start = context.indexOf('/', i);
 75  0 int end = context.indexOf('/', start + 1);
 76  0 if (end == -1) {
 77  0 end = context.length();
 78    }
 79   
 80  0 return context.substring(0, end);
 81    }
 82   
 83  0 public void usage() {
 84  0 System.out.println("Format: xindice shutdown -c <context> [-l [-d <path>]] [-v]");
 85  0 System.out.println();
 86  0 System.out.println("Shuts down the database. Shutdown command only works with embedded driver");
 87  0 System.out.println();
 88    }
 89    }