edu.ucsb.nceas.metacat
Class QuerySpecification

java.lang.Object
  extended byorg.xml.sax.helpers.DefaultHandler
      extended byedu.ucsb.nceas.metacat.QuerySpecification
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

public class QuerySpecification
extends org.xml.sax.helpers.DefaultHandler

A Class that represents a structured query, and can be constructed from an XML serialization conforming to

See Also:
The printSQL() method can be used to print a SQL serialization of the query.

Field Summary
static java.lang.String ATTRIBUTESYMBOL
           
 
Constructor Summary
QuerySpecification(java.io.Reader queryspec, java.lang.String parserName, java.lang.String accNumberSeparator)
          construct an instance of the QuerySpecification class
QuerySpecification(java.lang.String accNumberSeparator)
          construct an instance of the QuerySpecification class which don't need to parser a xml document
QuerySpecification(java.lang.String queryspec, java.lang.String parserName, java.lang.String accNumberSeparator)
          construct an instance of the QuerySpecification class
 
Method Summary
 void characters(char[] ch, int start, int length)
          callback method used by the SAX Parser when the text sequences of an xml stream are detected.
 boolean containsAttributeReturnField()
          A method to get if the query has an attribute return field
 boolean containsExtendedSQL()
          Returns true if the parsed query contains and extended xml query (i.e.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          callback method used by the SAX Parser when the end tag of an element is detected.
 java.lang.String getAccessQuery()
          Method to append a access control query to SQL.
static java.lang.String getAttributeName(java.lang.String path)
          A method to get attribute name from path
 java.util.Vector getFilterDocList()
          Accessor method to return a vector of the filter doc types as defined in the <filterdoctype> tag in the pathquery dtd.
 java.lang.String getIdentifier()
          Accessor method to return the identifier of this Query
 java.util.Vector getOwnerList()
          Accessor method to return a vector of the owner fields as defined in the <owner> tag in the pathquery dtd.
 QueryGroup getQueryGroup()
          get the QueryGroup used to express query constraints
 java.lang.String getQueryTitle()
          Accessor method to return the title of this Query
 java.util.Vector getReturnDocList()
          Accessor method to return a vector of the return document types as defined in the <returndoctype> tag in the pathquery dtd.
 java.util.Vector getReturnFieldList()
          Accessor method to return a vector of the extended return fields as defined in the <returnfield> tag in the pathquery dtd.
 java.util.Vector getSiteList()
          Accessor method to return a vector of the site fields as defined in the <site> tag in the pathquery dtd.
 java.lang.String getSortedReturnFieldString()
          Method to return a String generated after sorting the returnFieldList Vector
 void handleReturnField(java.lang.String inputString)
          Method to transfer string to return field
 boolean isPercentageSearch()
          Method to indicate this query is a percentage search
static java.lang.String newPathExpressionWithOutAttribute(java.lang.String pathExpression)
          A method to get rid of attribute part in path expression
 java.lang.String printAccessControlSQLForReturnField(java.lang.String doclist)
          This sql command will selecet startnodeid and endnodeid that user can NOT access
 java.lang.String printAttributeQuery(java.lang.String doclist)
          This method prints sql that finds the values of attributes in the xml documents based upon the whether the returnfield tag in the pathquery document has an attribute symbol (@).
 java.lang.String printAttributeQuery(java.lang.String doclist, boolean useXMLIndex)
          This method prints sql that finds the values of attributes in the xml documents based upon the whether the returnfield tag in the pathquery document has an attribute symbol (@).
 java.lang.String printExtendedSQL(java.lang.String doclist, java.util.Hashtable unaccessableNodePair)
          This method prints sql based upon the <returnfield> tag in the pathquery document.
 java.lang.String printExtendedSQL(java.lang.String doclist, java.util.Hashtable unaccessableNodePair, boolean useXMLIndex)
          This method prints sql based upon the <returnfield> tag in the pathquery document.
static java.lang.String printGetDocByDoctypeSQL(java.lang.String docid)
           
static java.lang.String printRelationSQL(java.lang.String docid)
           
 java.lang.String printSQL(boolean useXMLIndex)
          create a SQL serialization of the query that this instance represents
 void setContainsExtenedSQL(boolean hasExtenedQuery)
          set if this query sepcification has extendQuery(has return doc type or not)
 void setFilterDocList(java.util.Vector filterDocList)
          method to set the list of filter docs of this query
 void setGroup(java.lang.String[] myGroup)
          Method to set user group
 void setIdentifier(java.lang.String id)
          method to set the identifier of this query
 void setOwnerList(java.util.Vector ownerList)
          method to set the list of owners used to constrain this query
 void setQueryGroup(QueryGroup group)
          set the querygroup
 void setQueryTitle(java.lang.String title)
          method to set the title of this query
 void setReturnDocList(java.util.Vector returnDocList)
          method to set the list of return docs of this query
 void setReturnFieldList(java.util.Vector returnFieldList)
          method to set the list of fields to be returned by this query
 void setSiteList(java.util.Vector siteList)
          method to set the list of sites used to constrain this query
 void setUserName(java.lang.String myName)
          Method to set user name
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)
          callback method used by the SAX Parser when the start tag of an element is detected.
 java.lang.String toString()
          create a String description of the query that this instance represents.
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endDocument, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ATTRIBUTESYMBOL

