📄 indexservice.java
字号:
package net.jxta.index;
import java.io.*;
/**
* IndexService allows for indexing of XML documents
* and execution of XPath queries, and also for indexing
* of XPath queries and matching them against XML documents.
*/
public interface IndexService {
/**
* Create an index structure for indexing documents.
*/
Index getIndex (File dir) throws IOException;
/**
* Create an index structure for indexing XPath queries.
*/
ReverseIndex getReverseIndex (File dir) throws IOException;
/**
* Index of documents.
*/
interface Index {
/**
* Add an xml document to the index under the given id.
* This is the id that will be returned by <em>Index.query</em>.
*
* @exception IOException if there was a problem reading the
* document from the stream.
* @exception BadDocumentException if the XML document could
* not be parsed.
* @exception IndexException if the document could not be indexed
* or if some internal error occurred, such as a failure to
* acquire a lock, etc.
*/
void add (String id, InputStream xmlDoc)
throws IOException, BadDocumentException, IndexException;
/**
* Remove the given xml document from the index.
* @exception IOException if there was a problem reading the
* document from the stream.
* @exception BadDocumentException if the XML document could
* not be parsed.
* @exception IndexException if an internal error occurred, such
* as a failure to acquire a lock, etc.
*/
void remove (String id, InputStream xmlDoc)
throws IOException, BadDocumentException, IndexException;
/**
* Return an array of document ids matching the given XPath string.
*
* @exception BadQueryException if the query was not valid XPath.
* @exception IndexException if an internal error occurred, such
* as a failure to acquire a lock, etc.
*/
String[] query (String xpathQuery)
throws BadQueryException, IndexException;
}
/**
* Index of queries.
*/
interface ReverseIndex {
/**
* Add an XPath query to the index. If this query later
* matches during querying of the index with a document,
* this id string will be returned.
*
* @exception BadQueryException if the xpath is invalid.
* @exception IndexException if indexing failed.
*/
void add (String id, String xpath)
throws BadQueryException, IndexException;
/**
* Remove the XPath query from the index.
*
* @exception BadQueryException if the xpath is invalid.
* @exception IndexException if indexing failed.
*/
void remove (String id, String xpath)
throws BadQueryException, IndexException;
/**
* Return an array of xpath ids that match the given xml document.
*
* @exception IOException if the document could not be read from
* the stream
* @exception BadDocumentException if the document could not be
* parsed.
* @exception IndexException if the document could not be indexed
* or some internal index error occurred.
*/
String[] query (InputStream xmlDoc)
throws IOException, BadDocumentException, IndexException;
}
/**
* Exceptions of this type are thrown when a document cannot
* be parsed.
*/
public class BadDocumentException extends Exception {
Throwable t;
public BadDocumentException (String msg, Throwable t) {
super (msg);
this.t = t;
}
/**
* Get the real cause of this exception.
*/
public Throwable getNestedThrowable () {
return t;
}
}
/**
* Exceptions of this type are thrown when a query is
* incorrectly formatted.
*/
public class BadQueryException extends Exception {
Throwable t;
public BadQueryException (String msg, Throwable t) {
super (msg);
this.t = t;
}
public Throwable getNestedThrowable () {
return t;
}
}
/**
* Exceptions of this type are thrown when a document
* or a query cannot be inserted into an index due
* to some internal index problem.
*/
public class IndexException extends Exception {
Throwable t;
public IndexException (String msg, Throwable t) {
super (msg);
this.t = t;
}
public Throwable getNestedThrowable () {
return t;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -