001: /*
002: * LICENSE INFORMATION
003: * Copyright 2005-2007 by FZI (http://www.fzi.de).
004: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
005: * <OWNER> = Max Völkel
006: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
007: * <YEAR> = 2007
008: *
009: * Project information at http://semweb4j.org/rdf2go
010: */
011: package org.ontoware.rdf2go.model.impl;
012:
013: import java.util.Collection;
014: import java.util.Iterator;
015: import java.util.LinkedList;
016:
017: import org.ontoware.rdf2go.exception.ModelRuntimeException;
018: import org.ontoware.rdf2go.model.Diff;
019: import org.ontoware.rdf2go.model.DiffReader;
020: import org.ontoware.rdf2go.model.ModelAddRemove;
021: import org.ontoware.rdf2go.model.Statement;
022: import org.ontoware.rdf2go.model.node.Node;
023: import org.ontoware.rdf2go.model.node.Resource;
024: import org.ontoware.rdf2go.model.node.URI;
025: import org.ontoware.rdf2go.model.node.impl.DatatypeLiteralImpl;
026: import org.ontoware.rdf2go.model.node.impl.LanguageTagLiteralImpl;
027: import org.ontoware.rdf2go.model.node.impl.PlainLiteralImpl;
028: import org.ontoware.rdf2go.model.node.impl.URIImpl;
029: import org.slf4j.Logger;
030: import org.slf4j.LoggerFactory;
031:
032: /**
033: * For high-performance, adapters should override all of these methods, to avoid
034: * internal object creations, such as "new URIImpl(subjectURIString)" in
035: * "removeStatement(String subjectURIString, URI predicate, String literal)"
036: *
037: * @author mvo
038: *
039: */
040: public abstract class AbstractModelAddRemove extends
041: AbstractModelWriter implements ModelAddRemove {
042:
043: @SuppressWarnings("unused")
044: private static Logger log = LoggerFactory
045: .getLogger(AbstractModelAddRemove.class);
046:
047: public void removeStatement(String subjectURIString, URI predicate,
048: String literal) throws ModelRuntimeException {
049: removeStatement(new URIImpl(subjectURIString), predicate,
050: new PlainLiteralImpl(literal));
051: }
052:
053: public void removeStatement(String subjectURIString, URI predicate,
054: String literal, String languageTag)
055: throws ModelRuntimeException {
056: removeStatement(new URIImpl(subjectURIString), predicate,
057: new LanguageTagLiteralImpl(literal, languageTag));
058: }
059:
060: public void removeStatement(String subjectURIString, URI predicate,
061: String literal, URI datatypeURI)
062: throws ModelRuntimeException {
063: removeStatement(new URIImpl(subjectURIString), predicate,
064: new DatatypeLiteralImpl(literal, datatypeURI));
065: }
066:
067: public void removeStatement(Resource subject, URI predicate,
068: String literal) throws ModelRuntimeException {
069: removeStatement(subject, predicate, new PlainLiteralImpl(
070: literal));
071: }
072:
073: public void removeStatement(Resource subject, URI predicate,
074: String literal, String languageTag)
075: throws ModelRuntimeException {
076: removeStatement(subject, predicate, new LanguageTagLiteralImpl(
077: literal, languageTag));
078: }
079:
080: public void removeStatement(Resource subject, URI predicate,
081: String literal, URI datatypeURI)
082: throws ModelRuntimeException {
083: removeStatement(subject, predicate, new DatatypeLiteralImpl(
084: literal, datatypeURI));
085: }
086:
087: public void removeStatement(Statement statement)
088: throws ModelRuntimeException {
089: removeStatement(statement.getSubject(), statement
090: .getPredicate(), statement.getObject());
091: }
092:
093: // bulk operations
094:
095: public void removeAll(Iterator<? extends Statement> other)
096: throws ModelRuntimeException {
097: while (other.hasNext()) {
098: Statement stmt = other.next();
099: removeStatement(stmt);
100: }
101: }
102:
103: public void removeAll() throws ModelRuntimeException {
104: // fill temp
105: Collection<Statement> temp = new LinkedList<Statement>();
106: for (Statement statement : this ) {
107: temp.add(statement);
108: }
109:
110: // delete
111: for (Statement s : temp) {
112: removeStatement(s);
113: }
114: }
115:
116: public void update(DiffReader diff) throws ModelRuntimeException {
117: removeAll(diff.getRemoved().iterator());
118: addAll(diff.getAdded().iterator());
119: }
120:
121: @Deprecated
122: public void update(Diff diff) throws ModelRuntimeException {
123: removeAll(diff.getRemoved().iterator());
124: addAll(diff.getAdded().iterator());
125: }
126:
127: // core rdf2go model methods
128: // /////////////////////////
129:
130: /* this method is replicated here for informational purposes only */
131: @Override
132: public abstract void addStatement(Resource subject, URI predicate,
133: Node object) throws ModelRuntimeException;
134:
135: public abstract void removeStatement(Resource subject,
136: URI predicate, Node object) throws ModelRuntimeException;
137:
138: }
|