org.z3950.zing.cql
Class CQLNode

java.lang.Object
  extended by org.z3950.zing.cql.CQLNode
Direct Known Subclasses:
CQLBooleanNode, CQLPrefixNode, CQLRelation, CQLSortNode, CQLTermNode

public abstract class CQLNode
extends java.lang.Object

Represents a node in a CQL parse-tree.

Version:
$Id: CQLNode.java,v 1.26 2007-07-03 13:36:03 mike Exp $

Field Summary
protected static int APPLICATION
           
static byte BITSTRING
           
static byte BOOLEAN
           
protected static int CONSTRUCTED
           
protected static int CONTEXT
           
static byte ENUMERATED
           
static byte EXTERNAL
           
static byte GENERALSTRING
           
static byte INTEGER
           
static byte NULL
           
static byte OBJECTDESCRIPTOR
           
static byte OBJECTIDENTIFIER
           
static byte OCTETSTRING
           
protected static int PRIMITIVE
           
protected static int PRIVATE
           
static byte SEQUENCE
           
static byte SET
           
protected static int UNIVERSAL
           
static byte VISIBLESTRING
           
 
Method Summary
 java.lang.String getResultSetName()
          Returns the name of the result-set to which this query is a reference, if and only if the entire query consists only of a result-set reference.
protected static java.lang.String indent(int level)
          Returns a String of spaces for indenting to the specified level.
protected static int lenLen(int length)
          Get the length needed to represent the given length.
protected static byte[] makeOID(java.lang.String oid)
           
static byte[] makeQuery(CQLNode root, java.util.Properties properties)
           
protected static int numLen(long num)
          Get the length needed to represent the given number.
static int putLen(int len, byte[] record, int offset)
          Put a length directly into a BER record.
protected static int putNum(long num, byte[] record, int offset)
          Put a number into a given buffer
protected static int putTag(int asn1class, int fldid, int form, byte[] record, int offset)
           
protected static java.lang.String renderPrefixes(int level, java.util.Vector prefixes)
           
protected static java.lang.String renderSortKeys(int level, java.util.Vector<ModifierSet> sortkeys)
           
abstract  java.lang.String toCQL()
          Decompiles a parse-tree into a CQL query.
abstract  java.lang.String toPQF(java.util.Properties config)
          Renders a parse-tree into a Yaz-style PQF string.
abstract  byte[] toType1BER(java.util.Properties config)
          Renders a parser-tree into a BER-endoded packet representing an equivalent Z39.50 Type-1 query.
 java.lang.String toXCQL(int level)
          Translates a parse-tree into an XCQL document.
 java.lang.String toXCQL(int level, java.util.Vector<CQLPrefix> prefixes)
           
abstract  java.lang.String toXCQL(int level, java.util.Vector<CQLPrefix> prefixes, java.util.Vector<ModifierSet> sortkeys)
           
protected static java.lang.String xq(java.lang.String str)
          Returns the argument String quoted for XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIVERSAL

protected static final int UNIVERSAL
See Also:
Constant Field Values

APPLICATION

protected static final int APPLICATION
See Also:
Constant Field Values

CONTEXT

protected static final int CONTEXT
See Also:
Constant Field Values

PRIVATE

protected static final int PRIVATE
See Also:
Constant Field Values

PRIMITIVE

protected static final int PRIMITIVE
See Also:
Constant Field Values

CONSTRUCTED

protected static final int CONSTRUCTED
See Also:
Constant Field Values

BOOLEAN

public static final byte BOOLEAN
See Also:
Constant Field Values

INTEGER

public static final byte INTEGER
See Also:
Constant Field Values

BITSTRING

public static final byte BITSTRING
See Also:
Constant Field Values

OCTETSTRING

public static final byte OCTETSTRING
See Also:
Constant Field Values

NULL

public static final byte NULL
See Also:
Constant Field Values

OBJECTIDENTIFIER

public static final byte OBJECTIDENTIFIER
See Also:
Constant Field Values

OBJECTDESCRIPTOR

public static final byte OBJECTDESCRIPTOR
See Also:
Constant Field Values

EXTERNAL

public static final byte EXTERNAL
See Also:
Constant Field Values

ENUMERATED

public static final byte ENUMERATED
See Also:
Constant Field Values

SEQUENCE

public static final byte SEQUENCE
See Also:
Constant Field Values

SET

public static final byte SET
See Also:
Constant Field Values

VISIBLESTRING

public static final byte VISIBLESTRING
See Also:
Constant Field Values