public static final java.lang.String ATTRIBUTESYMBOL
See Also:
Constant Field Values
Constructor Detail

QuerySpecification

public QuerySpecification(java.io.Reader queryspec,
                          java.lang.String parserName,
                          java.lang.String accNumberSeparator)
                   throws java.io.IOException
construct an instance of the QuerySpecification class

Parameters:
queryspec - the XML representation of the query (should conform to pathquery.dtd) as a Reader
parserName - the fully qualified name of a Java Class implementing the org.xml.sax.XMLReader interface

QuerySpecification

public QuerySpecification(java.lang.String queryspec,
                          java.lang.String parserName,
                          java.lang.String accNumberSeparator)
                   throws java.io.IOException
construct an instance of the QuerySpecification class

Parameters:
queryspec - the XML representation of the query (should conform to pathquery.dtd) as a String
parserName - the fully qualified name of a Java Class implementing the org.xml.sax.Parser interface

QuerySpecification

public QuerySpecification(java.lang.String accNumberSeparator)
                   throws java.io.IOException
construct an instance of the QuerySpecification class which don't need to parser a xml document

Parameters:
accNumberSeparator - the separator between doc version
Method Detail

setUserName

public void setUserName(java.lang.String myName)
Method to set user name

Parameters:
myName - the user name

setGroup

public void setGroup(java.lang.String[] myGroup)
Method to set user group

Parameters:
myGroup - the user group

isPercentageSearch

public boolean isPercentageSearch()
Method to indicate this query is a percentage search


getAccessQuery

public java.lang.String getAccessQuery()
Method to append a access control query to SQL. So in DBQuery class, we can get docid from both user specified query and access control query. We don't need to checking permission after we get the doclist. It will be good to performance


containsExtendedSQL

public boolean containsExtendedSQL()
Returns true if the parsed query contains and extended xml query (i.e. there is at least one <returnfield> in the pathquery document)


containsAttributeReturnField

public boolean containsAttributeReturnField()
A method to get if the query has an attribute return field


getIdentifier

public java.lang.String getIdentifier()
Accessor method to return the identifier of this Query


setIdentifier

public void setIdentifier(java.lang.String id)
method to set the identifier of this query


getQueryTitle

public java.lang.String getQueryTitle()
Accessor method to return the title of this Query


setQueryTitle

public void setQueryTitle(java.lang.String title)
method to set the title of this query


getReturnDocList

public java.util.Vector getReturnDocList()
Accessor method to return a vector of the return document types as defined in the <returndoctype> tag in the pathquery dtd.


setReturnDocList

public void setReturnDocList(java.util.Vector returnDocList)
method to set the list of return docs of this query


getFilterDocList

public java.util.Vector getFilterDocList()
Accessor method to return a vector of the filter doc types as defined in the <filterdoctype> tag in the pathquery dtd.


setFilterDocList

public void setFilterDocList(java.util.Vector filterDocList)
method to set the list of filter docs of this query


getReturnFieldList

public java.util.Vector getReturnFieldList()
Accessor method to return a vector of the extended return fields as defined in the <returnfield> tag in the pathquery dtd.


setReturnFieldList

