Package: AbstractSesameIterator
AbstractSesameIterator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AbstractSesameIterator(ListDescriptor, Connector, ValueFactory) |
|
|
|
|
|
||||||||||||||||||||
checkNodeIsResource(Statement) |
|
|
|
|
|
||||||||||||||||||||
checkSuccessorMax(Collection, URI) |
|
|
|
|
|
||||||||||||||||||||
createAxiom(Resource, Assertion, Resource) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.sesame;
16:
17: import java.util.Collection;
18: import java.util.HashSet;
19:
20: import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils;
21: import org.openrdf.model.Resource;
22: import org.openrdf.model.Statement;
23: import org.openrdf.model.URI;
24: import org.openrdf.model.ValueFactory;
25:
26: import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException;
27: import cz.cvut.kbss.ontodriver.sesame.connector.Connector;
28: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
29: import cz.cvut.kbss.ontodriver.model.Assertion;
30: import cz.cvut.kbss.ontodriver.model.Axiom;
31: import cz.cvut.kbss.ontodriver.model.AxiomImpl;
32: import cz.cvut.kbss.ontodriver.model.NamedResource;
33: import cz.cvut.kbss.ontodriver.model.Value;
34:
35: abstract class AbstractSesameIterator implements SesameIterator {
36:
37: protected final Resource listOwner;
38: protected final URI hasListProperty;
39: protected final URI hasNextProperty;
40: protected final URI context;
41: protected final boolean includeInferred;
42:
43: protected final Connector connector;
44: protected final ValueFactory vf;
45:
46: public AbstractSesameIterator(ListDescriptor listDescriptor, Connector connector,
47: ValueFactory vf) {
48: this.listOwner = SesameUtils.toSesameUri(listDescriptor.getListOwner().getIdentifier(), vf);
49: this.hasListProperty = SesameUtils.toSesameUri(listDescriptor.getListProperty()
50: .getIdentifier(), vf);
51: this.hasNextProperty = SesameUtils.toSesameUri(
52: listDescriptor.getNextNode().getIdentifier(), vf);
53: this.context = SesameUtils.toSesameUri(listDescriptor.getContext(), vf);
54: this.includeInferred = listDescriptor.getListProperty().isInferred();
55: this.connector = connector;
56: this.vf = vf;
57: }
58:
59: protected void checkSuccessorMax(Collection<Statement> stmts, URI property) {
60: // We don't mind the same statement multiple times, it could have been added during transaction
61:• if (new HashSet<>(stmts).size() > 1) {
62: throw new IntegrityConstraintViolatedException(
63: "Invalid number of values found for assertion " + property
64: + ". Expected 1, got " + stmts.size());
65: }
66: }
67:
68: protected void checkNodeIsResource(Statement stmt) {
69:• if (!(stmt.getObject() instanceof Resource)) {
70: throw new IntegrityConstraintViolatedException(
71: "Invalid property value. Expected object property value, got literal.");
72: }
73: }
74:
75: protected Axiom<NamedResource> createAxiom(Resource subject, Assertion assertion, Resource value) {
76: final NamedResource subjectRes = NamedResource.create(subject.stringValue());
77: return new AxiomImpl<>(subjectRes, assertion, new Value<>(NamedResource.create(value.stringValue())));
78: }
79: }