01: package it.unimi.dsi.mg4j.tool;
02:
03: /*
04: * MG4J: Managing Gigabytes for Java
05: *
06: * Copyright (C) 2006-2007 Paolo Boldi and Sebastiano Vigna
07: *
08: * This library is free software; you can redistribute it and/or modify it
09: * under the terms of the GNU Lesser General Public License as published by the Free
10: * Software Foundation; either version 2.1 of the License, or (at your option)
11: * any later version.
12: *
13: * This library is distributed in the hope that it will be useful, but
14: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16: * for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License
19: * along with this program; if not, write to the Free Software
20: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21: *
22: */
23:
24: import it.unimi.dsi.mg4j.document.Document;
25: import it.unimi.dsi.mg4j.tool.Scan.VirtualDocumentFragment;
26:
27: import java.io.Serializable;
28:
29: /** A resolver for virtual documents.
30: *
31: * <p>Fields of {@linkplain it.unimi.dsi.mg4j.document.DocumentFactory.FieldType#VIRTUAL virtual type} return
32: * a list of {@linkplain VirtualDocumentFragment virtual document fragments}
33: * containing a document specification (e.g., its URI) and the virtual text associated to the document. Since there are
34: * many ways of defining the virtual document, {@link it.unimi.dsi.mg4j.tool.Scan} requires
35: * a virtual-document resolver for each virtual field: the resolver takes in the string defining a document,
36: * and returns a document number. See {@link it.unimi.dsi.mg4j.tool.URLMPHVirtualDocumentResolver} for a
37: * natural example.
38: *
39: */
40:
41: public interface VirtualDocumentResolver extends Serializable {
42: /** Sets the context document. All successive calls to {@link #resolve(CharSequence)} will
43: * assume the virtual-document specification was found in <code>document</code>.
44: *
45: * @param document the context document.
46: */
47: public void context(Document document);
48:
49: /** Resolves a virtual document specification.
50: *
51: * <p>Note that the resolution process is carried out in the context of the last document
52: * passed to {@link #context(Document)} (e.g., for relative URI resolution). If {@link #context(Document)}
53: * was never called, the behaviour is undefined.
54: *
55: * @param virtualDocumentSpec the virtual document specification.
56: * @return the document <code>virtualDocumentSpec</code> refers to, or -1 if the specification could not be resolved.
57: */
58: public int resolve(CharSequence virtualDocumentSpec);
59:
60: /** Returns the number of documents handled by this resolver, if it is known. A call
61: * to {@link #resolve(CharSequence)} will always return a number
62: * smaller than the one returned by this method.
63: *
64: * @return the number of documents handled by this resolver.
65: */
66:
67: public int numberOfDocuments();
68: }
|