/*
* Copyright 1999-2004 The Apache Software Foundation.
*
* Licensed 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.
*
* CVS $Id: DeleteIndexer.java,v 1.8 2004/02/08 02:57:35 vgritsenko Exp $
*/
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;
import java.util.Hashtable;
/**
* DeleteIndexer.java is designed to let the user delete or drop
* an Indexer from a named Collection or a nested Collection within
* the Database.
*
* @version CVS $Revision: 1.8 $, $Date: 2004/02/08 02:57:35 $
*/
public class DeleteIndexer extends Command {
public boolean execute(Hashtable table) throws Exception {
Collection col = null;
try {
if (table.get(XMLTools.COLLECTION) != null) {
// Get a Collection reference to the collection
String colstring = normalizeCollectionURI((String) table.get(XMLTools.COLLECTION),
(String) table.get(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 collection
CollectionManager colman = (CollectionManager) col.getService("CollectionManager", XMLDBAPIVERSION);
if (table.get(XMLTools.NAME_OF) != null) {
colman.dropIndexer((String) table.get(XMLTools.NAME_OF));
System.out.println("DELETED: " + (String) table.get(XMLTools.NAME_OF));
} else {
System.out.println("ERROR : Name switch and Indexer name required");
}
} else
System.out.println("ERROR : Collection and switch required");
} finally {
if (col != null) {
col.close();
}
}
return true;
}
}