/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: DeleteCollection.java 578602 2007-09-23 20:33:31Z natalia $
*/
package org.apache.xindice.tools.command;
import org.apache.xindice.client.xmldb.services.CollectionManager;
import org.apache.xindice.tools.XMLTools;
import org.xmldb.api.DatabaseManager;
import org.xmldb.api.base.Collection;
/**
* DeleteCollection.java is designed to let the user delete or drop
* a named Collection or Nested Collection from the Database or Parent
* Collection respectively.
*
* @version $Revision: 578602 $, $Date: 2007-09-23 16:33:31 -0400 (Sun, 23 Sep 2007) $
*/
public class DeleteCollection extends Command {
public boolean execute(XMLTools.Config table) throws Exception {
// Verify that the collection passed in is not null
if (table.getString(XMLTools.COLLECTION) == null) {
System.out.println("ERROR : Collection and switch required");
return false;
}
if (table.getString(XMLTools.NAME_OF) == null) {
System.out.println("ERROR : Name and switch required");
return false;
}
Collection col = null;
try {
// Get a Collection reference to the collection to be deleted
String colstring = normalizeCollectionURI(table.getString(XMLTools.COLLECTION),
table.getBoolean(XMLTools.LOCAL));
col = DatabaseManager.getCollection(colstring);
if (col == null) {
System.out.println("ERROR : Collection not found!");
return false;
}
// Create a collection manager instance for the parent of the collection
CollectionManager colman = (CollectionManager) col.getService("CollectionManager", XMLDBAPIVERSION);
// Drop the collection
colman.dropCollection(table.getString(XMLTools.NAME_OF));
System.out.println("Deleted: " + table.getString(XMLTools.COLLECTION) + "/" + table.getString(XMLTools.NAME_OF));
} finally {
if (col != null) {
col.close();
}
}
return true;
}
public void usage() {
System.out.println("Format: xindice dc -c <context> [-l [-d <path>]] [-v] [parameters...]");
System.out.println();
System.out.println("Drops a collection from the database or parent collection");
System.out.println();
System.out.println("Command-specific switches:");
System.out.println(" -n|--nameOf <name>");
System.out.println(" Name of the collection to be deleted");
System.out.println();
}
}