📄 modelcom.java
字号:
/*
(c) Copyright 2003, 2004, 2005, 2006, 2007 Hewlett-Packard Development Company, LP
[See end of file]
$Id: ModelCom.java,v 1.117 2007/01/02 11:48:30 andy_seaborne Exp $
*/
package com.hp.hpl.jena.rdf.model.impl;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.shared.*;
import com.hp.hpl.jena.shared.impl.*;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.graph.impl.*;
import com.hp.hpl.jena.graph.query.*;
import com.hp.hpl.jena.util.CollectionFactory;
import com.hp.hpl.jena.util.iterator.*;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.datatypes.*;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
import com.hp.hpl.jena.enhanced.*;
import java.io.*;
import java.net.URL;
import java.util.*;
/** Common methods for model implementations.
*
* <P>This class implements common methods, mainly convenience methods, for
* model implementations. It is intended use is as a base class from which
* model implemenations can be derived.</P>
*
* @author bwm
* hacked by Jeremy, tweaked by Chris (May 2002 - October 2002)
*/
public class ModelCom
extends EnhGraph
implements Model, PrefixMapping, ModelLock
{
private static final RDFReaderF readerFactory = new RDFReaderFImpl();
private static final RDFWriterF writerFactory = new RDFWriterFImpl();
private ModelLock modelLock = null ;
/**
make a model based on the specified graph
*/
public ModelCom( Graph base )
{ this( base, BuiltinPersonalities.model ); }
public ModelCom( Graph base, Personality personality )
{ super( base, personality );
withDefaultMappings( defaultPrefixMapping ); }
private static PrefixMapping defaultPrefixMapping = PrefixMapping.Factory.create();
public static PrefixMapping getDefaultModelPrefixes()
{ return defaultPrefixMapping; }
public static PrefixMapping setDefaultModelPrefixes( PrefixMapping pm )
{ PrefixMapping result = defaultPrefixMapping;
defaultPrefixMapping = pm;
return result; }
public QueryHandler queryHandler()
{ return getGraph().queryHandler(); }
public Graph getGraph()
{ return graph; }
protected static Model createWorkModel()
{ return ModelFactory.createDefaultModel(); }
public RDFNode asRDFNode( Node n )
{
return n.isLiteral()
? (RDFNode) this.getNodeAs( n, Literal.class )
: (RDFNode) this.getNodeAs( n, Resource.class );
}
/**
the ModelReifier does everything to do with reification.
*/
protected ModelReifier modelReifier = new ModelReifier( this );
public Resource getResource(String uri, ResourceF f) {
try {
return f.createResource(getResource(uri));
} catch (Exception e) {
throw new JenaException(e);
}
}
public Model add(Resource s, Property p, boolean o) {
return add(s, p, String.valueOf( o ) );
}
public Model add(Resource s, Property p, long o) {
return add(s, p, String.valueOf( o ) );
}
public Model add(Resource s, Property p, char o) {
return add(s, p, String.valueOf( o ) );
}
public Model add(Resource s, Property p, float o) {
return add(s, p, String.valueOf( o ) );
}
public Model add(Resource s, Property p, double o) {
return add(s, p, String.valueOf( o ) );
}
public Model add(Resource s, Property p, String o) {
return add( s, p, o, "", false );
}
public Model add(Resource s, Property p, String o, boolean wellFormed)
{
add( s, p, literal( o, "", wellFormed ) );
return this;
}
public Model add( Resource s, Property p, String o, String lang,
boolean wellFormed) {
add( s, p, literal( o, lang, wellFormed ) );
return this;
}
public Model add(Resource s, Property p, String lex, RDFDatatype datatype)
{
add( s, p, literal( lex, datatype)) ;
return this;
}
private Literal literal( String s, String lang, boolean wellFormed )
{ return new LiteralImpl( Node.createLiteral( s, lang, wellFormed), this ); }
private Literal literal( String lex, RDFDatatype datatype)
{ return new LiteralImpl( Node.createLiteral( lex, "", datatype), this ); }
public Model add( Resource s, Property p, String o, String l )
{ return add( s, p, o, l, false ); }
/**
ensure that an object is an RDFNode. If it isn't, fabricate a literal
from its string representation. NOTE: probably proper data-typing
makes this suspect - Chris introduced it to abstract from some existing code.
*/
private RDFNode ensureRDFNode( Object o )
{
return o instanceof RDFNode
? (RDFNode) o
: literal( o.toString(), null, false )
;
}
public Model add(Resource s, Property p, Object o) {
return add( s, p, ensureRDFNode( o ) );
}
public Model add( StmtIterator iter ) {
try { getBulkUpdateHandler().add( asTriples( iter ) ); }
finally { iter.close(); }
return this;
}
public Model add( Model m )
{ return add( m, false ); }
public Model add( Model m, boolean suppressReifications ) {
getBulkUpdateHandler().add( m.getGraph(), !suppressReifications );
return this;
}
public RDFReader getReader() {
return readerFactory.getReader();
}
public RDFReader getReader(String lang) {
return readerFactory.getReader(lang);
}
public String setReaderClassName(String lang, String className) {
return readerFactory.setReaderClassName(lang, className);
}
public Model read(String url) {
readerFactory .getReader() .read(this, url);
return this;
}
public Model read(Reader reader, String base) {
readerFactory .getReader() .read(this, reader, base);
return this;
}
public Model read(InputStream reader, String base) {
readerFactory .getReader() .read(this, reader, base);
return this;
}
public Model read(String url, String lang) {
readerFactory. getReader(lang) .read(this, url);
return this;
}
public Model read( String url, String base, String lang )
{
try
{
InputStream is = new URL( url ) .openStream();
try { read( is, base, lang ); }
finally { is.close(); }
}
catch (IOException e) { throw new WrappedIOException( e ); }
return this;
}
public Model read(Reader reader, String base, String lang)
{
readerFactory .getReader(lang) .read(this, reader, base);
return this;
}
public Model read(InputStream reader, String base, String lang)
{
readerFactory .getReader(lang) .read(this, reader, base);
return this;
}
/**
Get the model's writer after priming it with the model's namespace
prefixes.
*/
public RDFWriter getWriter() {
return writerFactory.getWriter();
}
/**
Get the model's writer after priming it with the model's namespace
prefixes.
*/
public RDFWriter getWriter(String lang) {
return writerFactory.getWriter(lang);
}
public String setWriterClassName(String lang, String className) {
return writerFactory.setWriterClassName(lang, className);
}
public Model write(Writer writer)
{
getWriter() .write(this, writer, "");
return this;
}
public Model write(Writer writer, String lang)
{
getWriter(lang) .write(this, writer, "");
return this;
}
public Model write(Writer writer, String lang, String base)
{
getWriter(lang) .write(this, writer, base);
return this;
}
public Model write( OutputStream writer )
{
getWriter() .write(this, writer, "");
return this;
}
public Model write(OutputStream writer, String lang)
{
getWriter(lang) .write(this, writer, "");
return this;
}
public Model write(OutputStream writer, String lang, String base)
{
getWriter(lang) .write(this, writer, base);
return this;
}
public Model remove(Statement s) {
graph.delete(s.asTriple());
return this;
}
public Model remove( Resource s, Property p, RDFNode o ) {
graph.delete( Triple.create( s.asNode(), p.asNode(), o.asNode() ) );
return this;
}
public Model remove( StmtIterator iter )
{
getBulkUpdateHandler().delete( asTriples( iter ) );
return this;
}
public Model remove( Model m )
{ return remove( m, false ); }
public Model remove( Model m, boolean suppressReifications )
{
getBulkUpdateHandler().delete( m.getGraph(), !suppressReifications );
return this;
}
public Model removeAll()
{
getGraph().getBulkUpdateHandler().removeAll();
return this;
}
public Model removeAll( Resource s, Property p, RDFNode o )
{
getGraph().getBulkUpdateHandler().remove( asNode( s ), asNode( p ), asNode( o ) );
return this;
}
public boolean contains( Resource s, Property p, boolean o )
{ return contains(s, p, String.valueOf( o ) ); }
public boolean contains( Resource s, Property p, long o )
{ return contains(s, p, String.valueOf( o ) ); }
public boolean contains( Resource s, Property p, char o )
{ return contains(s, p, String.valueOf( o ) ); }
public boolean contains( Resource s, Property p, float o )
{ return contains(s, p, String.valueOf( o ) ); }
public boolean contains( Resource s, Property p, double o )
{ return contains(s, p, String.valueOf( o ) ); }
public boolean contains( Resource s, Property p, String o )
{ return contains( s, p, o, "" ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -