All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ontoware.rdf2go.model.impl.AbstractModelWriter Maven / Gradle / Ivy

Go to download

RDF2go is an implementation-independent Java API with the design goals: portability (hence the name), performance and ease of implementation. This project was started at FZI Forschungszentrum Informatik Karlsruhe, Germany - www.fzi.de

The newest version!
/**
 * LICENSE INFORMATION
 *
 * Copyright 2005-2008 by FZI (http://www.fzi.de).
 * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
 *  = Max Völkel
 *  = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
 *  = 2010
 *
 * Further project information at http://semanticweb.org/wiki/RDF2Go
 */

package org.ontoware.rdf2go.model.impl;

import java.util.Iterator;

import org.ontoware.rdf2go.exception.ModelRuntimeException;
import org.ontoware.rdf2go.model.ModelWriter;
import org.ontoware.rdf2go.model.Statement;
import org.ontoware.rdf2go.model.node.Node;
import org.ontoware.rdf2go.model.node.Resource;
import org.ontoware.rdf2go.model.node.URI;
import org.ontoware.rdf2go.model.node.impl.DatatypeLiteralImpl;
import org.ontoware.rdf2go.model.node.impl.LanguageTagLiteralImpl;
import org.ontoware.rdf2go.model.node.impl.PlainLiteralImpl;
import org.ontoware.rdf2go.model.node.impl.URIImpl;

/**
 * All these methods create some RDF2Go objects before calling the base case.
 * For high-performance reasons, adapters should override all methods here.
 * 
 * @author voelkel
 */
public abstract class AbstractModelWriter implements ModelWriter {

	@Override
    public void addAll(Iterator other) throws ModelRuntimeException {
		while (other.hasNext()) {
			addStatement(other.next());
		}
	}

	@Override
    public void addStatement(Resource subject, URI predicate, String literal)
			throws ModelRuntimeException {
		addStatement(subject, predicate, new PlainLiteralImpl(literal));
	}

	@Override
    public void addStatement(Resource subject, URI predicate, String literal,
			String languageTag) throws ModelRuntimeException {
		addStatement(subject, predicate, new LanguageTagLiteralImpl(literal,
				languageTag));
	}

	/*
	 * (wth) for information on typed literals see this very good how to
	 * http://jena.sourceforge.net/how-to/typedLiterals.html
	 */
	@Override
    public void addStatement(Resource subject, URI predicate, String literal,
			URI datatypeURI) throws ModelRuntimeException {
		addStatement(subject, predicate, new DatatypeLiteralImpl(literal,
				datatypeURI));
	}

	@Override
    public void addStatement(String subjectURIString, URI predicate,
			String literal) throws ModelRuntimeException {
		addStatement(new URIImpl(subjectURIString), predicate,
				new PlainLiteralImpl(literal));
	}

	@Override
    public void addStatement(String subjectURIString, URI predicate,
			String literal, String languageTag) throws ModelRuntimeException {
		addStatement(new URIImpl(subjectURIString), predicate,
				new LanguageTagLiteralImpl(literal, languageTag));
	}

	@Override
    public void addStatement(String subjectURIString, URI predicate,
			String literal, URI datatypeURI) throws ModelRuntimeException {
		addStatement(new URIImpl(subjectURIString), predicate,
				new DatatypeLiteralImpl(literal, datatypeURI));
	}

	@Override
    public void addStatement(Statement statement) throws ModelRuntimeException {
		addStatement(statement.getSubject(), statement.getPredicate(),
				statement.getObject());
	}

	// /////////////////////////

	@Override
    public abstract void addStatement(Resource subject, URI predicate,
			Node object) throws ModelRuntimeException;
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy