1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.commons.rdf.rdf4j.impl; 19 20 import java.util.UUID; 21 22 import org.apache.commons.rdf.api.BlankNode; 23 import org.apache.commons.rdf.rdf4j.RDF4JBlankNode; 24 import org.apache.commons.rdf.rdf4j.RDF4JDataset; 25 import org.apache.commons.rdf.rdf4j.RDF4JGraph; 26 import org.apache.commons.rdf.rdf4j.RDF4JIRI; 27 import org.apache.commons.rdf.rdf4j.RDF4JLiteral; 28 import org.apache.commons.rdf.rdf4j.RDF4JQuad; 29 import org.apache.commons.rdf.rdf4j.RDF4JTerm; 30 import org.apache.commons.rdf.rdf4j.RDF4J; 31 import org.apache.commons.rdf.rdf4j.RDF4JTriple; 32 import org.eclipse.rdf4j.model.BNode; 33 import org.eclipse.rdf4j.model.IRI; 34 import org.eclipse.rdf4j.model.Literal; 35 import org.eclipse.rdf4j.model.Model; 36 import org.eclipse.rdf4j.model.Resource; 37 import org.eclipse.rdf4j.model.Statement; 38 import org.eclipse.rdf4j.repository.Repository; 39 40 /** 41 * Factory for {@link RDF4JTerm} instances. 42 * <p> 43 * <strong>Internal class:</strong> This "abstract" class is intended for 44 * internal use by Commons RDF and may change in any minor update. Use instead 45 * {@link RDF4J} methods like {@link RDF4J#createBlankNode()}, 46 * {@link RDF4J#asRDFTerm(org.eclipse.rdf4j.model.Value)} and 47 * {@link RDF4J#asGraph(Repository, Option...)} 48 * <p> 49 * This class exists as a <code>public</code> bridge between the packages 50 * {@link org.apache.commons.rdf.rdf4j} and 51 * {@link org.apache.commons.rdf.rdf4j.impl} by exposing the package-public 52 * constructors. 53 * 54 * @see RDF4J 55 */ 56 public abstract class InternalRDF4JFactory { 57 58 /** 59 * Construct a {@link RDF4JBlankNode} from a RDF4J {@link BNode}. 60 * 61 * @param bNode 62 * RDF4J {@link BNode} to adapt 63 * @param salt 64 * {@link UUID} to use for {@link BlankNode#uniqueReference()} in 65 * combination with {@link BNode#getID()} 66 * @return Adapted {@link RDF4JBlankNode} 67 */ 68 public RDF4JBlankNode createBlankNodeImpl(final BNode bNode, final UUID salt) { 69 return new BlankNodeImpl(bNode, salt); 70 } 71 72 /** 73 * Construct a {@link RDF4JIRI} from a RDF4J {@link IRI}. 74 * 75 * @param iri 76 * RDF4J {@link IRI} to adapt 77 * @return Adapted {@link RDF4JIRI} 78 */ 79 public RDF4JIRI createIRIImpl(final IRI iri) { 80 return new IRIImpl(iri); 81 } 82 83 /** 84 * Construct a {@link RDF4JLiteral} from a RDF4J {@link Literal}. 85 * 86 * @param literal 87 * RDF4J {@link Literal} 88 * @return Adapted {@link RDF4JLiteral} 89 */ 90 public RDF4JLiteral createLiteralImpl(final Literal literal) { 91 return new LiteralImpl(literal); 92 } 93 94 /** 95 * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}. 96 * <p> 97 * Changes in the graph will be reflected in the model, and vice versa. 98 * 99 * @param model 100 * RDF4J {@link Model} to adapt 101 * @param rdf4jTermFactory 102 * factory to use for adapting graph triples 103 * @return Adapted {@link RDF4JGraph} 104 */ 105 public RDF4JGraph createModelGraphImpl(final Model model, final RDF4J rdf4jTermFactory) { 106 return new ModelGraphImpl(model, rdf4jTermFactory); 107 } 108 109 /** 110 * Construct a {@link RDF4JQuad} from a RDF4J {@link Statement}. 111 * 112 * @param statement 113 * RDF4J {@link Statement} to adapt 114 * @param salt 115 * {@link UUID} for adapting any {@link BNode}s 116 * @return Adapted {@link RDF4JQuad} 117 */ 118 public RDF4JQuad createQuadImpl(final Statement statement, final UUID salt) { 119 return new QuadImpl(statement, salt); 120 } 121 122 /** 123 * Construct a {@link RDF4JDataset} from a RDF4J {@link Repository}. 124 * <p> 125 * Changes in the dataset will be reflected in the repsitory, and vice 126 * versa. 127 * 128 * @param repository 129 * RDF4J {@link Repository} to adapt 130 * @param handleInitAndShutdown 131 * If <code>true</code>, the {@link RDF4JDataset} will initialize 132 * the repository (if needed), and shut it down on 133 * {@link RDF4JDataset#close()}. 134 * @param includeInferred 135 * If true, any inferred quads are included in the dataset 136 * 137 * @return Adapted {@link RDF4JDataset} 138 */ 139 public RDF4JDataset createRepositoryDatasetImpl(final Repository repository, final boolean handleInitAndShutdown, 140 final boolean includeInferred) { 141 return new RepositoryDatasetImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred); 142 } 143 144 /** 145 * Construct a {@link RDF4JGraph} from a RDF4J {@link Model}. 146 * <p> 147 * Changes in the graph will be reflected in the model, and vice versa. 148 * 149 * @param repository 150 * RDF4J {@link Repository} to adapt 151 * @param handleInitAndShutdown 152 * If <code>true</code>, the {@link RDF4JGraph} will initialize 153 * the repository (if needed), and shut it down on 154 * {@link RDF4JGraph#close()}. 155 * @param includeInferred 156 * If true, any inferred quads are included in the dataset 157 * @param contextMask 158 * Zero or more {@link Resource}s contexts. The array may contain 159 * the value <code>null</code> for the default graph - however 160 * care must be taken to not provide a null-array 161 * <code>(Resource[]) null</code>. 162 * @return Adapted {@link RDF4JGraph} 163 */ 164 public RDF4JGraph createRepositoryGraphImpl(final Repository repository, final boolean handleInitAndShutdown, 165 final boolean includeInferred, final Resource... contextMask) { 166 return new RepositoryGraphImpl(repository, UUID.randomUUID(), handleInitAndShutdown, includeInferred, 167 contextMask); 168 } 169 170 /** 171 * Construct a {@link RDF4JTriple} from a RDF4J {@link Statement}. 172 * 173 * @param statement 174 * RDF4J {@link Statement} to adapt 175 * @param salt 176 * {@link UUID} for adapting any {@link BNode}s 177 * @return Adapted {@link RDF4JTriple} 178 */ 179 public RDF4JTriple createTripleImpl(final Statement statement, final UUID salt) { 180 return new TripleImpl(statement, salt); 181 } 182 183 }