001: /*
002: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
003: *
004: * Licensed under the Aduna BSD-style license.
005: */
006: package org.openrdf.rio;
007:
008: import java.io.IOException;
009: import java.io.InputStream;
010: import java.io.Reader;
011:
012: import org.openrdf.model.ValueFactory;
013:
014: /**
015: * An interface for RDF parsers. All implementing classes should define a public
016: * zero-argument constructor to allow them to be created through reflection.
017: */
018: public interface RDFParser {
019:
020: /*-----------*
021: * Constants *
022: *-----------*/
023:
024: public enum DatatypeHandling {
025: /**
026: * Indicates that datatype semantics should be ignored.
027: */
028: IGNORE,
029:
030: /**
031: * Indicates that values of datatyped literals should be verified.
032: */
033: VERIFY,
034:
035: /**
036: * Indicates that values of datatyped literals should be normalized to
037: * their canonical representation.
038: */
039: NORMALIZE
040: }
041:
042: /*---------*
043: * Methods *
044: *---------*/
045:
046: /**
047: * Gets the RDF format that this parser can parse.
048: */
049: public RDFFormat getRDFFormat();
050:
051: /**
052: * Sets the ValueFactory that the parser will use to create Value objects for
053: * the parsed RDF data.
054: *
055: * @param valueFactory
056: * The value factory that the parser should use.
057: */
058: public void setValueFactory(ValueFactory valueFactory);
059:
060: /**
061: * Sets the RDFHandler that will handle the parsed RDF data.
062: */
063: public void setRDFHandler(RDFHandler handler);
064:
065: /**
066: * Sets the ParseErrorListener that will be notified of any errors that this
067: * parser finds during parsing.
068: */
069: public void setParseErrorListener(ParseErrorListener el);
070:
071: /**
072: * Sets the ParseLocationListener that will be notified of the parser's
073: * progress during the parse process.
074: */
075: public void setParseLocationListener(ParseLocationListener ll);
076:
077: /**
078: * Sets whether the parser should verify the data it parses (default value is
079: * <tt>true</tt>).
080: */
081: public void setVerifyData(boolean verifyData);
082:
083: /**
084: * Set whether the parser should preserve bnode identifiers specified in the
085: * source (default is <tt>false</tt>).
086: */
087: public void setPreserveBNodeIDs(boolean preserveBNodeIDs);
088:
089: /**
090: * Sets whether the parser should stop immediately if it finds an error in
091: * the data (default value is <tt>true</tt>).
092: */
093: public void setStopAtFirstError(boolean stopAtFirstError);
094:
095: /**
096: * Sets the datatype handling mode. There are three modes for handling
097: * datatyped literals: <em>ignore</em>, <em>verify</em>and
098: * <em>normalize</em>. If set to <em>ignore</em>, no special action
099: * will be taken to handle datatyped literals. If set to <em>verify</em>,
100: * any literals with known (XML Schema built-in) datatypes are checked to see
101: * if their values are valid. If set to <em>normalize</em>, the literal
102: * values are not only checked, but also normalized to their canonical
103: * representation. The default value is <em>verify</em>.
104: *
105: * @param datatypeHandling
106: * A datatype handling option.
107: */
108: public void setDatatypeHandling(DatatypeHandling datatypeHandling);
109:
110: /**
111: * Parses the data from the supplied InputStream, using the supplied baseURI
112: * to resolve any relative URI references.
113: *
114: * @param in
115: * The InputStream from which to read the data.
116: * @param baseURI
117: * The URI associated with the data in the InputStream.
118: * @throws IOException
119: * If an I/O error occurred while data was read from the InputStream.
120: * @throws RDFParseException
121: * If the parser has found an unrecoverable parse error.
122: * @throws RDFHandlerException
123: * If the configured statement handler has encountered an
124: * unrecoverable error.
125: */
126: public void parse(InputStream in, String baseURI)
127: throws IOException, RDFParseException, RDFHandlerException;
128:
129: /**
130: * Parses the data from the supplied Reader, using the supplied baseURI to
131: * resolve any relative URI references.
132: *
133: * @param reader
134: * The Reader from which to read the data.
135: * @param baseURI
136: * The URI associated with the data in the InputStream.
137: * @throws IOException
138: * If an I/O error occurred while data was read from the InputStream.
139: * @throws RDFParseException
140: * If the parser has found an unrecoverable parse error.
141: * @throws RDFHandlerException
142: * If the configured statement handler has encountered an
143: * unrecoverable error.
144: */
145: public void parse(Reader reader, String baseURI)
146: throws IOException, RDFParseException, RDFHandlerException;
147: }
|