RDF4JFactory -> RDF4J
Project: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/commit/defb7d81 Tree: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/tree/defb7d81 Diff: http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/diff/defb7d81 Branch: refs/heads/COMMONSRDF-7 Commit: defb7d81ca349f1403ff261cff0acf08275e61b7 Parents: 790b605 Author: Stian Soiland-Reyes <st...@apache.org> Authored: Sun Oct 23 00:46:53 2016 +0100 Committer: Stian Soiland-Reyes <st...@apache.org> Committed: Sun Oct 23 00:46:53 2016 +0100 ---------------------------------------------------------------------- .../org/apache/commons/rdf/rdf4j/RDF4J.java | 601 +++++++++++++++++++ .../commons/rdf/rdf4j/RDF4JBlankNode.java | 2 +- .../apache/commons/rdf/rdf4j/RDF4JDataset.java | 4 +- .../apache/commons/rdf/rdf4j/RDF4JFactory.java | 601 ------------------- .../apache/commons/rdf/rdf4j/RDF4JGraph.java | 10 +- .../org/apache/commons/rdf/rdf4j/RDF4JIRI.java | 2 +- .../apache/commons/rdf/rdf4j/RDF4JLiteral.java | 2 +- .../org/apache/commons/rdf/rdf4j/RDF4JQuad.java | 2 +- .../apache/commons/rdf/rdf4j/RDF4JTriple.java | 2 +- .../rdf/rdf4j/experimental/RDF4JParser.java | 12 +- .../rdf4j/impl/AbstractRepositoryGraphLike.java | 6 +- .../rdf/rdf4j/impl/InternalRDF4JFactory.java | 14 +- .../commons/rdf/rdf4j/impl/ModelGraphImpl.java | 6 +- .../apache/commons/rdf/rdf4j/impl/QuadImpl.java | 10 +- .../commons/rdf/rdf4j/impl/TripleImpl.java | 8 +- .../apache/commons/rdf/rdf4j/package-info.java | 8 +- .../org.apache.commons.rdf.api.RDFFactory | 2 +- .../apache/commons/rdf/rdf4j/BlankNodeTest.java | 2 +- .../org/apache/commons/rdf/rdf4j/GraphTest.java | 2 +- .../commons/rdf/rdf4j/MemoryGraphTest.java | 6 +- .../rdf/rdf4j/MemoryRDFTermFactoryTest.java | 2 +- .../commons/rdf/rdf4j/NativeStoreGraphTest.java | 6 +- .../rdf/rdf4j/RDF4JServiceLoaderTest.java | 4 +- .../rdf/rdf4j/Rdf4JRDFTermFactoryTest.java | 2 +- 24 files changed, 658 insertions(+), 658 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java new file mode 100644 index 0000000..37dd7a2 --- /dev/null +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4J.java @@ -0,0 +1,601 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.rdf.rdf4j; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; + +// To avoid confusion, avoid importing +// classes that are in both +// commons.rdf and openrdf.model (e.g. IRI, Literal) +import org.apache.commons.rdf.api.BlankNode; +import org.apache.commons.rdf.api.BlankNodeOrIRI; +import org.apache.commons.rdf.api.Dataset; +import org.apache.commons.rdf.api.Graph; +import org.apache.commons.rdf.api.Quad; +import org.apache.commons.rdf.api.RDFTerm; +import org.apache.commons.rdf.api.RDF; +import org.apache.commons.rdf.api.Triple; +import org.apache.commons.rdf.api.TripleLike; +import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory; +import org.eclipse.rdf4j.model.BNode; +import org.eclipse.rdf4j.model.Model; +import org.eclipse.rdf4j.model.Resource; +import org.eclipse.rdf4j.model.Statement; +import org.eclipse.rdf4j.model.Value; +import org.eclipse.rdf4j.model.ValueFactory; +import org.eclipse.rdf4j.model.impl.LinkedHashModel; +import org.eclipse.rdf4j.model.impl.SimpleValueFactory; +import org.eclipse.rdf4j.repository.Repository; +import org.eclipse.rdf4j.repository.RepositoryConnection; +import org.eclipse.rdf4j.repository.sail.SailRepository; +import org.eclipse.rdf4j.sail.Sail; +import org.eclipse.rdf4j.sail.memory.MemoryStore; + +/** + * RDF4J implementation of RDF. + * <p> + * The {@link #RDF4J()} constructor uses a {@link SimpleValueFactory} + * to create corresponding RDF4J {@link Value} instances. Alternatively, this + * factory can be constructed with a different {@link ValueFactory} using + * {@link #RDF4J(ValueFactory)}. + * <p> + * {@link #asRDFTerm(Value)} can be used to convert any RDF4J {@link Value} to + * an RDFTerm. Note that adapted {@link BNode}s are considered equal if they are + * converted with the same {@link RDF4J} instance and have the same + * {@link BNode#getID()}. + * <p> + * {@link #createGraph()} creates a new Graph backed by {@link LinkedHashModel}. + * To use other models, see {@link #asRDFTermGraph(Model)}. + * <p> + * To adapt a RDF4J {@link Repository} as a {@link Dataset} or {@link Graph}, + * use {@link #asRDFTermDataset(Repository, Option...)} + * or + * {@link #asRDFTermGraph(Repository, Option...)}. + * <p> + * {@link #asTriple(Statement)} can be used to convert a RDF4J {@link Statement} + * to a Commons RDF {@link Triple}, and equivalent {@link #asQuad(Statement)} to + * convert a {@link Quad}. + * <p> + * To convert any {@link Triple} or {@link Quad} to to RDF4J {@link Statement}, + * use {@link #asStatement(TripleLike)}. This recognises previously converted + * {@link RDF4JTriple}s and {@link RDF4JQuad}s without re-converting their + * {@link RDF4JTripleLike#asStatement()}. + * <p> + * Likewise, {@link #asValue(RDFTerm)} can be used to convert any Commons RDF + * {@link RDFTerm} to a corresponding RDF4J {@link Value}. This recognises + * previously converted {@link RDF4JTerm}s without re-converting their + * {@link RDF4JTerm#asValue()}. + * <p> + * For the purpose of {@link BlankNode} equivalence, this factory contains an + * internal {@link UUID} salt that is used by adapter methods like + * {@link #asQuad(Statement)}, {@link #asTriple(Statement)}, + * {@link #asRDFTerm(Value)} as well as {@link #createBlankNode(String)}. As + * RDF4J {@link BNode} instances from multiple repositories or models may have + * the same {@link BNode#getID()}, converting them with the above methods might + * cause accidental {@link BlankNode} equivalence. Note that the {@link Graph} + * and {@link Dataset} adapter methods like + * {@link #asRDFTermDataset(Repository, Option...)} + * and + * {@link #asRDFTermGraph(Repository, Option...)} + * therefore uses a unique {@link RDF4J} internally. + * + */ +public final class RDF4J implements RDF { + + /** + * InternalRDF4JFactory is deliberately abstract + */ + private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory() { + }; + + public enum Option { + /** + * The Graph/Dataset should include any inferred statements + */ + includeInferred, + /** + * The graph/dataset should handle {@link Repository#initialize()} (if + * needed) and {@link Repository#shutDown()} on {@link Graph#close()} / + * {@link Dataset#close()}. + */ + handleInitAndShutdown + } + + private final UUID salt; + + private final ValueFactory valueFactory; + + /** + * Construct an {@link RDF4J}. + * + */ + public RDF4J() { + this(SimpleValueFactory.getInstance(), UUID.randomUUID()); + } + + /** + * Construct an {@link RDF4J}. + * <p> + * This constructor is intended for use with the value factory from + * {@link Repository#getValueFactory()} when using + * Repository-based graphs and datasets. + * + * @param valueFactory + * The RDF4J {@link ValueFactory} to use + */ + public RDF4J(ValueFactory valueFactory) { + this(valueFactory, UUID.randomUUID()); + } + + /** + * Construct an {@link RDF4J}. + * <p> + * This constructor may be used if reproducible + * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable. + * + * @param salt + * An {@link UUID} salt to be used by any created + * {@link BlankNode}s for the purpose of + * {@link BlankNode#uniqueReference()} + */ + public RDF4J(UUID salt) { + this(SimpleValueFactory.getInstance(), salt); + } + /** + * Construct an {@link RDF4J}. + * <p> + * This constructor may be used if reproducible + * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable. + * + * @param valueFactory + * The RDF4J {@link ValueFactory} to use + * @param salt + * An {@link UUID} salt to be used by any created + * {@link BlankNode}s for the purpose of + * {@link BlankNode#uniqueReference()} + */ + public RDF4J(ValueFactory valueFactory, UUID salt) { + this.valueFactory = valueFactory; + this.salt = salt; + } + + /** + * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}. + * <p> + * For the purpose of {@link BlankNode} equivalence, this method will use an + * internal salt UUID that is unique per instance of + * {@link RDF4J}. + * <p> + * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s multiple + * repositories or models, then their {@link BNode}s may have the same + * {@link BNode#getID()}, which with this method would become equivalent + * according to {@link BlankNode#equals(Object)} and + * {@link BlankNode#uniqueReference()}, unless a separate + * {@link RDF4J} instance is used per RDF4J repository/model. + * + * @param statement + * The statement to convert + * @return A {@link RDF4JQuad} that is equivalent to the statement + */ + public RDF4JQuad asQuad(final Statement statement) { + return rdf4j.createQuadImpl(statement, salt); + } + + /** + * + * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}. + * <p> + * The value will be of the same kind as the term, e.g. a + * {@link org.eclipse.rdf4j.model.BNode} is converted to a + * {@link org.apache.commons.rdf.api.BlankNode}, a + * {@link org.eclipse.rdf4j.model.IRI} is converted to a + * {@link org.apache.commons.rdf.api.IRI} and a + * {@link org.eclipse.rdf4j.model.Literal}. is converted to a + * {@link org.apache.commons.rdf.api.Literal} + * <p> + * For the purpose of {@link BlankNode} equivalence, this method will use an + * internal salt UUID that is unique per instance of + * {@link RDF4J}. + * <p> + * <strong>NOTE:</strong> If combining RDF4J values from multiple + * repositories or models, then their {@link BNode}s may have the same + * {@link BNode#getID()}, which with this method would become equivalent + * according to {@link BlankNode#equals(Object)} and + * {@link BlankNode#uniqueReference()}, unless a separate + * {@link RDF4J} instance is used per RDF4J repository/model. + * + * @param value + * The RDF4J {@link Value} to convert. + * @return A {@link RDFTerm} that corresponds to the RDF4J value + * @throws IllegalArgumentException + * if the value is not a BNode, Literal or IRI + */ + public RDF4JTerm asRDFTerm(Value value) { + return asRDFTerm(value, salt); + } + + /** + * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}. + * <p> + * The value will be of the same kind as the term, e.g. a + * {@link org.eclipse.rdf4j.model.BNode} is converted to a + * {@link org.apache.commons.rdf.api.BlankNode}, a + * {@link org.eclipse.rdf4j.model.IRI} is converted to a + * {@link org.apache.commons.rdf.api.IRI} and a + * {@link org.eclipse.rdf4j.model.Literal}. is converted to a + * {@link org.apache.commons.rdf.api.Literal} + * + * @param value + * The RDF4J {@link Value} to convert. + * @param salt + * A {@link UUID} salt to use for uniquely mapping any + * {@link BNode}s. The salt should typically be the same for + * multiple statements in the same {@link Repository} or + * {@link Model} to ensure {@link BlankNode#equals(Object)} and + * {@link BlankNode#uniqueReference()} works as intended. + * @return A {@link RDFTerm} that corresponds to the RDF4J value + * @throws IllegalArgumentException + * if the value is not a BNode, Literal or IRI + */ + public static RDF4JTerm asRDFTerm(final Value value, UUID salt) { + if (value instanceof BNode) { + return rdf4j.createBlankNodeImpl((BNode) value, salt); + } + if (value instanceof org.eclipse.rdf4j.model.Literal) { + return rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal) value); + } + if (value instanceof org.eclipse.rdf4j.model.IRI) { + return rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value); + } + throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass()); + } + + /** + * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}. + * <p> + * Changes to the dataset are reflected in the repository, and vice versa. + * <p> + * <strong>Note:</strong> Some operations on the {@link RDF4JDataset} + * requires the use of try-with-resources to close underlying + * {@link RepositoryConnection}s, including + * {@link RDF4JDataset#iterate()}, + * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}. + * + * @param repository + * RDF4J {@link Repository} to connect to. + * @param options + * Zero or more {@link Option} + * @return A {@link Dataset} backed by the RDF4J repository. + */ + public RDF4JDataset asRDFTermDataset(Repository repository, Option... options) { + EnumSet<Option> opts = optionSet(options); + return rdf4j.createRepositoryDatasetImpl(repository, + opts.contains(Option.handleInitAndShutdown), + opts.contains(Option.includeInferred)); + } + + /** + * Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}. + * <p> + * Changes to the graph are reflected in the model, and vice versa. + * + * @param model + * RDF4J {@link Model} to adapt. + * @return Adapted {@link Graph}. + */ + public RDF4JGraph asRDFTermGraph(Model model) { + return rdf4j.createModelGraphImpl(model, this); + } + + /** + * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}. + * <p> + * The graph will only include triples in the default graph (equivalent to + * context <code>new Resource[0]{null})</code> in RDF4J). + * <p> + * Changes to the graph are reflected in the repository, and vice versa. + * <p> + * <strong>Note:</strong> Some operations on the {@link RDF4JGraph} + * requires the use of try-with-resources to close underlying + * {@link RepositoryConnection}s, including + * {@link RDF4JGraph#iterate()} and + * {@link RDF4JGraph#stream()}. + * + * @param repository + * RDF4J {@link Repository} to connect to. + * @param options + * Zero or more {@link Option} + * @return A {@link Graph} backed by the RDF4J repository. + */ + public RDF4JGraph asRDFTermGraph(Repository repository, Option... options) { + EnumSet<Option> opts = optionSet(options); + return rdf4j.createRepositoryGraphImpl(repository, + opts.contains(Option.handleInitAndShutdown), + opts.contains(Option.includeInferred), + new Resource[]{null}); // default graph + } + + /** + * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}. + * <p> + * The graph will include triples in any contexts (e.g. the union graph). + * <p> + * Changes to the graph are reflected in the repository, and vice versa. + * + * @param repository + * RDF4J {@link Repository} to connect to. + * @param options + * Zero or more {@link Option} + * @return A union {@link Graph} backed by the RDF4J repository. + */ + public RDF4JGraph asRDFTermGraphUnion(Repository repository, Option... options) { + EnumSet<Option> opts = optionSet(options); + return rdf4j.createRepositoryGraphImpl(repository, + opts.contains(Option.handleInitAndShutdown), + opts.contains(Option.includeInferred), + new Resource[]{}); // union graph + + } + + /** + * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}. + * <p> + * The graph will include triples in the specified contexts. + * <p> + * Changes to the graph are reflected in the repository, and vice versa. + * Triples added/removed to the graph are reflected in all the specified + * contexts. + * <p> + * <strong>Note:</strong> Some operations on the {@link RDF4JGraph} + * requires the use of try-with-resources to close underlying + * {@link RepositoryConnection}s, including + * {@link RDF4JGraph#iterate()} and + * {@link RDF4JGraph#stream()}. + * + * @param repository + * RDF4J {@link Repository} to connect to. + * @param contexts + * A {@link Set} of {@link BlankNodeOrIRI} specifying the graph + * names to use as a context. The set may include the value + * <code>null</code> to indicate the default graph. The empty set + * indicates any context, e.g. the <em>union graph</em>. + * @param option + * Zero or more {@link Option}s + * @return A {@link Graph} backed by the RDF4J repository. + */ + public RDF4JGraph asRDFTermGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts, + Option... option) { + EnumSet<Option> opts = optionSet(option); + /** NOTE: asValue() deliberately CAN handle <code>null</code> */ + Resource[] resources = contexts.stream().map(g -> (Resource) asValue(g)).toArray(Resource[]::new); + return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository), + opts.contains(Option.handleInitAndShutdown), + opts.contains(Option.includeInferred), + resources); + } + + /** + * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J + * {@link Statement}. + * <p> + * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or a + * {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is + * returned as-is. Note that this means that a {@link RDF4JTriple} would + * preserve its {@link Statement#getContext()}, and that any + * {@link BlankNode}s would be deemed equivalent in RDF4J if they have the + * same {@link BNode#getID()}. + * + * @param tripleLike + * A {@link Triple} or {@link Quad} to adapt + * @return A corresponding {@link Statement} + */ + public Statement asStatement(TripleLike tripleLike) { + if (tripleLike instanceof RDF4JTripleLike) { + // Return original statement - this covers both RDF4JQuad and + // RDF4JTriple + return ((RDF4JTripleLike) tripleLike).asStatement(); + } + + org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject()); + org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate()); + Value object = asValue(tripleLike.getObject()); + + org.eclipse.rdf4j.model.Resource context = null; + if (tripleLike instanceof Quad) { + Quad quad = (Quad) tripleLike; + context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null)); + } + + return getValueFactory().createStatement(subject, predicate, object, context); + } + + /** + * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}. + * <p> + * For the purpose of {@link BlankNode} equivalence, this method will use an + * internal salt UUID that is unique per instance of + * {@link RDF4J}. + * <p> + * <strong>NOTE:</strong> If combining RDF4J statements from multiple + * repositories or models, then their {@link BNode}s may have the same + * {@link BNode#getID()}, which with this method would become equivalent + * according to {@link BlankNode#equals(Object)} and + * {@link BlankNode#uniqueReference()}, unless a separate + * {@link RDF4J} instance is used per RDF4J repository/model. + * + * @param statement + * The RDF4J {@link Statement} to adapt. + * @return A {@link RDF4JTriple} that is equivalent to the statement + */ + public RDF4JTriple asTriple(final Statement statement) { + return rdf4j.createTripleImpl(statement, salt); + } + + /** + * Adapt a Commons RDF {@link RDFTerm} as a RDF4J {@link Value}. + * <p> + * The value will be of the same kind as the term, e.g. a + * {@link org.apache.commons.rdf.api.BlankNode} is converted to a + * {@link org.eclipse.rdf4j.model.BNode}, a + * {@link org.apache.commons.rdf.api.IRI} is converted to a + * {@link org.eclipse.rdf4j.model.IRI} and a + * {@link org.apache.commons.rdf.api.Literal} is converted to a + * {@link org.eclipse.rdf4j.model.Literal}. + * <p> + * If the provided {@link RDFTerm} is <code>null</code>, then the returned + * value is <code>null</code>. + * <p> + * If the provided term is an instance of {@link RDF4JTerm}, then the + * {@link RDF4JTerm#asValue()} is returned without any conversion. Note that + * this could mean that a {@link Value} from a different kind of + * {@link ValueFactory} could be returned. + * + * @param term + * RDFTerm to adapt to RDF4J Value + * @return Adapted RDF4J {@link Value} + */ + public Value asValue(RDFTerm term) { + if (term == null) { + return null; + } + if (term instanceof RDF4JTerm) { + // One of our own - avoid converting again. + // (This is crucial to avoid double-escaping in BlankNode) + return ((RDF4JTerm) term).asValue(); + } + if (term instanceof org.apache.commons.rdf.api.IRI) { + org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) term; + return getValueFactory().createIRI(iri.getIRIString()); + } + if (term instanceof org.apache.commons.rdf.api.Literal) { + org.apache.commons.rdf.api.Literal literal = (org.apache.commons.rdf.api.Literal) term; + String label = literal.getLexicalForm(); + if (literal.getLanguageTag().isPresent()) { + String lang = literal.getLanguageTag().get(); + return getValueFactory().createLiteral(label, lang); + } + org.eclipse.rdf4j.model.IRI dataType = (org.eclipse.rdf4j.model.IRI) asValue(literal.getDatatype()); + return getValueFactory().createLiteral(label, dataType); + } + if (term instanceof BlankNode) { + // This is where it gets tricky to support round trips! + BlankNode blankNode = (BlankNode) term; + // FIXME: The uniqueReference might not be a valid BlankNode + // identifier.. + // does it have to be in RDF4J? + return getValueFactory().createBNode(blankNode.uniqueReference()); + } + throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass()); + } + + @Override + public RDF4JBlankNode createBlankNode() { + BNode bnode = getValueFactory().createBNode(); + return (RDF4JBlankNode) asRDFTerm(bnode); + } + + @Override + public RDF4JBlankNode createBlankNode(String name) { + BNode bnode = getValueFactory().createBNode(name); + return (RDF4JBlankNode) asRDFTerm(bnode); + } + + /** + * {@inheritDoc} + * <p> + * <strong>Note:</strong> Some operations on the {@link RDF4JDataset} + * requires the use of try-with-resources to close underlying + * {@link RepositoryConnection}s, including + * {@link RDF4JDataset#iterate()}, + * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}. + * + */ + @Override + public RDF4JDataset createDataset() { + Sail sail = new MemoryStore(); + Repository repository = new SailRepository(sail); + return rdf4j.createRepositoryDatasetImpl(repository, true, false); + } + + @Override + public RDF4JGraph createGraph() { + return asRDFTermGraph(new LinkedHashModel()); + } + + @Override + public RDF4JIRI createIRI(String iri) throws IllegalArgumentException { + return (RDF4JIRI) asRDFTerm(getValueFactory().createIRI(iri)); + } + + @Override + public RDF4JLiteral createLiteral(String lexicalForm) + throws IllegalArgumentException { + org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm); + return (RDF4JLiteral) asRDFTerm(lit); + } + + @Override + public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType) + throws IllegalArgumentException { + org.eclipse.rdf4j.model.IRI iri = getValueFactory().createIRI(dataType.getIRIString()); + org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, iri); + return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit); + } + + @Override + public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag) + throws IllegalArgumentException { + org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, languageTag); + return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit); + } + + @Override + public RDF4JTriple createTriple(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) + throws IllegalArgumentException { + final Statement statement = getValueFactory().createStatement( + (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate), + asValue(object)); + return asTriple(statement); + } + + @Override + public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, + RDFTerm object) throws IllegalArgumentException { + final Statement statement = getValueFactory().createStatement( + (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate), + asValue(object), (org.eclipse.rdf4j.model.Resource) asValue(graphName)); + return asQuad(statement); + } + + public ValueFactory getValueFactory() { + return valueFactory; + } + + private EnumSet<Option> optionSet(Option... options) { + EnumSet<Option> opts = EnumSet.noneOf(Option.class); + opts.addAll(Arrays.asList(options)); + return opts; + } + + + +} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java index 2ed616f..15ca381 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JBlankNode.java @@ -27,7 +27,7 @@ import org.eclipse.rdf4j.model.BNode; * The underlying RDF4J {@link BNode} instance can * be retrieved with {@link #asValue()}. * - * @see RDF4JFactory#createBlankNode() + * @see RDF4J#createBlankNode() */ public interface RDF4JBlankNode extends RDF4JBlankNodeOrIRI, BlankNode { http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java index 2066c34..28c2659 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JDataset.java @@ -30,8 +30,8 @@ import org.apache.commons.rdf.api.RDFTerm; /** * Marker interface for RDF4J implementations of Dataset. * - * @see RDF4JFactory#createDataset() - * @see RDF4JFactory#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...) + * @see RDF4J#createDataset() + * @see RDF4J#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...) */ public interface RDF4JDataset extends Dataset, RDF4JGraphLike<Quad> { http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java deleted file mode 100644 index 8dd9745..0000000 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JFactory.java +++ /dev/null @@ -1,601 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.rdf.rdf4j; - -import java.util.Arrays; -import java.util.EnumSet; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; - -// To avoid confusion, avoid importing -// classes that are in both -// commons.rdf and openrdf.model (e.g. IRI, Literal) -import org.apache.commons.rdf.api.BlankNode; -import org.apache.commons.rdf.api.BlankNodeOrIRI; -import org.apache.commons.rdf.api.Dataset; -import org.apache.commons.rdf.api.Graph; -import org.apache.commons.rdf.api.Quad; -import org.apache.commons.rdf.api.RDFTerm; -import org.apache.commons.rdf.api.RDF; -import org.apache.commons.rdf.api.Triple; -import org.apache.commons.rdf.api.TripleLike; -import org.apache.commons.rdf.rdf4j.impl.InternalRDF4JFactory; -import org.eclipse.rdf4j.model.BNode; -import org.eclipse.rdf4j.model.Model; -import org.eclipse.rdf4j.model.Resource; -import org.eclipse.rdf4j.model.Statement; -import org.eclipse.rdf4j.model.Value; -import org.eclipse.rdf4j.model.ValueFactory; -import org.eclipse.rdf4j.model.impl.LinkedHashModel; -import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import org.eclipse.rdf4j.repository.Repository; -import org.eclipse.rdf4j.repository.RepositoryConnection; -import org.eclipse.rdf4j.repository.sail.SailRepository; -import org.eclipse.rdf4j.sail.Sail; -import org.eclipse.rdf4j.sail.memory.MemoryStore; - -/** - * RDF4J implementation of RDF. - * <p> - * The {@link #RDF4JFactory()} constructor uses a {@link SimpleValueFactory} - * to create corresponding RDF4J {@link Value} instances. Alternatively, this - * factory can be constructed with a different {@link ValueFactory} using - * {@link #RDF4JFactory(ValueFactory)}. - * <p> - * {@link #asRDFTerm(Value)} can be used to convert any RDF4J {@link Value} to - * an RDFTerm. Note that adapted {@link BNode}s are considered equal if they are - * converted with the same {@link RDF4JFactory} instance and have the same - * {@link BNode#getID()}. - * <p> - * {@link #createGraph()} creates a new Graph backed by {@link LinkedHashModel}. - * To use other models, see {@link #asRDFTermGraph(Model)}. - * <p> - * To adapt a RDF4J {@link Repository} as a {@link Dataset} or {@link Graph}, - * use {@link #asRDFTermDataset(Repository, Option...)} - * or - * {@link #asRDFTermGraph(Repository, Option...)}. - * <p> - * {@link #asTriple(Statement)} can be used to convert a RDF4J {@link Statement} - * to a Commons RDF {@link Triple}, and equivalent {@link #asQuad(Statement)} to - * convert a {@link Quad}. - * <p> - * To convert any {@link Triple} or {@link Quad} to to RDF4J {@link Statement}, - * use {@link #asStatement(TripleLike)}. This recognises previously converted - * {@link RDF4JTriple}s and {@link RDF4JQuad}s without re-converting their - * {@link RDF4JTripleLike#asStatement()}. - * <p> - * Likewise, {@link #asValue(RDFTerm)} can be used to convert any Commons RDF - * {@link RDFTerm} to a corresponding RDF4J {@link Value}. This recognises - * previously converted {@link RDF4JTerm}s without re-converting their - * {@link RDF4JTerm#asValue()}. - * <p> - * For the purpose of {@link BlankNode} equivalence, this factory contains an - * internal {@link UUID} salt that is used by adapter methods like - * {@link #asQuad(Statement)}, {@link #asTriple(Statement)}, - * {@link #asRDFTerm(Value)} as well as {@link #createBlankNode(String)}. As - * RDF4J {@link BNode} instances from multiple repositories or models may have - * the same {@link BNode#getID()}, converting them with the above methods might - * cause accidental {@link BlankNode} equivalence. Note that the {@link Graph} - * and {@link Dataset} adapter methods like - * {@link #asRDFTermDataset(Repository, Option...)} - * and - * {@link #asRDFTermGraph(Repository, Option...)} - * therefore uses a unique {@link RDF4JFactory} internally. - * - */ -public final class RDF4JFactory implements RDF { - - /** - * InternalRDF4JFactory is deliberately abstract - */ - private static InternalRDF4JFactory rdf4j = new InternalRDF4JFactory() { - }; - - public enum Option { - /** - * The Graph/Dataset should include any inferred statements - */ - includeInferred, - /** - * The graph/dataset should handle {@link Repository#initialize()} (if - * needed) and {@link Repository#shutDown()} on {@link Graph#close()} / - * {@link Dataset#close()}. - */ - handleInitAndShutdown - } - - private final UUID salt; - - private final ValueFactory valueFactory; - - /** - * Construct an {@link RDF4JFactory}. - * - */ - public RDF4JFactory() { - this(SimpleValueFactory.getInstance(), UUID.randomUUID()); - } - - /** - * Construct an {@link RDF4JFactory}. - * <p> - * This constructor is intended for use with the value factory from - * {@link Repository#getValueFactory()} when using - * Repository-based graphs and datasets. - * - * @param valueFactory - * The RDF4J {@link ValueFactory} to use - */ - public RDF4JFactory(ValueFactory valueFactory) { - this(valueFactory, UUID.randomUUID()); - } - - /** - * Construct an {@link RDF4JFactory}. - * <p> - * This constructor may be used if reproducible - * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable. - * - * @param salt - * An {@link UUID} salt to be used by any created - * {@link BlankNode}s for the purpose of - * {@link BlankNode#uniqueReference()} - */ - public RDF4JFactory(UUID salt) { - this(SimpleValueFactory.getInstance(), salt); - } - /** - * Construct an {@link RDF4JFactory}. - * <p> - * This constructor may be used if reproducible - * {@link BlankNode#uniqueReference()} in {@link BlankNode} is desirable. - * - * @param valueFactory - * The RDF4J {@link ValueFactory} to use - * @param salt - * An {@link UUID} salt to be used by any created - * {@link BlankNode}s for the purpose of - * {@link BlankNode#uniqueReference()} - */ - public RDF4JFactory(ValueFactory valueFactory, UUID salt) { - this.valueFactory = valueFactory; - this.salt = salt; - } - - /** - * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Quad}. - * <p> - * For the purpose of {@link BlankNode} equivalence, this method will use an - * internal salt UUID that is unique per instance of - * {@link RDF4JFactory}. - * <p> - * <strong>NOTE:</strong> If combining RDF4J {@link Statement}s multiple - * repositories or models, then their {@link BNode}s may have the same - * {@link BNode#getID()}, which with this method would become equivalent - * according to {@link BlankNode#equals(Object)} and - * {@link BlankNode#uniqueReference()}, unless a separate - * {@link RDF4JFactory} instance is used per RDF4J repository/model. - * - * @param statement - * The statement to convert - * @return A {@link RDF4JQuad} that is equivalent to the statement - */ - public RDF4JQuad asQuad(final Statement statement) { - return rdf4j.createQuadImpl(statement, salt); - } - - /** - * - * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}. - * <p> - * The value will be of the same kind as the term, e.g. a - * {@link org.eclipse.rdf4j.model.BNode} is converted to a - * {@link org.apache.commons.rdf.api.BlankNode}, a - * {@link org.eclipse.rdf4j.model.IRI} is converted to a - * {@link org.apache.commons.rdf.api.IRI} and a - * {@link org.eclipse.rdf4j.model.Literal}. is converted to a - * {@link org.apache.commons.rdf.api.Literal} - * <p> - * For the purpose of {@link BlankNode} equivalence, this method will use an - * internal salt UUID that is unique per instance of - * {@link RDF4JFactory}. - * <p> - * <strong>NOTE:</strong> If combining RDF4J values from multiple - * repositories or models, then their {@link BNode}s may have the same - * {@link BNode#getID()}, which with this method would become equivalent - * according to {@link BlankNode#equals(Object)} and - * {@link BlankNode#uniqueReference()}, unless a separate - * {@link RDF4JFactory} instance is used per RDF4J repository/model. - * - * @param value - * The RDF4J {@link Value} to convert. - * @return A {@link RDFTerm} that corresponds to the RDF4J value - * @throws IllegalArgumentException - * if the value is not a BNode, Literal or IRI - */ - public RDF4JTerm asRDFTerm(Value value) { - return asRDFTerm(value, salt); - } - - /** - * Adapt a RDF4J {@link Value} as a Commons RDF {@link RDFTerm}. - * <p> - * The value will be of the same kind as the term, e.g. a - * {@link org.eclipse.rdf4j.model.BNode} is converted to a - * {@link org.apache.commons.rdf.api.BlankNode}, a - * {@link org.eclipse.rdf4j.model.IRI} is converted to a - * {@link org.apache.commons.rdf.api.IRI} and a - * {@link org.eclipse.rdf4j.model.Literal}. is converted to a - * {@link org.apache.commons.rdf.api.Literal} - * - * @param value - * The RDF4J {@link Value} to convert. - * @param salt - * A {@link UUID} salt to use for uniquely mapping any - * {@link BNode}s. The salt should typically be the same for - * multiple statements in the same {@link Repository} or - * {@link Model} to ensure {@link BlankNode#equals(Object)} and - * {@link BlankNode#uniqueReference()} works as intended. - * @return A {@link RDFTerm} that corresponds to the RDF4J value - * @throws IllegalArgumentException - * if the value is not a BNode, Literal or IRI - */ - public static RDF4JTerm asRDFTerm(final Value value, UUID salt) { - if (value instanceof BNode) { - return rdf4j.createBlankNodeImpl((BNode) value, salt); - } - if (value instanceof org.eclipse.rdf4j.model.Literal) { - return rdf4j.createLiteralImpl((org.eclipse.rdf4j.model.Literal) value); - } - if (value instanceof org.eclipse.rdf4j.model.IRI) { - return rdf4j.createIRIImpl((org.eclipse.rdf4j.model.IRI) value); - } - throw new IllegalArgumentException("Value is not a BNode, Literal or IRI: " + value.getClass()); - } - - /** - * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Dataset}. - * <p> - * Changes to the dataset are reflected in the repository, and vice versa. - * <p> - * <strong>Note:</strong> Some operations on the {@link RDF4JDataset} - * requires the use of try-with-resources to close underlying - * {@link RepositoryConnection}s, including - * {@link RDF4JDataset#iterate()}, - * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}. - * - * @param repository - * RDF4J {@link Repository} to connect to. - * @param options - * Zero or more {@link Option} - * @return A {@link Dataset} backed by the RDF4J repository. - */ - public RDF4JDataset asRDFTermDataset(Repository repository, Option... options) { - EnumSet<Option> opts = optionSet(options); - return rdf4j.createRepositoryDatasetImpl(repository, - opts.contains(Option.handleInitAndShutdown), - opts.contains(Option.includeInferred)); - } - - /** - * Adapt an RDF4J {@link Model} as a Commons RDF {@link Graph}. - * <p> - * Changes to the graph are reflected in the model, and vice versa. - * - * @param model - * RDF4J {@link Model} to adapt. - * @return Adapted {@link Graph}. - */ - public RDF4JGraph asRDFTermGraph(Model model) { - return rdf4j.createModelGraphImpl(model, this); - } - - /** - * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}. - * <p> - * The graph will only include triples in the default graph (equivalent to - * context <code>new Resource[0]{null})</code> in RDF4J). - * <p> - * Changes to the graph are reflected in the repository, and vice versa. - * <p> - * <strong>Note:</strong> Some operations on the {@link RDF4JGraph} - * requires the use of try-with-resources to close underlying - * {@link RepositoryConnection}s, including - * {@link RDF4JGraph#iterate()} and - * {@link RDF4JGraph#stream()}. - * - * @param repository - * RDF4J {@link Repository} to connect to. - * @param options - * Zero or more {@link Option} - * @return A {@link Graph} backed by the RDF4J repository. - */ - public RDF4JGraph asRDFTermGraph(Repository repository, Option... options) { - EnumSet<Option> opts = optionSet(options); - return rdf4j.createRepositoryGraphImpl(repository, - opts.contains(Option.handleInitAndShutdown), - opts.contains(Option.includeInferred), - new Resource[]{null}); // default graph - } - - /** - * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}. - * <p> - * The graph will include triples in any contexts (e.g. the union graph). - * <p> - * Changes to the graph are reflected in the repository, and vice versa. - * - * @param repository - * RDF4J {@link Repository} to connect to. - * @param options - * Zero or more {@link Option} - * @return A union {@link Graph} backed by the RDF4J repository. - */ - public RDF4JGraph asRDFTermGraphUnion(Repository repository, Option... options) { - EnumSet<Option> opts = optionSet(options); - return rdf4j.createRepositoryGraphImpl(repository, - opts.contains(Option.handleInitAndShutdown), - opts.contains(Option.includeInferred), - new Resource[]{}); // union graph - - } - - /** - * Adapt an RDF4J {@link Repository} as a Commons RDF {@link Graph}. - * <p> - * The graph will include triples in the specified contexts. - * <p> - * Changes to the graph are reflected in the repository, and vice versa. - * Triples added/removed to the graph are reflected in all the specified - * contexts. - * <p> - * <strong>Note:</strong> Some operations on the {@link RDF4JGraph} - * requires the use of try-with-resources to close underlying - * {@link RepositoryConnection}s, including - * {@link RDF4JGraph#iterate()} and - * {@link RDF4JGraph#stream()}. - * - * @param repository - * RDF4J {@link Repository} to connect to. - * @param contexts - * A {@link Set} of {@link BlankNodeOrIRI} specifying the graph - * names to use as a context. The set may include the value - * <code>null</code> to indicate the default graph. The empty set - * indicates any context, e.g. the <em>union graph</em>. - * @param option - * Zero or more {@link Option}s - * @return A {@link Graph} backed by the RDF4J repository. - */ - public RDF4JGraph asRDFTermGraph(Repository repository, Set<? extends BlankNodeOrIRI> contexts, - Option... option) { - EnumSet<Option> opts = optionSet(option); - /** NOTE: asValue() deliberately CAN handle <code>null</code> */ - Resource[] resources = contexts.stream().map(g -> (Resource) asValue(g)).toArray(Resource[]::new); - return rdf4j.createRepositoryGraphImpl(Objects.requireNonNull(repository), - opts.contains(Option.handleInitAndShutdown), - opts.contains(Option.includeInferred), - resources); - } - - /** - * Adapt a Commons RDF {@link Triple} or {@link Quad} as a RDF4J - * {@link Statement}. - * <p> - * If the <code>tripleLike</code> argument is an {@link RDF4JTriple} or a - * {@link RDF4JQuad}, then its {@link RDF4JTripleLike#asStatement()} is - * returned as-is. Note that this means that a {@link RDF4JTriple} would - * preserve its {@link Statement#getContext()}, and that any - * {@link BlankNode}s would be deemed equivalent in RDF4J if they have the - * same {@link BNode#getID()}. - * - * @param tripleLike - * A {@link Triple} or {@link Quad} to adapt - * @return A corresponding {@link Statement} - */ - public Statement asStatement(TripleLike tripleLike) { - if (tripleLike instanceof RDF4JTripleLike) { - // Return original statement - this covers both RDF4JQuad and - // RDF4JTriple - return ((RDF4JTripleLike) tripleLike).asStatement(); - } - - org.eclipse.rdf4j.model.Resource subject = (org.eclipse.rdf4j.model.Resource) asValue(tripleLike.getSubject()); - org.eclipse.rdf4j.model.IRI predicate = (org.eclipse.rdf4j.model.IRI) asValue(tripleLike.getPredicate()); - Value object = asValue(tripleLike.getObject()); - - org.eclipse.rdf4j.model.Resource context = null; - if (tripleLike instanceof Quad) { - Quad quad = (Quad) tripleLike; - context = (org.eclipse.rdf4j.model.Resource) asValue(quad.getGraphName().orElse(null)); - } - - return getValueFactory().createStatement(subject, predicate, object, context); - } - - /** - * Adapt a RDF4J {@link Statement} as a Commons RDF {@link Triple}. - * <p> - * For the purpose of {@link BlankNode} equivalence, this method will use an - * internal salt UUID that is unique per instance of - * {@link RDF4JFactory}. - * <p> - * <strong>NOTE:</strong> If combining RDF4J statements from multiple - * repositories or models, then their {@link BNode}s may have the same - * {@link BNode#getID()}, which with this method would become equivalent - * according to {@link BlankNode#equals(Object)} and - * {@link BlankNode#uniqueReference()}, unless a separate - * {@link RDF4JFactory} instance is used per RDF4J repository/model. - * - * @param statement - * The RDF4J {@link Statement} to adapt. - * @return A {@link RDF4JTriple} that is equivalent to the statement - */ - public RDF4JTriple asTriple(final Statement statement) { - return rdf4j.createTripleImpl(statement, salt); - } - - /** - * Adapt a Commons RDF {@link RDFTerm} as a RDF4J {@link Value}. - * <p> - * The value will be of the same kind as the term, e.g. a - * {@link org.apache.commons.rdf.api.BlankNode} is converted to a - * {@link org.eclipse.rdf4j.model.BNode}, a - * {@link org.apache.commons.rdf.api.IRI} is converted to a - * {@link org.eclipse.rdf4j.model.IRI} and a - * {@link org.apache.commons.rdf.api.Literal} is converted to a - * {@link org.eclipse.rdf4j.model.Literal}. - * <p> - * If the provided {@link RDFTerm} is <code>null</code>, then the returned - * value is <code>null</code>. - * <p> - * If the provided term is an instance of {@link RDF4JTerm}, then the - * {@link RDF4JTerm#asValue()} is returned without any conversion. Note that - * this could mean that a {@link Value} from a different kind of - * {@link ValueFactory} could be returned. - * - * @param term - * RDFTerm to adapt to RDF4J Value - * @return Adapted RDF4J {@link Value} - */ - public Value asValue(RDFTerm term) { - if (term == null) { - return null; - } - if (term instanceof RDF4JTerm) { - // One of our own - avoid converting again. - // (This is crucial to avoid double-escaping in BlankNode) - return ((RDF4JTerm) term).asValue(); - } - if (term instanceof org.apache.commons.rdf.api.IRI) { - org.apache.commons.rdf.api.IRI iri = (org.apache.commons.rdf.api.IRI) term; - return getValueFactory().createIRI(iri.getIRIString()); - } - if (term instanceof org.apache.commons.rdf.api.Literal) { - org.apache.commons.rdf.api.Literal literal = (org.apache.commons.rdf.api.Literal) term; - String label = literal.getLexicalForm(); - if (literal.getLanguageTag().isPresent()) { - String lang = literal.getLanguageTag().get(); - return getValueFactory().createLiteral(label, lang); - } - org.eclipse.rdf4j.model.IRI dataType = (org.eclipse.rdf4j.model.IRI) asValue(literal.getDatatype()); - return getValueFactory().createLiteral(label, dataType); - } - if (term instanceof BlankNode) { - // This is where it gets tricky to support round trips! - BlankNode blankNode = (BlankNode) term; - // FIXME: The uniqueReference might not be a valid BlankNode - // identifier.. - // does it have to be in RDF4J? - return getValueFactory().createBNode(blankNode.uniqueReference()); - } - throw new IllegalArgumentException("RDFTerm was not an IRI, Literal or BlankNode: " + term.getClass()); - } - - @Override - public RDF4JBlankNode createBlankNode() { - BNode bnode = getValueFactory().createBNode(); - return (RDF4JBlankNode) asRDFTerm(bnode); - } - - @Override - public RDF4JBlankNode createBlankNode(String name) { - BNode bnode = getValueFactory().createBNode(name); - return (RDF4JBlankNode) asRDFTerm(bnode); - } - - /** - * {@inheritDoc} - * <p> - * <strong>Note:</strong> Some operations on the {@link RDF4JDataset} - * requires the use of try-with-resources to close underlying - * {@link RepositoryConnection}s, including - * {@link RDF4JDataset#iterate()}, - * {@link RDF4JDataset#stream()} and {@link RDF4JDataset#getGraphNames()}. - * - */ - @Override - public RDF4JDataset createDataset() { - Sail sail = new MemoryStore(); - Repository repository = new SailRepository(sail); - return rdf4j.createRepositoryDatasetImpl(repository, true, false); - } - - @Override - public RDF4JGraph createGraph() { - return asRDFTermGraph(new LinkedHashModel()); - } - - @Override - public RDF4JIRI createIRI(String iri) throws IllegalArgumentException { - return (RDF4JIRI) asRDFTerm(getValueFactory().createIRI(iri)); - } - - @Override - public RDF4JLiteral createLiteral(String lexicalForm) - throws IllegalArgumentException { - org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm); - return (RDF4JLiteral) asRDFTerm(lit); - } - - @Override - public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, org.apache.commons.rdf.api.IRI dataType) - throws IllegalArgumentException { - org.eclipse.rdf4j.model.IRI iri = getValueFactory().createIRI(dataType.getIRIString()); - org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, iri); - return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit); - } - - @Override - public org.apache.commons.rdf.api.Literal createLiteral(String lexicalForm, String languageTag) - throws IllegalArgumentException { - org.eclipse.rdf4j.model.Literal lit = getValueFactory().createLiteral(lexicalForm, languageTag); - return (org.apache.commons.rdf.api.Literal) asRDFTerm(lit); - } - - @Override - public RDF4JTriple createTriple(BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, RDFTerm object) - throws IllegalArgumentException { - final Statement statement = getValueFactory().createStatement( - (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate), - asValue(object)); - return asTriple(statement); - } - - @Override - public Quad createQuad(BlankNodeOrIRI graphName, BlankNodeOrIRI subject, org.apache.commons.rdf.api.IRI predicate, - RDFTerm object) throws IllegalArgumentException { - final Statement statement = getValueFactory().createStatement( - (org.eclipse.rdf4j.model.Resource) asValue(subject), (org.eclipse.rdf4j.model.IRI) asValue(predicate), - asValue(object), (org.eclipse.rdf4j.model.Resource) asValue(graphName)); - return asQuad(statement); - } - - public ValueFactory getValueFactory() { - return valueFactory; - } - - private EnumSet<Option> optionSet(Option... options) { - EnumSet<Option> opts = EnumSet.noneOf(Option.class); - opts.addAll(Arrays.asList(options)); - return opts; - } - - - -} http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java index b7ef9a2..68978ce 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JGraph.java @@ -33,10 +33,10 @@ import org.eclipse.rdf4j.repository.Repository; /** * Marker interface for RDF4J implementations of Graph. * - * @see RDF4JFactory#createGraph() - * @see RDF4JFactory#asRDFTermGraph(Model) - * @see RDF4JFactory#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...) - * @see RDF4JFactory#asRDFTermGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...) + * @see RDF4J#createGraph() + * @see RDF4J#asRDFTermGraph(Model) + * @see RDF4J#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...) + * @see RDF4J#asRDFTermGraphUnion(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...) * @see RDF4JDataset#getGraph() * @see RDF4JDataset#getGraph(BlankNodeOrIRI) */ @@ -64,7 +64,7 @@ public interface RDF4JGraph extends Graph, RDF4JGraphLike<Triple> { * Note that the context mask itself cannot be <code>null</code>. * <p> * The returned set is an immutable copy; to specify a different mask, use - * {@link RDF4JFactory#asRDFTermGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)} + * {@link RDF4J#asRDFTermGraph(Repository, Set, org.apache.commons.rdf.rdf4j.RDF4J.Option...)} * * @return The context mask as a set of {@link BlankNodeOrIRI} graph names, which * may contain the value <code>null</code>. http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java index 270567b..72c83fa 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JIRI.java @@ -24,7 +24,7 @@ package org.apache.commons.rdf.rdf4j; * The underlying RDF4J {@link org.eclipse.rdf4j.model.IRI} * instance can be retrieved with {@link #asValue()}. * - * @see RDF4JFactory#createIRI(String) + * @see RDF4J#createIRI(String) */ public interface RDF4JIRI extends RDF4JBlankNodeOrIRI, org.apache.commons.rdf.api.IRI { http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java index f6b0349..6022da7 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JLiteral.java @@ -24,7 +24,7 @@ package org.apache.commons.rdf.rdf4j; * The underlying RDF4J {@link org.eclipse.rdf4j.model.Literal} instance can be * retrieved with {@link #asValue()}. * - * @see RDF4JFactory#createLiteral(String) + * @see RDF4J#createLiteral(String) */ public interface RDF4JLiteral extends RDF4JTerm, org.apache.commons.rdf.api.Literal { } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java index d3fbcf0..23b6cdf 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JQuad.java @@ -22,7 +22,7 @@ import org.apache.commons.rdf.api.Quad; /** * Marker interface for RDF4J implementations of Quad. * - * @see RDF4JFactory#createQuad(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm) + * @see RDF4J#createQuad(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm) */ public interface RDF4JQuad extends Quad, RDF4JTripleLike { http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java index e475a08..ca32d94 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/RDF4JTriple.java @@ -22,7 +22,7 @@ import org.apache.commons.rdf.api.Triple; /** * Marker interface for RDF4J implementations of Triple. * - * @see RDF4JFactory#createTriple(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm) + * @see RDF4J#createTriple(org.apache.commons.rdf.api.BlankNodeOrIRI, org.apache.commons.rdf.api.IRI, org.apache.commons.rdf.api.RDFTerm) */ public interface RDF4JTriple extends Triple, RDF4JTripleLike { http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java index f9a1e74..558108b 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/experimental/RDF4JParser.java @@ -34,7 +34,7 @@ import org.apache.commons.rdf.experimental.RDFParser; import org.apache.commons.rdf.rdf4j.RDF4JBlankNodeOrIRI; import org.apache.commons.rdf.rdf4j.RDF4JDataset; import org.apache.commons.rdf.rdf4j.RDF4JGraph; -import org.apache.commons.rdf.rdf4j.RDF4JFactory; +import org.apache.commons.rdf.rdf4j.RDF4J; import org.apache.commons.rdf.simple.experimental.AbstractRDFParser; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; @@ -101,20 +101,20 @@ public class RDF4JParser extends AbstractRDFParser<RDF4JParser> implements RDFPa } } - private RDF4JFactory rdf4jTermFactory; + private RDF4J rdf4jTermFactory; private ParserConfig parserConfig = new ParserConfig(); @Override - protected RDF4JFactory createRDFTermFactory() { - return new RDF4JFactory(); + protected RDF4J createRDFTermFactory() { + return new RDF4J(); } @Override protected RDF4JParser prepareForParsing() throws IOException, IllegalStateException { RDF4JParser c = prepareForParsing(); - // Ensure we have an RDF4JFactory for conversion. + // Ensure we have an RDF4J for conversion. // We'll make a new one if user has provided a non-RDF4J factory - c.rdf4jTermFactory = (RDF4JFactory) getRdfTermFactory().filter(RDF4JFactory.class::isInstance) + c.rdf4jTermFactory = (RDF4J) getRdfTermFactory().filter(RDF4J.class::isInstance) .orElseGet(c::createRDFTermFactory); return c; } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java index 1948a32..37487b4 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/AbstractRepositoryGraphLike.java @@ -22,7 +22,7 @@ import java.util.UUID; import org.apache.commons.rdf.api.TripleLike; import org.apache.commons.rdf.rdf4j.RDF4JGraphLike; -import org.apache.commons.rdf.rdf4j.RDF4JFactory; +import org.apache.commons.rdf.rdf4j.RDF4J; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.repository.Repository; @@ -34,7 +34,7 @@ abstract class AbstractRepositoryGraphLike<T extends TripleLike> protected final Repository repository; protected final boolean includeInferred; protected final boolean handleInitAndShutdown; - protected final RDF4JFactory rdf4jTermFactory; + protected final RDF4J rdf4jTermFactory; protected final UUID salt; AbstractRepositoryGraphLike(Repository repository, UUID salt, boolean handleInitAndShutdown, boolean includeInferred) { @@ -45,7 +45,7 @@ abstract class AbstractRepositoryGraphLike<T extends TripleLike> if (handleInitAndShutdown && !repository.isInitialized()) { repository.initialize(); } - rdf4jTermFactory = new RDF4JFactory(repository.getValueFactory(), salt); + rdf4jTermFactory = new RDF4J(repository.getValueFactory(), salt); } @Override http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java index 7744e01..b1cd419 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/InternalRDF4JFactory.java @@ -27,7 +27,7 @@ import org.apache.commons.rdf.rdf4j.RDF4JIRI; import org.apache.commons.rdf.rdf4j.RDF4JLiteral; import org.apache.commons.rdf.rdf4j.RDF4JQuad; import org.apache.commons.rdf.rdf4j.RDF4JTerm; -import org.apache.commons.rdf.rdf4j.RDF4JFactory; +import org.apache.commons.rdf.rdf4j.RDF4J; import org.apache.commons.rdf.rdf4j.RDF4JTriple; import org.eclipse.rdf4j.model.BNode; import org.eclipse.rdf4j.model.IRI; @@ -42,17 +42,17 @@ import org.eclipse.rdf4j.repository.Repository; * <p> * <strong>Internal class:</strong> This "abstract" class is intended for * internal use by Commons RDF and may change in any minor update. Use instead - * {@link RDF4JFactory} methods like - * {@link RDF4JFactory#createBlankNode()}, - * {@link RDF4JFactory#asRDFTerm(org.eclipse.rdf4j.model.Value)} and - * {@link RDF4JFactory#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)} + * {@link RDF4J} methods like + * {@link RDF4J#createBlankNode()}, + * {@link RDF4J#asRDFTerm(org.eclipse.rdf4j.model.Value)} and + * {@link RDF4J#asRDFTermGraph(Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)} * <p> * This class exists as a <code>public</code> bridge between the packages * {@link org.apache.commons.rdf.rdf4j} and * {@link org.apache.commons.rdf.rdf4j.impl} by exposing the package-public * constructors. * - * @see RDF4JFactory + * @see RDF4J */ public abstract class InternalRDF4JFactory { @@ -103,7 +103,7 @@ public abstract class InternalRDF4JFactory { * factory to use for adapting graph triples * @return Adapted {@link RDF4JGraph} */ - public RDF4JGraph createModelGraphImpl(Model model, RDF4JFactory rdf4jTermFactory) { + public RDF4JGraph createModelGraphImpl(Model model, RDF4J rdf4jTermFactory) { return new ModelGraphImpl(model, rdf4jTermFactory); } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java index 0d2695e..ced9c99 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/ModelGraphImpl.java @@ -31,7 +31,7 @@ import org.apache.commons.rdf.api.Triple; import org.apache.commons.rdf.rdf4j.ClosableIterable; import org.apache.commons.rdf.rdf4j.RDF4JBlankNodeOrIRI; import org.apache.commons.rdf.rdf4j.RDF4JGraph; -import org.apache.commons.rdf.rdf4j.RDF4JFactory; +import org.apache.commons.rdf.rdf4j.RDF4J; import org.apache.commons.rdf.rdf4j.RDF4JTriple; import org.eclipse.rdf4j.model.Model; import org.eclipse.rdf4j.model.Resource; @@ -40,9 +40,9 @@ import org.eclipse.rdf4j.repository.Repository; final class ModelGraphImpl implements RDF4JGraph { private Model model; - private RDF4JFactory rdf4jTermFactory; + private RDF4J rdf4jTermFactory; - ModelGraphImpl(Model model, RDF4JFactory rdf4jTermFactory) { + ModelGraphImpl(Model model, RDF4J rdf4jTermFactory) { this.model = model; this.rdf4jTermFactory = rdf4jTermFactory; } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java index cf60883..8da29b6 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/QuadImpl.java @@ -26,7 +26,7 @@ import org.apache.commons.rdf.api.Quad; import org.apache.commons.rdf.api.RDFTerm; import org.apache.commons.rdf.api.Triple; import org.apache.commons.rdf.rdf4j.RDF4JQuad; -import org.apache.commons.rdf.rdf4j.RDF4JFactory; +import org.apache.commons.rdf.rdf4j.RDF4J; import org.eclipse.rdf4j.model.Statement; final class QuadImpl implements Quad, RDF4JQuad { @@ -65,23 +65,23 @@ final class QuadImpl implements Quad, RDF4JQuad { if (statement.getContext() == null) { return Optional.empty(); } - BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4JFactory.asRDFTerm(statement.getContext(), salt); + BlankNodeOrIRI g = (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getContext(), salt); return Optional.of(g); } @Override public RDFTerm getObject() { - return RDF4JFactory.asRDFTerm(statement.getObject(), salt); + return RDF4J.asRDFTerm(statement.getObject(), salt); } @Override public org.apache.commons.rdf.api.IRI getPredicate() { - return (org.apache.commons.rdf.api.IRI) RDF4JFactory.asRDFTerm(statement.getPredicate(), null); + return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null); } @Override public BlankNodeOrIRI getSubject() { - return (BlankNodeOrIRI) RDF4JFactory.asRDFTerm(statement.getSubject(), salt); + return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt); } @Override http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java index 23041c4..0526c77 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/impl/TripleImpl.java @@ -23,7 +23,7 @@ import java.util.UUID; import org.apache.commons.rdf.api.BlankNodeOrIRI; import org.apache.commons.rdf.api.RDFTerm; import org.apache.commons.rdf.api.Triple; -import org.apache.commons.rdf.rdf4j.RDF4JFactory; +import org.apache.commons.rdf.rdf4j.RDF4J; import org.apache.commons.rdf.rdf4j.RDF4JTriple; import org.eclipse.rdf4j.model.Statement; @@ -54,17 +54,17 @@ final class TripleImpl implements Triple, RDF4JTriple { @Override public RDFTerm getObject() { - return RDF4JFactory.asRDFTerm(statement.getObject(), salt); + return RDF4J.asRDFTerm(statement.getObject(), salt); } @Override public org.apache.commons.rdf.api.IRI getPredicate() { - return (org.apache.commons.rdf.api.IRI) RDF4JFactory.asRDFTerm(statement.getPredicate(), null); + return (org.apache.commons.rdf.api.IRI) RDF4J.asRDFTerm(statement.getPredicate(), null); } @Override public BlankNodeOrIRI getSubject() { - return (BlankNodeOrIRI) RDF4JFactory.asRDFTerm(statement.getSubject(), salt); + return (BlankNodeOrIRI) RDF4J.asRDFTerm(statement.getSubject(), salt); } @Override http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java index f17a499..51556bc 100644 --- a/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java +++ b/rdf4j/src/main/java/org/apache/commons/rdf/rdf4j/package-info.java @@ -18,9 +18,9 @@ /** * Commons RDF integration with <a href="http://rdf4j.org/">RDF4J</a>. * <p> - * Use the {@link org.apache.commons.rdf.rdf4j.RDF4JFactory} to convert + * Use the {@link org.apache.commons.rdf.rdf4j.RDF4J} to convert * between Commons RDF and RDF4J types, for instance - * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asQuad(org.eclipse.rdf4j.model.Statement)} + * {@link org.apache.commons.rdf.rdf4j.RDF4J#asQuad(org.eclipse.rdf4j.model.Statement)} * converts a RDF4J {@link org.eclipse.rdf4j.model.Statement} to a * {@link org.apache.commons.rdf.api.Quad}. Converted RDF terms implement the * {@link org.apache.commons.rdf.rdf4j.RDF4JTerm} interface, and converted @@ -32,9 +32,9 @@ * {@link org.eclipse.rdf4j.repository.Repository} instances can be adapted to * Commons RDF {@link org.apache.commons.rdf.api.Graph} and * {@link org.apache.commons.rdf.api.Dataset}, e.g. using - * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asRDFTermGraph(org.eclipse.rdf4j.model.Model)} + * {@link org.apache.commons.rdf.rdf4j.RDF4J#asRDFTermGraph(org.eclipse.rdf4j.model.Model)} * or - * {@link org.apache.commons.rdf.rdf4j.RDF4JFactory#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4JFactory.Option...)} + * {@link org.apache.commons.rdf.rdf4j.RDF4J#asRDFTermDataset(org.eclipse.rdf4j.repository.Repository, org.apache.commons.rdf.rdf4j.RDF4J.Option...)} * The returned adapted graph/dataset is directly mapped, so changes are * propagated both ways. For convenience, the marker interface * {@link org.apache.commons.rdf.rdf4j.RDF4JGraph} and http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory ---------------------------------------------------------------------- diff --git a/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory index bfcdc12..f8a94bb 100644 --- a/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory +++ b/rdf4j/src/main/resources/META-INF/services/org.apache.commons.rdf.api.RDFFactory @@ -1 +1 @@ -org.apache.commons.rdf.rdf4j.RDF4JFactory +org.apache.commons.rdf.rdf4j.RDF4J http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java index 1da3c11..d31c24d 100644 --- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java +++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/BlankNodeTest.java @@ -22,7 +22,7 @@ import org.apache.commons.rdf.api.BlankNode; public class BlankNodeTest extends AbstractBlankNodeTest { - RDF4JFactory factory = new RDF4JFactory(); + RDF4J factory = new RDF4J(); @Override protected BlankNode getBlankNode() { http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java index 7d6104d..4ad8969 100644 --- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java +++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/GraphTest.java @@ -24,7 +24,7 @@ public class GraphTest extends AbstractGraphTest{ @Override public RDF createFactory() { - return new RDF4JFactory(); + return new RDF4J(); } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java index 5377983..37ba0ff 100644 --- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java +++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryGraphTest.java @@ -33,9 +33,9 @@ import org.eclipse.rdf4j.sail.memory.model.MemValueFactory; public class MemoryGraphTest extends AbstractGraphTest { - public static final class MemoryStoreFactory implements RDF { + public static final class MemoryStoreRDF implements RDF { - RDF4JFactory rdf4jFactory = new RDF4JFactory(new MemValueFactory()); + RDF4J rdf4jFactory = new RDF4J(new MemValueFactory()); public RDF4JBlankNode createBlankNode() { return rdf4jFactory.createBlankNode(); @@ -83,7 +83,7 @@ public class MemoryGraphTest extends AbstractGraphTest { @Override public RDF createFactory() { - return new MemoryStoreFactory(); + return new MemoryStoreRDF(); } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java index 73ea05e..83968ee 100644 --- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java +++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/MemoryRDFTermFactoryTest.java @@ -25,7 +25,7 @@ public class MemoryRDFTermFactoryTest extends AbstractRDFTermFactoryTest { @Override public RDF createFactory() { - return new MemoryGraphTest.MemoryStoreFactory(); + return new MemoryGraphTest.MemoryStoreRDF(); } @Override http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java index 7b31738..bedea22 100644 --- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java +++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/NativeStoreGraphTest.java @@ -49,9 +49,9 @@ import org.junit.rules.Timeout; */ public class NativeStoreGraphTest extends AbstractGraphTest { - public final class NativeStoreFactory implements RDF { + public final class NativeStoreRDF implements RDF { - RDF4JFactory rdf4jFactory = new RDF4JFactory(getRepository().getValueFactory()); + RDF4J rdf4jFactory = new RDF4J(getRepository().getValueFactory()); @Override public RDF4JGraph createGraph() { @@ -146,7 +146,7 @@ public class NativeStoreGraphTest extends AbstractGraphTest { @Override public RDF createFactory() { - return new NativeStoreFactory(); + return new NativeStoreRDF(); } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java index 46da04a..cbd85f1 100644 --- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java +++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/RDF4JServiceLoaderTest.java @@ -31,10 +31,10 @@ public class RDF4JServiceLoaderTest { public void testServiceLoaderLookup() { ServiceLoader<RDF> loader = ServiceLoader.load(RDF.class); for (RDF impl : loader) { - if (impl instanceof RDF4JFactory) { + if (impl instanceof RDF4J) { return; // yay } } - fail("RDF4JFactory not found in ServiceLoader"); + fail("RDF4J not found in ServiceLoader"); } } http://git-wip-us.apache.org/repos/asf/incubator-commonsrdf/blob/defb7d81/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java ---------------------------------------------------------------------- diff --git a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java index 24283c3..502d9ac 100644 --- a/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java +++ b/rdf4j/src/test/java/org/apache/commons/rdf/rdf4j/Rdf4JRDFTermFactoryTest.java @@ -25,7 +25,7 @@ public class Rdf4JRDFTermFactoryTest extends AbstractRDFTermFactoryTest { @Override public RDF createFactory() { - return new RDF4JFactory(); + return new RDF4J(); } @Override