*/
public class AddIndexer 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 && table.get(XMLTools.PATTERN) != null ) {
Document doc = new DocumentImpl();
// Create the index element to hold attributes
Element idxEle = doc.createElement("index");
idxEle.setAttribute("class", XINDICE_VAL_INDEXER);
idxEle.setAttribute("name", (String)table.get(XMLTools.NAME_OF));
idxEle.setAttribute("pattern", (String)table.get(XMLTools.PATTERN) );
// Setup optional index attributes
if ( table.containsKey(XMLTools.TYPE) ) {
String t = (String)table.get(XMLTools.TYPE);
if ( t.equalsIgnoreCase("name") )
idxEle.setAttribute("class", XINDICE_NAME_INDEXER);
else
idxEle.setAttribute("type", (String)table.get(XMLTools.TYPE));
}
if ( table.containsKey(XMLTools.PAGE_SIZE) ) {
idxEle.setAttribute("pagesize", (String)table.get(XMLTools.PAGE_SIZE));
}
if (table.containsKey(XMLTools.MAX_KEY_SIZE) ) {
idxEle.setAttribute("maxkeysize", (String)table.get(XMLTools.MAX_KEY_SIZE) );
}
// Add Element to the document
doc.appendChild(idxEle);
//If in verbose mode, show....
if ( (String)table.get(XMLTools.VERBOSE) == "true" ) {
String indexstr = TextWriter.toString(doc);
System.out.println("Index node element = ");
System.out.println("\t" + indexstr + "\n" );
}
// Create the indexer for this collection manager
colman.createIndexer(doc);
System.out.println("CREATED : " + table.get(XMLTools.NAME_OF));
}
else {
System.out.println("ERROR : Name and Pattern required");
}
}
else {
System.out.println("ERROR : Collection and switch required");
}
} finally {
if ( col != null ) {
col.close();
}
}
return true;
}