01: /*
02: * LICENSE INFORMATION
03: * Copyright 2005-2007 by FZI (http://www.fzi.de).
04: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
05: * <OWNER> = Max Völkel
06: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
07: * <YEAR> = 2007
08: *
09: * Project information at http://semweb4j.org/rdf2go
10: */
11: package org.ontoware.rdf2go.model.impl;
12:
13: import java.util.Iterator;
14:
15: import org.ontoware.rdf2go.exception.ModelRuntimeException;
16: import org.ontoware.rdf2go.model.ModelWriter;
17: import org.ontoware.rdf2go.model.Statement;
18: import org.ontoware.rdf2go.model.node.Node;
19: import org.ontoware.rdf2go.model.node.Resource;
20: import org.ontoware.rdf2go.model.node.URI;
21: import org.ontoware.rdf2go.model.node.impl.DatatypeLiteralImpl;
22: import org.ontoware.rdf2go.model.node.impl.LanguageTagLiteralImpl;
23: import org.ontoware.rdf2go.model.node.impl.PlainLiteralImpl;
24: import org.ontoware.rdf2go.model.node.impl.URIImpl;
25:
26: /**
27: * All these methods create some RDF2Go objects before calling the base case.
28: * For high-performance reasons, adapters should override all methods here.
29: *
30: * @author voelkel
31: */
32: public abstract class AbstractModelWriter implements ModelWriter {
33:
34: public void addAll(Iterator<? extends Statement> other)
35: throws ModelRuntimeException {
36: while (other.hasNext()) {
37: addStatement(other.next());
38: }
39: }
40:
41: public void addStatement(Resource subject, URI predicate,
42: String literal) throws ModelRuntimeException {
43: addStatement(subject, predicate, new PlainLiteralImpl(literal));
44: }
45:
46: public void addStatement(Resource subject, URI predicate,
47: String literal, String languageTag)
48: throws ModelRuntimeException {
49: addStatement(subject, predicate, new LanguageTagLiteralImpl(
50: literal, languageTag));
51: }
52:
53: /*
54: * (wth) for information on typed literals see this very good how to
55: * http://jena.sourceforge.net/how-to/typedLiterals.html
56: */
57: public void addStatement(Resource subject, URI predicate,
58: String literal, URI datatypeURI)
59: throws ModelRuntimeException {
60: addStatement(subject, predicate, new DatatypeLiteralImpl(
61: literal, datatypeURI));
62: }
63:
64: public void addStatement(String subjectURIString, URI predicate,
65: String literal) throws ModelRuntimeException {
66: addStatement(new URIImpl(subjectURIString), predicate,
67: new PlainLiteralImpl(literal));
68: }
69:
70: public void addStatement(String subjectURIString, URI predicate,
71: String literal, String languageTag)
72: throws ModelRuntimeException {
73: addStatement(new URIImpl(subjectURIString), predicate,
74: new LanguageTagLiteralImpl(literal, languageTag));
75: }
76:
77: public void addStatement(String subjectURIString, URI predicate,
78: String literal, URI datatypeURI)
79: throws ModelRuntimeException {
80: addStatement(new URIImpl(subjectURIString), predicate,
81: new DatatypeLiteralImpl(literal, datatypeURI));
82: }
83:
84: public void addStatement(Statement statement)
85: throws ModelRuntimeException {
86: addStatement(statement.getSubject(), statement.getPredicate(),
87: statement.getObject());
88: }
89:
90: // /////////////////////////
91:
92: public abstract void addStatement(Resource subject, URI predicate,
93: Node object) throws ModelRuntimeException;
94: }
|