X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=src%2Forg%2Fz3950%2Fzing%2Fcql%2FCQLGenerator.java;h=991f60dbc535636273af256a8692d4f9bb6f6ef5;hb=08b7f3f08d97b9efdd5a3aef7992a359b71910d6;hp=bc732e27859065cd77ccdd9dfb8e3d76f3ceb1b7;hpb=70be8275aabe87c909bf11148bb279c3e1380bb2;p=cql-java-moved-to-github.git diff --git a/src/org/z3950/zing/cql/CQLGenerator.java b/src/org/z3950/zing/cql/CQLGenerator.java index bc732e2..991f60d 100644 --- a/src/org/z3950/zing/cql/CQLGenerator.java +++ b/src/org/z3950/zing/cql/CQLGenerator.java @@ -1,4 +1,4 @@ -// $Id: CQLGenerator.java,v 1.1 2002-10-30 09:19:26 mike Exp $ +// $Id: CQLGenerator.java,v 1.3 2002-11-03 16:49:38 mike Exp $ package org.z3950.zing.cql; import java.util.Properties; @@ -22,7 +22,7 @@ import java.io.FileNotFoundException; * this distribution - there is a generate_x() method * for each grammar element X. * - * @version $Id: CQLGenerator.java,v 1.1 2002-10-30 09:19:26 mike Exp $ + * @version $Id: CQLGenerator.java,v 1.3 2002-11-03 16:49:38 mike Exp $ * @see http://zing.z3950.org/cql/index.html */ @@ -154,8 +154,9 @@ public class CQLGenerator { return generate_cql_query(); } + // ### Should sometimes generate qualifier/relation-free terms String qualifier = generate_qualifier(); - String relation = generate_relation(); + CQLRelation relation = generate_relation(); String term = generate_term(); return new CQLTermNode(qualifier, relation, term); @@ -182,10 +183,11 @@ public class CQLGenerator { return qualifier; } - // ### Representation of relations will change when we handle modifiers - private String generate_relation() throws ParameterMissingException { - return generate_base_relation(); + private CQLRelation generate_relation() throws ParameterMissingException { + String base = generate_base_relation(); + CQLRelation rel = new CQLRelation(base); // ### should generate modifiers too + return rel; } private String generate_base_relation() throws ParameterMissingException { @@ -258,13 +260,14 @@ public class CQLGenerator { * A simple test-harness for the generator. *

* It generates a single random query using the parameters - * specified in a nominated properties file, and decompiles it - * into CQL which is written to standard output. + * specified in a nominated properties file, plus any additional + * name value pairs provided on the command-line, and + * decompiles it into CQL which is written to standard output. *

* For example, - * java org.z3950.zing.cql.CQLGenerator etc/generate.properties + * java org.z3950.zing.cql.CQLGenerator + * etc/generate.properties seed 18398, * where the file generate.properties contains:

-     *	seed=18398
      *	complexQuery=0.4
      *	complexClause=0.4
      *	equalsRelation=0.5
@@ -279,13 +282,19 @@ public class CQLGenerator {
      * @param configFile
      *	The name of a properties file from which to read the
      *	configuration parameters (see above).
+     * @param name
+     *	The name of a configuration parameter.
+     * @param value
+     *	The value to assign to the configuration parameter named in
+     *	the immediately preceding command-line argument.
      * @return
      *	A CQL query expressed in a form that should be comprehensible
      *	to all conformant CQL compilers.
      */
     public static void main (String[] args) throws Exception {
-	if (args.length != 1) {
-	    System.err.println("Usage: CQLGenerator ");
+	if (args.length % 2 != 1) {
+	    System.err.println("Usage: CQLGenerator  "+
+			       "[ ]...");
 	    System.exit(1);
 	}
 
@@ -298,6 +307,8 @@ public class CQLGenerator {
 	Properties params = new Properties();
 	params.load(f);
 	f.close();
+	for (int i = 1; i < args.length; i += 2)
+	    params.setProperty(args[i], args[i+1]);
 
 	CQLGenerator generator = new CQLGenerator(params);
 	CQLNode tree = generator.generate();