001/** 002 * Copyright 2015 DuraSpace, Inc. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.fcrepo.kernel.impl.rdf.impl; 017 018import static org.fcrepo.kernel.impl.identifiers.NodeResourceConverter.nodeToResource; 019 020import javax.jcr.Node; 021 022import org.fcrepo.kernel.identifiers.IdentifierConverter; 023import org.fcrepo.kernel.models.FedoraResource; 024import org.fcrepo.kernel.utils.iterators.RdfStream; 025 026import com.google.common.base.Converter; 027import com.hp.hpl.jena.rdf.model.Resource; 028 029/** 030 * {@link RdfStream} that holds contexts related to a specific {@link Node}. 031 * 032 * @author ajs6f 033 * @since Oct 10, 2013 034 */ 035public class NodeRdfContext extends RdfStream { 036 037 private final FedoraResource resource; 038 039 private final IdentifierConverter<Resource, FedoraResource> idTranslator; 040 041 private final com.hp.hpl.jena.graph.Node subject; 042 043 044 /** 045 * Default constructor. 046 * 047 * @param resource the resource 048 * @param idTranslator the id translator 049 */ 050 public NodeRdfContext(final FedoraResource resource, 051 final IdentifierConverter<Resource, FedoraResource> idTranslator) { 052 super(); 053 this.resource = resource; 054 this.idTranslator = idTranslator; 055 this.subject = idTranslator.reverse().convert(resource).asNode(); 056 } 057 058 /** 059 * @return The {@link Node} in question 060 */ 061 public FedoraResource resource() { 062 return resource; 063 } 064 065 /** 066 * @return local {@link org.fcrepo.kernel.identifiers.IdentifierConverter} 067 */ 068 public IdentifierConverter<Resource, FedoraResource> translator() { 069 return idTranslator; 070 } 071 072 /** 073 * @return local {@link org.fcrepo.kernel.identifiers.IdentifierConverter} 074 */ 075 public Converter<Node, Resource> nodeConverter() { 076 return nodeToResource(idTranslator); 077 } 078 079 /** 080 * @return the RDF subject at the center of this context 081 */ 082 public com.hp.hpl.jena.graph.Node subject() { 083 return subject; 084 } 085}