📄 modelcom.java
字号:
/*
* (c) Copyright Hewlett-Packard Company 2001
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Model.java
*
* Created on 11 March 2001, 16:07
*/
package com.hp.hpl.mesa.rdf.jena.common;
import com.hp.hpl.mesa.rdf.jena.common.*;
import com.hp.hpl.mesa.rdf.jena.model.*;
import com.hp.hpl.mesa.rdf.jena.vocabulary.RDF;
import com.hp.hpl.jena.rdf.arp.Location;
import java.io.FileReader;
import java.io.Writer;
import java.io.Reader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Vector;
/** 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
* @version Release='$Name: $' Revision='$Revision: 1.10 $' Date='$Date: 2001/12/06 11:50:21 $'
*/
public abstract class ModelCom extends Object implements Model, ModelI {
protected Store store = null;
protected RDFReaderF readerFactory = new RDFReaderFImpl();
protected RDFWriterF writerFactory = new RDFWriterFImpl();
// next free error code = 3
public ModelCom() {
}
public Resource getResource(String uri, ResourceF f) throws RDFException {
try {
return f.createResource(getResource(uri));
} catch (Exception e) {
throw new RDFException(e);
}
}
public Model add(Resource s,Property p,RDFNode o) throws RDFException {
add(createStatement(s, p, o));
return this;
}
public Model add(Resource s,Property p,RDFNode o, Location l) throws RDFException {
Statement st = createStatement(s, p, o);
st.setLocation(l);
add(st);
return this;
}
public Model add(Resource s, Property p, boolean o) throws RDFException {
add(s, p, new LiteralImpl(o));
return this;
}
public Model add(Resource s, Property p, long o) throws RDFException {
add(s, p, new LiteralImpl(o));
return this;
}
public Model add(Resource s, Property p, char o) throws RDFException {
add(s, p, new LiteralImpl(o));
return this;
}
public Model add(Resource s, Property p, float o) throws RDFException {
add(s, p, new LiteralImpl(o));
return this;
}
public Model add(Resource s, Property p, double o) throws RDFException {
add(s, p, new LiteralImpl(o));
return this;
}
public Model add(Resource s, Property p, String o) throws RDFException {
add(s, p, new LiteralImpl(o));
return this;
}
public Model add(Resource s, Property p, String o, boolean wellFormed)
throws RDFException {
add(s, p, new LiteralImpl(o, wellFormed));
return this;
}
public Model add(Resource s, Property p, String o, String lang,
boolean wellFormed) throws RDFException {
add(s, p, new LiteralImpl(o, lang, wellFormed));
return this;
}
public Model add(Resource s, Property p, String o, String l)
throws RDFException {
add(s, p, new LiteralImpl(o,l));
return this;
}
public Model add(Resource s, Property p, Object o) throws RDFException {
if (o instanceof RDFNode) {
add(s, p, (RDFNode) o);
} else {
add(s, p, new LiteralImpl(o));
}
return this;
}
public Model add(StmtIterator iter) throws RDFException {
try {
while (iter.hasNext()) {
add(iter.next());
}
return this;
} finally {
iter.close();
}
}
public Model add(Model m) throws RDFException {
return add(m.listStatements());
}
public RDFReader getReader() throws RDFException {
return readerFactory.getReader();
}
public RDFReader getReader(String lang) throws RDFException {
return readerFactory.getReader(lang);
}
public String setReaderClassName(String lang, String className) {
return readerFactory.setReaderClassName(lang, className);
}
public Model read(String url) throws RDFException {
readerFactory.getReader()
.read(this, url);
return this;
}
public Model read(Reader reader, String base) throws RDFException {
readerFactory.getReader()
.read(this, reader, base);
return this;
}
public Model read(String url, String lang) throws RDFException {
readerFactory.getReader(lang)
.read(this, url);
return this;
}
public Model read(Reader reader, String base, String lang)
throws RDFException {
readerFactory.getReader(lang)
.read(this, reader, base);
return this;
}
public RDFWriter getWriter() throws RDFException {
return writerFactory.getWriter();
}
public RDFWriter getWriter(String lang) throws RDFException {
return writerFactory.getWriter(lang);
}
public String setWriterClassName(String lang, String className) {
return writerFactory.setWriterClassName(lang, className);
}
public Model write(Writer writer) throws RDFException {
try {
writerFactory.getWriter()
.write(this, writer, "");
return this;
} catch (Exception e) {
throw new RDFException(e);
}
}
public Model write(Writer writer, String lang) throws RDFException {
try {
writerFactory.getWriter(lang)
.write(this, writer, "");
return this;
} catch (Exception e) {
throw new RDFException(e);
}
}
public Model write(Writer writer, String lang, String base)
throws RDFException {
try {
writerFactory.getWriter(lang)
.write(this, writer, base);
return this;
} catch (Exception e) {
throw new RDFException(e);
}
}
public Model remove(StmtIterator iter) throws RDFException {
while (iter.hasNext()) {
remove((Statement)iter.next());
}
return this;
}
public Model remove(Model m) throws RDFException {
StmtIterator iter = m.listStatements();
try {
remove(iter);
} finally {
iter.close();
}
return this;
}
public boolean contains(Resource s, Property p, boolean o)
throws RDFException {
return contains(s, p, new LiteralImpl(o));
}
public boolean contains(Resource s, Property p, long o)
throws RDFException {
return contains(s, p, new LiteralImpl(o));
}
public boolean contains(Resource s, Property p, char o)
throws RDFException {
return contains(s, p, new LiteralImpl(o));
}
public boolean contains(Resource s, Property p, float o)
throws RDFException {
return contains(s, p, new LiteralImpl(o));
}
public boolean contains(Resource s, Property p, double o)
throws RDFException {
return contains(s, p, new LiteralImpl(o));
}
public boolean contains(Resource s, Property p, String o)
throws RDFException {
return contains(s, p, new LiteralImpl(o));
}
public boolean contains(Resource s, Property p, String o, String l)
throws RDFException {
return contains(s, p, new LiteralImpl(o,l));
}
public boolean contains(Resource s, Property p, Object o)
throws RDFException {
if (o instanceof RDFNode) {
return contains(s, p, (RDFNode) o);
} else {
return contains(s, p, new LiteralImpl(o));
}
}
public boolean containsAny(StmtIterator iter) throws RDFException {
while (iter.hasNext()) {
if (contains(iter.next())) return true;
}
return false;
}
public boolean containsAll(StmtIterator iter) throws RDFException {
while (iter.hasNext()) {
if (!contains(iter.next())) return false;
}
return true;
}
public boolean containsAny(Model model) throws RDFException {
StmtIterator iter = model.listStatements();
try {
return containsAny(iter);
} finally {
iter.close();
}
}
public boolean containsAll(Model model) throws RDFException {
StmtIterator iter = model.listStatements();
try {
return containsAll(iter);
} finally {
iter.close();
}
}
public ResIterator listSubjectsWithProperty(Property p, boolean o)
throws RDFException {
return listSubjectsWithProperty(p, new LiteralImpl(o));
}
public ResIterator listSubjectsWithProperty(Property p, long o)
throws RDFException {
return listSubjectsWithProperty(p, new LiteralImpl(o));
}
public ResIterator listSubjectsWithProperty(Property p, char o)
throws RDFException {
return listSubjectsWithProperty(p, new LiteralImpl(o));
}
public ResIterator listSubjectsWithProperty(Property p, float o)
throws RDFException {
return listSubjectsWithProperty(p, new LiteralImpl(o));
}
public ResIterator listSubjectsWithProperty(Property p, double o)
throws RDFException {
return listSubjectsWithProperty(p, new LiteralImpl(o));
}
public ResIterator listSubjectsWithProperty(Property p, String o)
throws RDFException {
return listSubjectsWithProperty(p, new LiteralImpl(o));
}
public ResIterator listSubjectsWithProperty(Property p, String o, String l)
throws RDFException {
return listSubjectsWithProperty(p, new LiteralImpl(o,l));
}
public ResIterator listSubjectsWithProperty(Property p, Object o)
throws RDFException {
if (o instanceof RDFNode) {
return listSubjectsWithProperty(p, (RDFNode) o);
} else {
return listSubjectsWithProperty(p, new LiteralImpl(o));
}
}
public Resource createResource(Resource type) throws RDFException {
return createResource().addProperty(RDF.type, type);
}
public Resource createResource(String uri,Resource type)
throws RDFException {
return getResource(uri)
.addProperty(RDF.type, type);
}
public Resource createResource(ResourceF f) throws RDFException {
return createResource(null, f);
}
public Resource createResource(String uri, ResourceF f) throws RDFException {
try {
return f.createResource(createResource(uri));
} catch (Exception e) {
throw new RDFException(RDFException.NESTEDEXCEPTION, e);
}
}
public Literal createLiteral(boolean v) throws RDFException {
return createLiteral(String.valueOf(v), "");
}
public Literal createLiteral(long v) throws RDFException {
return createLiteral(String.valueOf(v), "");
}
public Literal createLiteral(char v) throws RDFException {
return createLiteral(String.valueOf(v), "");
}
public Literal createLiteral(float v) throws RDFException {
return createLiteral(String.valueOf(v), "");
}
public Literal createLiteral(double v) throws RDFException {
return createLiteral(String.valueOf(v), "");
}
public Literal createLiteral(String v) throws RDFException {
return createLiteral(v, "");
}
public Literal createLiteral(String v, String l) throws RDFException {
return new LiteralImpl(v, l);
}
public Literal createLiteral(String v, String l, boolean wellFormed) {
return new LiteralImpl(v, l, wellFormed);
}
public Literal createLiteral(Object v) throws RDFException {
return createLiteral(v.toString(), "");
}
public Statement createStatement(Resource r, Property p, boolean o)
throws RDFException {
return createStatement(r, p, createLiteral(o));
}
public Statement createStatement(Resource r, Property p, long o)
throws RDFException {
return createStatement(r, p, createLiteral(o));
}
public Statement createStatement(Resource r, Property p, char o)
throws RDFException {
return createStatement(r, p, createLiteral(o));
}
public Statement createStatement(Resource r, Property p, float o)
throws RDFException {
return createStatement(r, p, createLiteral(o));
}
public Statement createStatement(Resource r, Property p, double o)
throws RDFException {
return createStatement(r, p, createLiteral(o));
}
public Statement createStatement(Resource r, Property p, String o)
throws RDFException {
return createStatement(r, p, createLiteral(o));
}
public Statement createStatement(Resource r, Property p, Object o)
throws RDFException {
if (o instanceof RDFNode) {
return createStatement(r, p, (RDFNode) o);
} else {
return createStatement(r, p, createLiteral(o));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -