Index: java/src/org/apache/xindice/tools/XMLTools.java
===================================================================
--- java/src/org/apache/xindice/tools/XMLTools.java (revision 471733)
+++ java/src/org/apache/xindice/tools/XMLTools.java (working copy)
@@ -35,7 +35,6 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Hashtable;
-import java.util.NoSuchElementException;
/**
* XMLAdmin is designed to take command line arguments and give
@@ -56,6 +55,7 @@
public static final String VERBOSE = "verbose";
public static final String TYPE = "type";
public static final String PAGE_SIZE = "pagesize";
+ public static final String PAGE_COUNT = "pagecount";
public static final String MAX_KEY_SIZE = "maxkeysize";
public static final String DB_SERVER = "dbServ";
public static final String PORT = "port";
@@ -67,11 +67,11 @@
public static final String AUTO_KEY = "autoKey";
public static final String NAMESPACES = "namespaces";
public static final String IMPL_CLASS = "implClass";
+ private static final String HELP = "help";
private Hashtable table;
protected String location = null;
private boolean initialized = false;
- private static boolean verbose = false;
private Document commandsDocument = null;
protected NodeList commandsList = null;
@@ -82,9 +82,6 @@
new XMLTools().process(args);
} catch (Exception e) {
System.out.println(e.getMessage());
- if (verbose) {
- e.printStackTrace(System.err);
- }
}
}
@@ -165,85 +162,90 @@
**/
public void process(String[] args) throws XindiceException, Exception {
try {
- init();
parseArguments(args);
+ } catch (IllegalArgumentException e) {
+ System.err.println("ERROR : " + e.getMessage());
+ return;
+ }
- if (!execute()) {
- printHelp();
+ try {
+ execute();
+ } catch (XMLDBException e) {
+ System.err.println("XMLDB Exception " + e.errorCode + ": " + e.getMessage());
+ if (table.get(VERBOSE).equals("true")) {
+ e.printStackTrace(System.err);
}
- } catch (IllegalArgumentException e) {
- printHelp();
- throw new XindiceException("ERROR : " + e.getMessage(), e);
- } catch (NoSuchElementException e) {
- throw new NoSuchElementException("ERROR : " + e + " Switch found. Parameter missing.");
- } catch (NullPointerException e) {
- e.printStackTrace(System.err);
- throw new NullPointerException("ERROR : " + e);
} catch (Exception e) {
- e.printStackTrace(System.err);
- throw new XindiceException("ERROR : " + e.getMessage(), e);
+ System.err.println("ERROR : " + e.getMessage());
+ if (table.get(VERBOSE).equals("true")) {
+ e.printStackTrace(System.err);
+ }
}
}
+ private String getRequiredSwitchArgument(ArgTokenizer at, String name) throws IllegalArgumentException {
+ String value = at.nextSwitchToken();
+ if ("".equals(value)) {
+ throw new IllegalArgumentException("Command line switch " + name + " requires value\n" +
+ "Type 'bin" + File.separatorChar + "xindice help' to see command usage");
+ }
+
+ return value;
+ }
+
/**
* Parses and validated the arguments of the command line. The arguments are
* stored into the table array.
*
* @exception IllegalArgumentException if an error is found
*/
- protected void parseArguments(String[] args)
- throws IllegalArgumentException {
+ protected void parseArguments(String[] args) throws IllegalArgumentException {
// parsing arguments for the command tools
ArgTokenizer at = new ArgTokenizer(args);
- if (!at.hasMoreTokens()) {
- throw new IllegalArgumentException("No argument found");
- }
-
// Action should always be the second token, if not there show help
- table.put(ACTION, at.nextToken());
+ String action = at.nextToken();
+ table.put(ACTION, "".equals(action) ? HELP : action);
// Loop over remaining command line arguments, populating hashtable
while (at.hasMoreTokens()) {
String token = at.nextToken();
if (token.equalsIgnoreCase("-c") || token.equalsIgnoreCase("--collection")) {
- String colname = at.nextSwitchToken();
+ String colname = getRequiredSwitchArgument(at, token);
if (!colname.startsWith("/") &&
!colname.startsWith("xmldb:xindice")) {
throw new IllegalArgumentException("The name of a collection must start with '/'");
}
table.put(COLLECTION, colname);
} else if (token.equalsIgnoreCase("-e") || token.equalsIgnoreCase("--extension")) {
- table.put(EXTENSION, at.nextSwitchToken());
+ table.put(EXTENSION, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("-f") || token.equalsIgnoreCase("--filepath")) {
- table.put(FILE_PATH, at.nextSwitchToken());
- } else if (token.equalsIgnoreCase("-h") || token.equalsIgnoreCase("--help")) {
- table.put(ACTION, "help");
+ table.put(FILE_PATH, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("-n") || token.equalsIgnoreCase("--nameOf")) {
- table.put(NAME_OF, at.nextSwitchToken());
+ table.put(NAME_OF, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("-p") || token.equalsIgnoreCase("--pattern")) {
- table.put(PATTERN, at.nextSwitchToken());
+ table.put(PATTERN, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("-q") || token.equalsIgnoreCase("--query")) {
- table.put(QUERY, at.nextSwitchToken());
+ table.put(QUERY, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("-u") || token.equalsIgnoreCase("--uri")) {
- table.put(URI, at.nextSwitchToken());
+ table.put(URI, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("-v") || token.equalsIgnoreCase("--verbose")) {
table.put(VERBOSE, "true");
} else if (token.equalsIgnoreCase("-l") || token.equalsIgnoreCase("--localdb")) {
table.put(LOCAL, "true");
} else if (token.equalsIgnoreCase("-d") || token.equalsIgnoreCase("--dbconfig")) {
- String configFile = at.nextSwitchToken();
+ String configFile = getRequiredSwitchArgument(at, token);
if (!new File(configFile).isAbsolute()) {
configFile = new File(System.getProperty("user.dir"), configFile).getAbsolutePath();
}
System.setProperty(Xindice.PROP_XINDICE_CONFIGURATION, configFile);
table.put(DB_CONFIG, configFile);
} else if (token.equalsIgnoreCase("-s") || token.equalsIgnoreCase("--namespaces")) {
- table.put(NAMESPACES, at.nextSwitchToken());
+ table.put(NAMESPACES, getRequiredSwitchArgument(at, token));
// Index specific options
} else if (token.equalsIgnoreCase("-t") || token.equalsIgnoreCase("--type")) {
- table.put(TYPE, at.nextSwitchToken());
+ table.put(TYPE, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("+trim")) {
if (!table.containsKey(TYPE)) {
table.put(TYPE, "trimmed");
@@ -253,20 +255,25 @@
table.put(TYPE, "string");
}
} else if (token.equalsIgnoreCase("--pagesize")) {
- table.put(PAGE_SIZE, at.nextSwitchToken());
+ table.put(PAGE_SIZE, getRequiredSwitchArgument(at, token));
+ } else if (token.equalsIgnoreCase("--pagecount")) {
+ table.put(PAGE_COUNT, getRequiredSwitchArgument(at, token));
} else if (token.equalsIgnoreCase("--maxkeysize")) {
- table.put(MAX_KEY_SIZE, at.nextSwitchToken());
+ table.put(MAX_KEY_SIZE, getRequiredSwitchArgument(at, token));
}
} // End of while loop
}
-
/**
* This method is to carry out execution, after instance variables being setup by process( args )
*/
public boolean execute() throws Exception {
init();
String action = (String) table.get(ACTION);
+ if (HELP.equals(action)) {
+ printHelp();
+ return true;
+ }
// get command class name
String commandClass = null;
@@ -278,50 +285,35 @@
if (action.equals(e.getAttribute("switch")) ||
action.equals(e.getAttribute("name"))) {
commandClass = e.getAttribute("class");
+ break;
}
}
}
- if (commandClass != null) {
- try {
- // Register Xindice Database with xml:db
- DatabaseImpl db = new DatabaseImpl();
- DatabaseManager.registerDatabase(db);
+ if (commandClass == null) {
+ throw new XindiceException("Unknown action '" + action + "'\n" +
+ "Type 'bin" + File.separatorChar + "xindice help' to see command usage");
+ }
- // Execute command class
- Command command = (Command) Class.forName(commandClass).newInstance();
- command.execute(table);
+ try {
+ // Register Xindice Database with xml:db
+ DatabaseImpl db = new DatabaseImpl();
+ DatabaseManager.registerDatabase(db);
- // Close Database
- if ("true".equals(table.get(LOCAL))) {
- command = new org.apache.xindice.tools.command.Shutdown();
- command.execute(table);
- }
-
- return true;
- } catch (XMLDBException e) {
- System.err.println("XMLDB Exception " + e.errorCode + ": " + e.getMessage());
- if (table.get(VERBOSE).equals("true")) {
- e.printStackTrace(System.err);
- }
- return false;
- } catch (Exception e) {
- System.err.println("ERROR : " + e.getMessage());
- if (table.get(VERBOSE).equals("true")) {
- e.printStackTrace(System.err);
- }
- return false;
+ // Execute command class
+ Command command = (Command) Class.forName(commandClass).newInstance();
+ command.execute(table);
+ } finally {
+ // Close Database
+ if ("true".equals(table.get(LOCAL))) {
+ Command command = new org.apache.xindice.tools.command.Shutdown();
+ command.execute(table);
}
}
- return false;
+ return true;
}
-
- public boolean handleOption(String option, ArgTokenizer at) {
- return false;
- }
-
/**
* setAction sets the action type that will be passed to the command line.
*
@@ -584,9 +576,7 @@
public void printHelp() {
NodeList list = getCommands();
- // This method relies on two things to format the output for help
- // Method isAdmin() - Tells us if this is an admin instance, used to hide certain output
- // XML file Commands.xml attribute "helpclass" - used to order output
+ // This method relies on XML file Commands.xml attribute "helpclass" - used to order output
String helpClass; // Holds the helpclass for the current node
String desc; // Holds the description for the current node
@@ -617,11 +607,14 @@
System.out.println(" -t Specify the data type in collection index");
System.out.println(" -v Verbose");
System.out.println(" --pagesize Page size for file pages (default: 4096)");
+ System.out.println(" --pagecount Number of pages in the primary storage (default: 1024)");
System.out.println(" --maxkeysize The maximum size for file keys (default: 0=none)");
System.out.println();
System.out.println("Actions:");
+ // show 'help' command
+ System.out.println(" " + StringUtilities.leftJustify(HELP, 13) + "Prints this screen");
// Show all elements with helpclass=document
// Loop over the commands, printing test from description attribute
for (int i = 0; i < list.getLength(); i++) {
Index: java/src/org/apache/xindice/tools/command/AddCollection.java
===================================================================
--- java/src/org/apache/xindice/tools/command/AddCollection.java (revision 471733)
+++ java/src/org/apache/xindice/tools/command/AddCollection.java (working copy)
@@ -93,6 +93,10 @@
filEle.setAttribute("pagesize", (String) table.get(XMLTools.PAGE_SIZE));
}
+ if (table.containsKey(XMLTools.PAGE_COUNT)) {
+ filEle.setAttribute("pagecount", (String) table.get(XMLTools.PAGE_COUNT));
+ }
+
if (table.containsKey(XMLTools.MAX_KEY_SIZE)) {
filEle.setAttribute("maxkeysize", (String) table.get(XMLTools.MAX_KEY_SIZE));
}
Index: java/src/org/apache/xindice/tools/command/AddIndexer.java
===================================================================
--- java/src/org/apache/xindice/tools/command/AddIndexer.java (revision 471733)
+++ java/src/org/apache/xindice/tools/command/AddIndexer.java (working copy)
@@ -82,6 +82,10 @@
idxEle.setAttribute("pagesize", (String) table.get(XMLTools.PAGE_SIZE));
}
+ if (table.containsKey(XMLTools.PAGE_COUNT)) {
+ idxEle.setAttribute("pagecount", (String) table.get(XMLTools.PAGE_COUNT));
+ }
+
if (table.containsKey(XMLTools.MAX_KEY_SIZE)) {
idxEle.setAttribute("maxkeysize", (String) table.get(XMLTools.MAX_KEY_SIZE));
}