edu.ucsb.adl.bucket99
Class PythonQueryTranslator

java.lang.Object
  |
  +--edu.ucsb.adl.bucket99.PythonQueryTranslator
All Implemented Interfaces:
QueryTranslator

public final class PythonQueryTranslator
extends java.lang.Object
implements QueryTranslator

Query translator that translates queries by executing a Python script. The script is loaded once (only) and the vocabularies associated with hierarchical buckets, i.e., an object of Java type Vocabulary[], is bound to Python variable vocabularies. To translate a query, the translator binds the query's root constraint node to Python variable constraint, the query's ranking method (or None if not present) to Python variable rankingMethod, and the query's result limit (or -1 if not present) to Python variable maximumResults, and invokes Python function translate(). The function should return either an SQL query as a string if successful, or a MiddlewareException (specifically, an UnsupportedException or an InternalErrorException) if not. Any exception thrown by the Python interpreter itself is treated as an InternalErrorException.

This class reads the following properties from Bucket99 configuration files. Property values may be indirectly specified using the notation @P where P is the name of another property (see ExtendedProperties for more information).

translator.script
The filename of the Python script. If the filename is not absolute, it is interpreted relative to the directory containing the Bucket99 configuration file.
translator.python_module_path
A pathlist of zero or more directories in which modules referenced by the Python script may be found, e.g., "/python/modules:../python/lib". The pathlist is appended to Python's python.path registry variable. Directories that are not absolute are interpreted relative to the directory containing the Bucket99 configuration file. (Note: this property is in addition to property jython.module_path in the main middleware configuration file.)
translator.python_class_path
A pathlist of zero or more directories in which Java class files referenced by the Python script may be found, e.g., "../../../classes". Directories that are not absolute are interpreted relative to the directory containing the Bucket99 configuration file. (Note: this property is in addition to property jython.class_path in the main middleware configuration file.)
translator.python_jar_path
A pathlist of zero or more directories in which JAR files referenced by the Python script may be found, and in particular, in which the middleware may be found, e.g., "../../../lib". Directories that are not absolute are interpreted relative to the directory containing the Bucket99 configuration file. (Note: this property is in addition to property jython.jar_path in the main middleware configuration file.)
translator.vocabularies
The names of all hierarchical bucket vocabularies separated by commas, e.g., "TYPES,FORMATS".
V.class
For vocabulary V, the fully-qualified name of the vocabulary class, e.g., "edu.ucsb.adl.bucket99.DatabaseCodedVocabulary".

Version:
$Header: /export/home/gjanee/bucket99/edu/ucsb/adl/bucket99/RCS/PythonQueryTranslator.java,v 1.8 2007/02/14 22:11:21 gjanee Exp $

$Log: PythonQueryTranslator.java,v $ Revision 1.8 2007/02/14 22:11:21 gjanee
The query ranking method and result limit are now passed to the Python script.

Revision 1.7 2004/09/23 17:20:44 gjanee
Rewrite to use class edu.ucsb.adl.middleware.ExtendedProperties.

Revision 1.6 2004/09/14 21:20:54 gjanee
Added some documentation.

Revision 1.5 2002/09/28 21:15:33 gjanee
Configuration file renames. Renamed the Bucket99 configuration file to bucket99.conf.

Revision 1.4 2001/10/14 14:27:52 gjanee
To get the Jython implementation of Python to work when the middleware is packaged as a JAR file within a web application, added the translator.python_class_path and translator.python_jar_path properties. Renamed the translator.python_path property to translator.python_module_path.

Revision 1.3 2001/10/10 03:01:20 gjanee
Added the translator.python_path property.

Revision 1.2 2001/10/09 20:36:27 gjanee
Added support for relative filenames.

Revision 1.1 2000/10/15 02:35:33 gjanee
Initial revision

Author:
Greg Janée
Alexandria Digital Library

Method Summary
static edu.ucsb.adl.bucket99.PythonQueryTranslator createTranslator(edu.ucsb.adl.middleware.ExtendedProperties propertyList)
          Creates a PythonQueryTranslator.
 void destroy()
          Frees all resources held by the translator.
static void main(java.lang.String[] args)
          Test driver.
 java.lang.String translate(edu.ucsb.adl.middleware.Query query)
          Translates a query to SQL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createTranslator

public static edu.ucsb.adl.bucket99.PythonQueryTranslator createTranslator(edu.ucsb.adl.middleware.ExtendedProperties propertyList)
                                                                    throws InternalErrorException
Creates a PythonQueryTranslator.

Parameters:
propertyList - The source for the above-mentioned properties.
Returns:
A PythonQueryTranslator.
Throws:
InternalErrorException - If any error is encountered.

translate

public java.lang.String translate(edu.ucsb.adl.middleware.Query query)
                           throws MiddlewareException
Translates a query to SQL.

Specified by:
translate in interface QueryTranslator
Parameters:
query - The query.
Returns:
An SQL query.
Throws:
UnsupportedException - If the query is not supported.
InternalErrorException - If any other error occurs.
MiddlewareException

destroy

public void destroy()
Frees all resources held by the translator.

Specified by:
destroy in interface QueryTranslator

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException,
                        MiddlewareException
Test driver.

java.io.IOException
MiddlewareException