GENERALSTRING

public static final byte GENERALSTRING
See Also:
Constant Field Values
Method Detail

getResultSetName

public java.lang.String getResultSetName()
Returns the name of the result-set to which this query is a reference, if and only if the entire query consists only of a result-set reference. If it's anything else, including a boolean combination of a result-set reference with something else, then null is returned instead.

Returns:
the name of the referenced result-set

toXCQL

public java.lang.String toXCQL(int level)
Translates a parse-tree into an XCQL document.

Parameters:
level - The number of levels to indent the top element of the XCQL document. This will typically be 0 when invoked by an application; it takes higher values when this method is invoked recursively for nodes further down the tree.
Returns:
A String containing an XCQL document equivalent to the parse-tree whose root is this node.

toXCQL

public java.lang.String toXCQL(int level,
                               java.util.Vector<CQLPrefix> prefixes)

toXCQL

public abstract java.lang.String toXCQL(int level,
                                        java.util.Vector<CQLPrefix> prefixes,
                                        java.util.Vector<ModifierSet> sortkeys)

renderPrefixes

protected static java.lang.String renderPrefixes(int level,
                                                 java.util.Vector prefixes)

renderSortKeys

protected static java.lang.String renderSortKeys(int level,
                                                 java.util.Vector<ModifierSet> sortkeys)

toCQL

public abstract java.lang.String toCQL()
Decompiles a parse-tree into a CQL query.

Returns:
A String containing a CQL query equivalent to the parse-tree whose root is this node, so that compiling that query will yield an identical tree.

toPQF

public abstract java.lang.String toPQF(java.util.Properties config)
                                throws PQFTranslationException
Renders a parse-tree into a Yaz-style PQF string. PQF, or Prefix Query Format, is a cryptic but powerful notation that can be trivially mapped, one-to-one, int Z39.50 Type-1 and Type-101 queries. A specification for the format can be found in Chapter 7 (Supporting Tools) of the YAZ manual.

Parameters:
config - A Properties object containing configuration information that specifies the mapping from CQL indexes, relations, etc. to Type-1 attributes. The mapping specification is described in the CQL-Java distribution's sample PQF-mapping configuration file, etc/pqf.properties, which see.
Returns:
A String containing a PQF query equivalent to the parse-tree whose root is this node.
Throws:
PQFTranslationException

indent

protected static java.lang.String indent(int level)
Returns a String of spaces for indenting to the specified level.


xq

protected static java.lang.String xq(java.lang.String str)
Returns the argument String quoted for XML. For example, each occurrence of < is translated to &lt;.


toType1BER

public abstract byte[] toType1BER(java.util.Properties config)
                           throws PQFTranslationException
Renders a parser-tree into a BER-endoded packet representing an equivalent Z39.50 Type-1 query. If you don't know what that means, then you don't need this method :-) This is useful primarily for SRW-to-Z39.50 gateways.

Parameters:
config - A Properties object containing configuration information that specifies the mapping from CQL indexes, relations, etc. to Type-1 attributes. The mapping specification is described in the CQL-Java distribution's sample PQF-mapping configuration file, etc/pqf.properties, which see.
Returns:
A byte array containing the BER packet.
Throws:
PQFTranslationException
See Also:
ftp://ftp.rsasecurity.com/pub/pkcs/ascii/layman.asc

putTag

protected static final int putTag(int asn1class,
                                  int fldid,
                                  int form,
                                  byte[] record,
                                  int offset)

putLen

public static final int putLen(int len,
                               byte[] record,
                               int offset)
Put a length directly into a BER record.

Parameters:
len - length to put into record
Returns:
the new, incremented value of the offset parameter.

lenLen

protected static final int lenLen(int length)
Get the length needed to represent the given length.

Parameters:
length - determine length needed to encode this
Returns:
length needed to encode given length

numLen

protected static final int numLen(long num)
Get the length needed to represent the given number.

Parameters:
num - determine length needed to encode this
Returns:
length needed to encode given number

putNum

protected static final int putNum(long num,
                                  byte[] record,
                                  int offset)
Put a number into a given buffer

Parameters:
num - number to put into buffer
record - buffer to use
offset - offset into buffer
Returns:
the new, incremented value of the offset parameter.

makeOID

protected static final byte[] makeOID(java.lang.String oid)

makeQuery

public static final byte[] makeQuery(CQLNode root,
                                     java.util.Properties properties)
                              throws PQFTranslationException
Throws:
PQFTranslationException