001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.commons.rdf.rdf4j.impl; 019 020import java.util.UUID; 021 022import org.apache.commons.rdf.api.BlankNode; 023import org.apache.commons.rdf.rdf4j.RDF4JBlankNode; 024import org.apache.commons.rdf.rdf4j.RDF4JDataset; 025import org.apache.commons.rdf.rdf4j.RDF4JGraph; 026import org.apache.commons.rdf.rdf4j.RDF4JIRI; 027import org.apache.commons.rdf.rdf4j.RDF4JLiteral; 028import org.apache.commons.rdf.rdf4j.RDF4JQuad; 029import org.apache.commons.rdf.rdf4j.RDF4JTerm; 030import org.apache.commons.rdf.rdf4j.RDF4J; 031import org.apache.commons.rdf.rdf4j.RDF4J.Option; 032import org.apache.commons.rdf.rdf4j.RDF4JTriple; 033import org.eclipse.rdf4j.model.BNode; 034import org.eclipse.rdf4j.model.IRI; 035import org.eclipse.rdf4j.model.Literal; 036import org.eclipse.rdf4j.model.Model; 037import org.eclipse.rdf4j.model.Resource; 038import org.eclipse.rdf4j.model.Statement; 039import org.eclipse.rdf4j.repository.Repository; 040 041/** 042 * Factory for {@link RDF4JTerm} instances. 043 * <p> 044 * <strong>Internal class:</strong> This "abstract" class is intended for 045 * internal use by Commons RDF and may change in any minor update. Use instead 046 * {@link RDF4J} methods like {@link RDF4J#createBlankNode()}, 047 * {@link RDF4J#asRDFTerm(org.eclipse.rdf4j.model.Value)} and 048 * {@link RDF4J#asGraph(Repository, Option...)} 049 * <p> 050 * This class exists as a <code>public</code> bridge between the packages 051 * {@link org.apache.commons.rdf.rdf4j} and 052 * {@link org.apache.commons.rdf.rdf4j.impl} by exposing the package-public 053 * constructors. 054 * 055 * @see RDF4J 056 */ 057public abstract class InternalRDF4JFactory { 058 059 /** 060 * Construct a {@link RDF4JBlankNode} from a RDF4J {@link BNode}. 061 * 062 * @param bNode 063 * RDF4J {@link BNode} to adapt 064 * @param salt 065 * {@link UUID} to use for {@link BlankNode#uniqueReference()} in 066 * combination with {@link BNode#getID()} 067 * @return Adapted {@link RDF4JBlankNode} 068 */ 069 public RDF4JBlankNode createBlankNodeImpl(final BNode bNode, final UUID salt) { 070 return new BlankNodeImpl(bNode, salt); 071 } 072 073 /** 074 * Construct a {@link RDF4JIRI} from a RDF4J {@link IRI}. 075 * 076 * @param iri 077 * RDF4J {@link IRI} to adapt 078 * @return Adapted {@link RDF4JIRI} 079 */ 080 public RDF4JIRI createIRIImpl(final IRI iri) { 081 return new IRIImpl(iri); 082 } 083 084 /** 085 * Construct a {@link RDF4JLiteral} from a RDF4J {@link Literal}. 086 * 087 * @param literal 088 * RDF4J {@link Literal} 089 * @return Adapted {@link RDF4JLiteral} 090 */ 091 public RDF4JLiteral createLiteralImpl(final Literal literal) { 092 return new LiteralImpl(literal); 093 } 094 095 /** 096 * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}. 097 * <p> 098 * Changes in the graph will be reflected in the model, and vice versa. 099 * 100 * @param model 101 * RDF4J {@link Model} to adapt 102 * @param rdf4jTermFactory 103 * factory to use for adapting graph triples 104 * @return Adapted {@link RDF4JGraph} 105 */ 106 public RDF4JGraph createModelGraphImpl(final Model model, final RDF4J rdf4jTermFactory) { 107 return new ModelGraphImpl(model, rdf4jTermFactory); 108 } 109 110 /** 111 * Construct a {@link RDF4JQuad} from a RDF4J {@link Statement}. 112 * 113 * @param statement 114 * RDF4J {@link Statement} to adapt 115 * @param salt 116 * {@link UUID} for adapting any {@link BNode}s 117 * @return Adapted {@link RDF4JQuad} 118 */ 119 public RDF4JQuad createQuadImpl(final Statement statement, final UUID salt) { 120 return new QuadImpl(statement, salt); 121 } 122 123 /** 124 * Construct a {@link RDF4JDataset} from a RDF4J {@link Repository}. 125 * <p> 126 * Changes in the dataset will be reflected in the repsitory, and vice 127 * versa. 128 * 129 * @param repository 130 * RDF4J {@link Repository} to adapt 131 * @param handleInitAndShutdown 132 * If <code>true</code>, the {@link RDF4JDataset} will initialize 133 * the repository (if needed), and shut it down on 134 * {@link RDF4JDataset#close()}. 135 * @param includeInferred 136 * If true, any inferred quads are included in the dataset 137 * 138 * @return Adapted {@link RDF4JDataset} 139 */ 140 public RDF4JDataset createRepositoryDatasetImpl(final Repository repository, final boolean handleInitAndShutdown, 141 final boolean includeInferred) { 142 return new RepositoryDatasetImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred); 143 } 144 145 /** 146 * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}. 147 * <p> 148 * Changes in the graph will be reflected in the model, and vice versa. 149 * 150 * @param repository 151 * RDF4J {@link Repository} to adapt 152 * @param handleInitAndShutdown 153 * If <code>true</code>, the {@link RDF4JGraph} will initialize 154 * the repository (if needed), and shut it down on 155 * {@link RDF4JGraph#close()}. 156 * @param includeInferred 157 * If true, any inferred quads are included in the dataset 158 * @param contextMask 159 * Zero or more {@link Resource}s contexts. The array may contain 160 * the value <code>null</code> for the default graph - however 161 * care must be taken to not provide a null-array 162 * <code>(Resource[]) null</code>. 163 * @return Adapted {@link RDF4JGraph} 164 */ 165 public RDF4JGraph createRepositoryGraphImpl(final Repository repository, final boolean handleInitAndShutdown, 166 final boolean includeInferred, final Resource... contextMask) { 167 return new RepositoryGraphImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred, 168 contextMask); 169 } 170 171 /** 172 * Construct a {@link RDF4JTriple} from a RDF4J {@link Statement}. 173 * 174 * @param statement 175 * RDF4J {@link Statement} to adapt 176 * @param salt 177 * {@link UUID} for adapting any {@link BNode}s 178 * @return Adapted {@link RDF4JTriple} 179 */ 180 public RDF4JTriple createTripleImpl(final Statement statement, final UUID salt) { 181 return new TripleImpl(statement, salt); 182 } 183 184}