001: package org.ontoware.rdf2go.model.impl;
002:
003: import java.io.IOException;
004: import java.io.InputStream;
005: import java.io.OutputStream;
006: import java.io.Reader;
007: import java.io.Writer;
008: import java.net.URL;
009: import java.util.Iterator;
010:
011: import org.ontoware.aifbcommons.collection.ClosableIterable;
012: import org.ontoware.aifbcommons.collection.ClosableIterator;
013: import org.ontoware.rdf2go.exception.LockException;
014: import org.ontoware.rdf2go.exception.ModelRuntimeException;
015: import org.ontoware.rdf2go.exception.QueryLanguageNotSupportedException;
016: import org.ontoware.rdf2go.model.Diff;
017: import org.ontoware.rdf2go.model.DiffReader;
018: import org.ontoware.rdf2go.model.Model;
019: import org.ontoware.rdf2go.model.QueryResultTable;
020: import org.ontoware.rdf2go.model.Statement;
021: import org.ontoware.rdf2go.model.Syntax;
022: import org.ontoware.rdf2go.model.TriplePattern;
023: import org.ontoware.rdf2go.model.node.BlankNode;
024: import org.ontoware.rdf2go.model.node.Node;
025: import org.ontoware.rdf2go.model.node.NodeOrVariable;
026: import org.ontoware.rdf2go.model.node.Resource;
027: import org.ontoware.rdf2go.model.node.ResourceOrVariable;
028: import org.ontoware.rdf2go.model.node.URI;
029: import org.ontoware.rdf2go.model.node.UriOrVariable;
030: import org.slf4j.Logger;
031: import org.slf4j.LoggerFactory;
032:
033: /**
034: * Delegates all calls to underlying model. This class is meant to be subclassed
035: * and have some methods overriden. This was inspired by Sesame's SAIL API.
036: *
037: * @author voelkel
038: */
039: public class DelegatingModel extends AbstractModel implements Model {
040:
041: private static final Logger log = LoggerFactory
042: .getLogger(DelegatingModel.class);
043:
044: private Model delegatedModel;
045:
046: /**
047: * Please set model!
048: */
049: protected DelegatingModel() {
050: // use the setModel method
051: }
052:
053: public DelegatingModel(Model model) {
054: this .delegatedModel = model;
055: }
056:
057: @Override
058: public void addAll(Iterator<? extends Statement> other)
059: throws ModelRuntimeException {
060: this .delegatedModel.addAll(other);
061: }
062:
063: @Override
064: public void addStatement(Resource subject, URI predicate,
065: Node object) throws ModelRuntimeException {
066: this .delegatedModel.addStatement(subject, predicate, object);
067: }
068:
069: @Override
070: public void addStatement(Resource subject, URI predicate,
071: String literal) throws ModelRuntimeException {
072: this .delegatedModel.addStatement(subject, predicate, literal);
073: }
074:
075: @Override
076: public void addStatement(Resource subject, URI predicate,
077: String literal, String languageTag)
078: throws ModelRuntimeException {
079: this .delegatedModel.addStatement(subject, predicate, literal,
080: languageTag);
081: }
082:
083: @Override
084: public void addStatement(Resource subject, URI predicate,
085: String literal, URI datatypeURI)
086: throws ModelRuntimeException {
087: this .delegatedModel.addStatement(subject, predicate, literal,
088: datatypeURI);
089: }
090:
091: @Override
092: public void addStatement(Statement statement)
093: throws ModelRuntimeException {
094: this .delegatedModel.addStatement(statement);
095: }
096:
097: @Override
098: public void addStatement(String subjectURIString, URI predicate,
099: String literal) throws ModelRuntimeException {
100: this .delegatedModel.addStatement(subjectURIString, predicate,
101: literal);
102: }
103:
104: @Override
105: public void addStatement(String subjectURIString, URI predicate,
106: String literal, String languageTag)
107: throws ModelRuntimeException {
108: this .delegatedModel.addStatement(subjectURIString, predicate,
109: literal, languageTag);
110: }
111:
112: @Override
113: public void addStatement(String subjectURIString, URI predicate,
114: String literal, URI datatypeURI)
115: throws ModelRuntimeException {
116: this .delegatedModel.addStatement(subjectURIString, predicate,
117: literal, datatypeURI);
118: }
119:
120: @Override
121: public void close() {
122: this .delegatedModel.close();
123: }
124:
125: @Override
126: public void commit() {
127: this .delegatedModel.commit();
128: }
129:
130: @Override
131: public boolean contains(ResourceOrVariable subject,
132: UriOrVariable predicate, NodeOrVariable object)
133: throws ModelRuntimeException {
134: return this .delegatedModel.contains(subject, predicate, object);
135: }
136:
137: public BlankNode createBlankNode() {
138: return this .delegatedModel.createBlankNode();
139: }
140:
141: public BlankNode createBlankNode(String internalID) {
142: return delegatedModel.createBlankNode(internalID);
143: }
144:
145: @Override
146: public URI createURI(String uriString) throws ModelRuntimeException {
147: return this .delegatedModel.createURI(uriString);
148: }
149:
150: public void dump() {
151: this .delegatedModel.dump();
152: }
153:
154: public ClosableIterator<Statement> findStatements(
155: ResourceOrVariable subject, UriOrVariable predicate,
156: NodeOrVariable object) throws ModelRuntimeException {
157: return this .delegatedModel.findStatements(subject, predicate,
158: object);
159: }
160:
161: @Override
162: public ClosableIterator<Statement> findStatements(
163: TriplePattern pattern) throws ModelRuntimeException {
164: return this .delegatedModel.findStatements(pattern);
165: }
166:
167: public URI getContextURI() {
168: return this .delegatedModel.getContextURI();
169: }
170:
171: public Model getDelegatedModel() {
172: return this .delegatedModel;
173: }
174:
175: @Override
176: public Diff getDiff(Iterator<? extends Statement> other)
177: throws ModelRuntimeException {
178: return this .delegatedModel.getDiff(other);
179: }
180:
181: @Override
182: public Object getProperty(URI propertyURI) {
183: return this .delegatedModel.getProperty(propertyURI);
184: }
185:
186: @Override
187: public Object getUnderlyingModelImplementation() {
188: return this .delegatedModel.getUnderlyingModelImplementation();
189: }
190:
191: public boolean isEmpty() {
192: return delegatedModel.isEmpty();
193: }
194:
195: public boolean isIsomorphicWith(Model other) {
196: return this .delegatedModel.isIsomorphicWith(other);
197: }
198:
199: public boolean isLocked() {
200: return this .delegatedModel.isLocked();
201: }
202:
203: @Override
204: public boolean isOpen() {
205: return this .delegatedModel.isOpen();
206: }
207:
208: public boolean isValidURI(String uriString) {
209: return this .delegatedModel.isValidURI(uriString);
210: }
211:
212: public ClosableIterator<Statement> iterator() {
213: return this .delegatedModel.iterator();
214: }
215:
216: public void lock() throws LockException {
217: this .delegatedModel.lock();
218: }
219:
220: @Override
221: public URI newRandomUniqueURI() {
222: return this .delegatedModel.newRandomUniqueURI();
223: }
224:
225: @Override
226: public void open() {
227: this .delegatedModel.open();
228: }
229:
230: @Override
231: public ClosableIterable<Statement> queryConstruct(String query,
232: String querylanguage)
233: throws QueryLanguageNotSupportedException,
234: ModelRuntimeException {
235: return this .delegatedModel.queryConstruct(query, querylanguage);
236: }
237:
238: @Override
239: public QueryResultTable querySelect(String query,
240: String querylanguage)
241: throws QueryLanguageNotSupportedException,
242: ModelRuntimeException {
243: return this .delegatedModel.querySelect(query, querylanguage);
244: }
245:
246: public void readFrom(InputStream in) throws IOException,
247: ModelRuntimeException {
248: this .delegatedModel.readFrom(in);
249: }
250:
251: @Override
252: public void readFrom(InputStream reader, Syntax syntax)
253: throws IOException, ModelRuntimeException {
254: this .delegatedModel.readFrom(reader, syntax);
255: }
256:
257: public void readFrom(Reader r) throws IOException,
258: ModelRuntimeException {
259: this .delegatedModel.readFrom(r);
260: }
261:
262: public void readFrom(Reader reader, Syntax syntax)
263: throws ModelRuntimeException, IOException {
264: this .delegatedModel.readFrom(reader, syntax);
265: }
266:
267: @Override
268: public void removeAll() throws ModelRuntimeException {
269: this .delegatedModel.removeAll();
270: }
271:
272: @Override
273: public void removeAll(Iterator<? extends Statement> other)
274: throws ModelRuntimeException {
275: this .delegatedModel.removeAll(other);
276: }
277:
278: @Override
279: public void removeStatement(Resource subject, URI predicate,
280: Node object) throws ModelRuntimeException {
281: this .delegatedModel.removeStatement(subject, predicate, object);
282: }
283:
284: @Override
285: public void removeStatement(Resource subject, URI predicate,
286: String literal) throws ModelRuntimeException {
287: this .delegatedModel
288: .removeStatement(subject, predicate, literal);
289: }
290:
291: @Override
292: public void removeStatement(Resource subject, URI predicate,
293: String literal, String languageTag)
294: throws ModelRuntimeException {
295: this .delegatedModel.removeStatement(subject, predicate,
296: literal, languageTag);
297: }
298:
299: @Override
300: public void removeStatement(Resource subject, URI predicate,
301: String literal, URI datatypeURI)
302: throws ModelRuntimeException {
303: this .delegatedModel.removeStatement(subject, predicate,
304: literal, datatypeURI);
305: }
306:
307: @Override
308: public void removeStatement(Statement statement)
309: throws ModelRuntimeException {
310: this .delegatedModel.removeStatement(statement);
311: }
312:
313: @Override
314: public void removeStatement(String subjectURIString, URI predicate,
315: String literal) throws ModelRuntimeException {
316: this .delegatedModel.removeStatement(subjectURIString,
317: predicate, literal);
318: }
319:
320: @Override
321: public void removeStatement(String subjectURIString, URI predicate,
322: String literal, String languageTag)
323: throws ModelRuntimeException {
324: this .delegatedModel.removeStatement(subjectURIString,
325: predicate, literal, languageTag);
326: }
327:
328: @Override
329: public void removeStatement(String subjectURIString, URI predicate,
330: String literal, URI datatypeURI)
331: throws ModelRuntimeException {
332: this .delegatedModel.removeStatement(subjectURIString,
333: predicate, literal, datatypeURI);
334: }
335:
336: @Override
337: public void removeStatements(ResourceOrVariable subject,
338: UriOrVariable predicate, NodeOrVariable object)
339: throws ModelRuntimeException {
340: this .delegatedModel
341: .removeStatements(subject, predicate, object);
342: }
343:
344: @Override
345: public void setAutocommit(boolean autocommit) {
346: this .delegatedModel.setAutocommit(autocommit);
347: }
348:
349: protected void setDelegatedModel(Model model) {
350: this .delegatedModel = model;
351: }
352:
353: @Override
354: public void setProperty(URI propertyURI, Object value) {
355: this .delegatedModel.setProperty(propertyURI, value);
356: }
357:
358: @Override
359: public long size() throws ModelRuntimeException {
360: return this .delegatedModel.size();
361: }
362:
363: public boolean sparqlAsk(String query) throws ModelRuntimeException {
364: boolean result = this .delegatedModel.sparqlAsk(query);
365: return result;
366: }
367:
368: public ClosableIterable<Statement> sparqlConstruct(String query)
369: throws ModelRuntimeException {
370: return this .delegatedModel.sparqlConstruct(query);
371: }
372:
373: public ClosableIterable<Statement> sparqlDescribe(String query)
374: throws ModelRuntimeException {
375: return this .delegatedModel.sparqlDescribe(query);
376: }
377:
378: public QueryResultTable sparqlSelect(String queryString)
379: throws ModelRuntimeException {
380: log.debug("SPARQL query: " + queryString);
381: return this .delegatedModel.sparqlSelect(queryString);
382: }
383:
384: public void unlock() {
385: this .delegatedModel.unlock();
386: }
387:
388: @Override
389: public void update(DiffReader diff) throws ModelRuntimeException {
390: this .delegatedModel.update(diff);
391: }
392:
393: public void writeTo(OutputStream out) throws IOException,
394: ModelRuntimeException {
395: this .delegatedModel.writeTo(out);
396: }
397:
398: @Override
399: public void writeTo(OutputStream out, Syntax syntax)
400: throws IOException, ModelRuntimeException {
401: this .delegatedModel.writeTo(out, syntax);
402: }
403:
404: public void writeTo(Writer w) throws IOException,
405: ModelRuntimeException {
406: this .delegatedModel.writeTo(w);
407: }
408:
409: public void writeTo(Writer writer, Syntax syntax)
410: throws ModelRuntimeException, IOException {
411: this .delegatedModel.writeTo(writer, syntax);
412: }
413:
414: public void readFrom(Reader in, Syntax syntax, URL baseURI)
415: throws IOException, ModelRuntimeException {
416: delegatedModel.readFrom(in, syntax, baseURI);
417: }
418:
419: public void readFrom(InputStream reader, Syntax syntax, URL baseURI)
420: throws IOException, ModelRuntimeException {
421: delegatedModel.readFrom(reader, syntax, baseURI);
422: }
423:
424: }
|