diff options
| author | Andrei Aiordachioaie <a.aiordachioaie@jacobs-university.de> | 2009-05-25 10:23:43 +0200 |
|---|---|---|
| committer | Andrei Aiordachioaie <andrei@kahlua.eecs.jacobs-university.de> | 2009-07-07 10:50:05 +0200 |
| commit | 256aa4ff66f4bcd87e9c9b3ae5fcd4455a65f67f (patch) | |
| tree | cc4c83035d4b61f58f661463e9ad8845c37672ad /src/wcps/server/cli | |
| parent | fcf40c09879355d0b1860cf5545ac26ac0aca681 (diff) | |
Updated WCPS source code to match spec WCPS 1.0.0
Diffstat (limited to 'src/wcps/server/cli')
| -rw-r--r-- | src/wcps/server/cli/WCPService.java | 126 | ||||
| -rw-r--r-- | src/wcps/server/cli/grammar.java | 53 | ||||
| -rw-r--r-- | src/wcps/server/cli/xml.java | 163 |
3 files changed, 216 insertions, 126 deletions
diff --git a/src/wcps/server/cli/WCPService.java b/src/wcps/server/cli/WCPService.java deleted file mode 100644 index 2090109..0000000 --- a/src/wcps/server/cli/WCPService.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * This file is part of Petascope. - * - * Petascope is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * Petascope is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with Petascope. If not, see <http://www.gnu.org/licenses/>. - * - * For more information please see <http://www.Petascope.org> - * or contact Peter Baumann via <baumann@rasdaman.com>. - * - * Copyright 2009 Jacobs University Bremen, Peter Baumann. - */ - -package wcps.server.cli; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.util.Iterator; -import java.util.List; -import java.util.Properties; - -import wcps.server.core.CachedMetadataSource; -import wcps.server.core.DbMetadataSource; -import wcps.server.core.ProcessCoverageRequest; -import wcps.server.core.WCPS; - -// This is a small application around the WCPS core. It takes XML requests as files and runs them through WCPS. The resulting radaman queries are displayed, but not executed. This is very useful for testing whether your metadata is valid. - -public class WCPService { - - private static WCPS wcps; - - public static void main( String[] args ) { - - if( args.length != 1 ) { - System.err.println( "WCPS: no input files" ); - System.exit( 1 ); - } - - String pcSchemaFileName = ".." + File.separator + "xml" + File.separator + "ogc" + File.separator + "wcps" + File.separator + "1.0.0" + File.separator + "wcpsProcessCoverage.xsd"; - File pcSchemaFile = new File( pcSchemaFileName ); - if( !pcSchemaFile.exists() ) { - System.err.println( "WCPS: could not find the WCPS ProcessCoverage schema (" + pcSchemaFileName + ")" ); - System.exit( 1 ); - } - - DbMetadataSource metadataSource = null; - try { - Properties dbParams = new Properties(); - dbParams.load( new FileInputStream( ".." + File.separator + "dbparams.properties" ) ); - metadataSource = new DbMetadataSource( dbParams.getProperty( "metadata_driver" ), dbParams.getProperty( "metadata_url" ), dbParams.getProperty( "metadata_user" ), dbParams.getProperty( "metadata_pass" ), false ); - wcps = new WCPS( pcSchemaFile, new CachedMetadataSource( metadataSource ) ); - } - catch( Exception e ) { - System.err.println( "WCPS: could not initialize WCPS:" ); - e.printStackTrace( System.err ); - System.exit( 1 ); - } - - for( int i = 0; i < args.length; i++ ) { - File fileIn = null; - try { - fileIn = new File( args[i] ); - } - catch( Exception fnfe ) { - System.err.println( "WCPS: " + args[i] + ": no such file or directory" + fnfe ); - System.exit( 1 ); - } - boolean ok = processCoverage( fileIn, i ); - if( !ok ) { - System.err.println( "WCPS: " + args[i] + " failed" ); - System.exit( 1 ); - } - } - - metadataSource.close(); - System.exit( 0 ); - - } - - // TODO: Here's a fun idea: make this function multithreaded! ;) - private static boolean processCoverage( File in, int i ) { - - try { - - ProcessCoverageRequest r = wcps.pcPrepare("http://kahlua.eecs.jacobs-university.de:7001", "RASSERVICE", in ); - - System.err.println( "Request " + i ); - - System.out.println( r.getQuery() ); - - -/* Iterator<byte[]> results = r.execute().iterator(); - - int j = 0; - while( results.hasNext() ) { - String outFileName = "WCPS-" + i + "-" + j++; - FileOutputStream out = new FileOutputStream( outFileName ); - out.write( results.next() ); - out.close(); - System.out.println( "WCPS: " + outFileName + " written" ); - }*/ - - } - catch( Exception e ) { - System.err.println( "WCPS: request " + i + " failed with the following exception:" ); - e.printStackTrace( System.err ); - } - - return true; - - } - -} diff --git a/src/wcps/server/cli/grammar.java b/src/wcps/server/cli/grammar.java new file mode 100644 index 0000000..879b814 --- /dev/null +++ b/src/wcps/server/cli/grammar.java @@ -0,0 +1,53 @@ +package wcps.server.cli; + +import grammar.*; +import grammar.wcpsParser.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import org.antlr.runtime.ANTLRInputStream; +import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.RecognitionException; + +/** Test the WCPS grammar parser (generated by ANTLR). + * Input a Abstract Syntax query. + * Outputs the corresponding XML tree. + * + * @author Andrei Aiordachioaie + */ +public class grammar { + + static String query; + + public static void main(String[] args) throws RecognitionException, IOException + { + if (args.length != 1) + { + System.err.println("AbstractGrammarGen: no query as parameter !"); + // What is the meaning of AxisIterator variable and axis type? Query 15, 16 + // Query 4: cast should not be this greedy! (float)a + b != (float) (a+b) + query = "for s in ( rgb, rgb, rgb ), r in ( rgb ) return count( ((s.0-s.1)/(s.0+s.1) > 0.6) * r )"; + } + else + query = args[0]; + + System.out.println("Running with the following query: " + query); + + InputStream stream = new ByteArrayInputStream(query.getBytes()); // defaults to ISO-1 + ANTLRInputStream inputStream = new ANTLRInputStream(stream); +// wcpsLexer lexer = new wcpsLexer( inputStream ); + wcpsLexer lexer = new wcpsLexer( inputStream ); + + CommonTokenStream tokenStream = new CommonTokenStream(lexer); +// wcpsParser parser = new wcpsParser(tokenStream); + wcpsParser parser = new wcpsParser(tokenStream); + + wcpsRequest_return rrequest = parser.wcpsRequest(); + WCPSRequest request = rrequest.value; + System.out.println("Output XML: \n****************\n" + request.toXML()); + + System.exit(0); + + } + +} diff --git a/src/wcps/server/cli/xml.java b/src/wcps/server/cli/xml.java new file mode 100644 index 0000000..725a878 --- /dev/null +++ b/src/wcps/server/cli/xml.java @@ -0,0 +1,163 @@ +/*
+ * This file is part of PetaScope.
+ *
+ * PetaScope is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of
+ * the License, or (at your option) any later version.
+ *
+ * PetaScope is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with PetaScope. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * For more information please see <http://www.PetaScope.org>
+ * or contact Peter Baumann via <baumann@rasdaman.com>.
+ *
+ * Copyright 2009 Jacobs University Bremen, Peter Baumann.
+ */
+
+
+package wcps.server.cli;
+
+import wcps.server.core.CachedMetadataSource;
+import wcps.server.core.DbMetadataSource;
+import wcps.server.core.ProcessCoveragesRequest;
+import wcps.server.core.WCPS;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import java.util.Properties;
+
+/**
+ * This is a small application around the WCPS core. It takes XML requests as files and runs them
+ * through WCPS. The resulting radaman queries are displayed, but not executed. This is very useful
+ * for testing whether your metadata is valid.
+ */
+
+
+public class xml
+{
+ private static WCPS wcps;
+
+ public static void main(String[] args)
+ {
+ if (args.length < 1)
+ {
+ System.err.println("WCPS CLI: no input files");
+
+ System.err.println("\nWCPS CLI Usage: java wcps.server.cli.xml input.xml");
+ System.err.println("Where input.xml contains a ProcessCoverages Request ");
+ System.exit(1);
+
+ args = new String[1];
+ args[0] = "old_testing/testcases/1.test.xml";
+ }
+ if (args.length > 1)
+ {
+ System.err.println("WCPS: no input files");
+ System.exit(1);
+ }
+
+ String pcSchemaFileName = "src" + File.separator + "conf" + File.separator + "xml"
+ + File.separator + "wcps"
+ + File.separator + "1.0.0" + File.separator + "wcpsProcessCoverages.xsd";
+ File pcSchemaFile = new File(pcSchemaFileName);
+
+ if (!pcSchemaFile.exists())
+ {
+ System.err.println("WCPS: could not find the WCPS ProcessCoverage schema ("
+ + pcSchemaFileName + ")");
+ System.exit(1);
+ }
+
+ DbMetadataSource metadataSource = null;
+
+ try
+ {
+ Properties dbParams = new Properties();
+
+ dbParams.load(new FileInputStream("dbparams.properties"));
+ metadataSource =
+ new DbMetadataSource(dbParams.getProperty("metadata_driver"),
+ dbParams.getProperty("metadata_url"),
+ dbParams.getProperty("metadata_user"),
+ dbParams.getProperty("metadata_pass"), false);
+ wcps = new WCPS(pcSchemaFile, new CachedMetadataSource(metadataSource));
+ }
+ catch (Exception e)
+ {
+ System.err.println("WCPS: could not initialize WCPS:");
+ e.printStackTrace(System.err);
+ System.exit(1);
+ }
+
+ for (int i = 0; i < args.length; i++)
+ {
+ File fileIn = null;
+
+ try
+ {
+ fileIn = new File(args[i]);
+ }
+ catch (Exception fnfe)
+ {
+ System.err.println("WCPS: " + args[i]
+ + ": no such file or directory" + fnfe);
+ System.exit(1);
+ }
+
+ boolean ok = processCoverage(fileIn, i);
+
+ if (!ok)
+ {
+ System.err.println("WCPS: " + args[i] + " failed");
+ System.exit(1);
+ }
+ }
+
+ metadataSource.close();
+ System.exit(0);
+
+ }
+
+ private static boolean processCoverage(File in, int i)
+ {
+ try
+ {
+
+ ProcessCoveragesRequest r =
+ wcps.pcPrepare("http://kahlua.eecs.jacobs-university.de:7001",
+ "RASSERVICE", in);
+
+ System.err.println("Request " + i);
+
+ System.out.println(r.getRasqlQuery());
+
+
+/* Iterator<byte[]> results = r.execute().iterator();
+
+ int j = 0;
+ while( results.hasNext() ) {
+ String outFileName = "WCPS-" + i + "-" + j++;
+ FileOutputStream out = new FileOutputStream( outFileName );
+ out.write( results.next() );
+ out.close();
+ System.out.println( "WCPS: " + outFileName + " written" );
+ }*/
+ }
+ catch (Exception e)
+ {
+ System.err.println("WCPS: request " + i
+ + " failed with the following exception:");
+ e.printStackTrace(System.err);
+ }
+
+ return true;
+
+ }
+}
|