public void setReturnFieldList(java.util.Vector returnFieldList)
method to set the list of fields to be returned by this query


getOwnerList

public java.util.Vector getOwnerList()
Accessor method to return a vector of the owner fields as defined in the <owner> tag in the pathquery dtd.


setOwnerList

public void setOwnerList(java.util.Vector ownerList)
method to set the list of owners used to constrain this query


getSiteList

public java.util.Vector getSiteList()
Accessor method to return a vector of the site fields as defined in the <site> tag in the pathquery dtd.


setSiteList

public void setSiteList(java.util.Vector siteList)
method to set the list of sites used to constrain this query


getQueryGroup

public QueryGroup getQueryGroup()
get the QueryGroup used to express query constraints


setQueryGroup

public void setQueryGroup(QueryGroup group)
set the querygroup


setContainsExtenedSQL

public void setContainsExtenedSQL(boolean hasExtenedQuery)
set if this query sepcification has extendQuery(has return doc type or not)


startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes atts)
                  throws org.xml.sax.SAXException
callback method used by the SAX Parser when the start tag of an element is detected. Used in this context to parse and store the query information in class variables.

Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.SAXException
callback method used by the SAX Parser when the end tag of an element is detected. Used in this context to parse and store the query information in class variables.

Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
callback method used by the SAX Parser when the text sequences of an xml stream are detected. Used in this context to parse and store the query information in class variables.


handleReturnField

public void handleReturnField(java.lang.String inputString)
Method to transfer string to return field


printSQL

public java.lang.String printSQL(boolean useXMLIndex)
create a SQL serialization of the query that this instance represents


printAccessControlSQLForReturnField

public java.lang.String printAccessControlSQLForReturnField(java.lang.String doclist)
This sql command will selecet startnodeid and endnodeid that user can NOT access


printExtendedSQL

public java.lang.String printExtendedSQL(java.lang.String doclist,
                                         java.util.Hashtable unaccessableNodePair,
                                         boolean useXMLIndex)
This method prints sql based upon the <returnfield> tag in the pathquery document. This allows for customization of the returned fields. If the boolean useXMLIndex paramter is false, it uses a recursive query on xml_nodes to find the fields to be included by their path expression, and avoids the use of the xml_index table.

Parameters:
doclist - the list of document ids to search
unaccessableNodePair - the node pairs (start id and end id) which this user should not access
useXMLIndex - a boolean flag indicating whether to search using xml_index

printExtendedSQL

public java.lang.String printExtendedSQL(java.lang.String doclist,
                                         java.util.Hashtable unaccessableNodePair)
This method prints sql based upon the <returnfield> tag in the pathquery document. This allows for customization of the returned fields. It uses the xml_index table and so assumes that this table has been built.

Parameters:
doclist - the list of document ids to search
unaccessableNodePair - the node pairs (start id and end id) which this user should not access

getSortedReturnFieldString

public java.lang.String getSortedReturnFieldString()
Method to return a String generated after sorting the returnFieldList Vector


printAttributeQuery

public java.lang.String printAttributeQuery(java.lang.String doclist,
                                            boolean useXMLIndex)
This method prints sql that finds the values of attributes in the xml documents based upon the whether the returnfield tag in the pathquery document has an attribute symbol (@). This allows for customization of the returned fields.

Parameters:
doclist - the list of document ids to search
useXMLIndex - a boolean flag indicating whether to search using xml_index

printAttributeQuery

public java.lang.String printAttributeQuery(java.lang.String doclist)
This method prints sql that finds the values of attributes in the xml documents based upon the whether the returnfield tag in the pathquery document has an attribute symbol (@). This allows for customization of the returned fields.

Parameters:
doclist - the list of document ids to search

printRelationSQL

public static java.lang.String printRelationSQL(java.lang.String docid)

printGetDocByDoctypeSQL

public static java.lang.String printGetDocByDoctypeSQL(java.lang.String docid)

toString

public java.lang.String toString()
create a String description of the query that this instance represents. This should become a way to get the XML serialization of the query.


newPathExpressionWithOutAttribute

public static java.lang.String newPathExpressionWithOutAttribute(java.lang.String pathExpression)
A method to get rid of attribute part in path expression


getAttributeName

public static java.lang.String getAttributeName(java.lang.String path)
A method to get attribute name from path



Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.