001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance 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.fcrepo.kernel.modeshape.rdf.impl; 019 020import static org.fcrepo.kernel.modeshape.identifiers.NodeResourceConverter.nodeToResource; 021 022import javax.jcr.Node; 023 024import org.fcrepo.kernel.api.identifiers.IdentifierConverter; 025import org.fcrepo.kernel.api.models.FedoraResource; 026import org.fcrepo.kernel.api.rdf.DefaultRdfStream; 027 028import com.google.common.base.Converter; 029import org.apache.jena.rdf.model.Resource; 030 031/** 032 * {@link org.fcrepo.kernel.api.RdfStream} that holds contexts related to a specific {@link Node}. 033 * 034 * @author ajs6f 035 * @since Oct 10, 2013 036 */ 037public class NodeRdfContext extends DefaultRdfStream { 038 039 private final FedoraResource resource; 040 041 private final IdentifierConverter<Resource, FedoraResource> idTranslator; 042 043 private final org.apache.jena.graph.Node subject; 044 045 /** 046 * Default constructor. 047 * 048 * @param resource the resource 049 * @param idTranslator the id translator 050 */ 051 public NodeRdfContext(final FedoraResource resource, 052 final IdentifierConverter<Resource, FedoraResource> idTranslator) { 053 super(idTranslator.reverse().convert(resource).asNode()); 054 this.resource = resource; 055 this.idTranslator = idTranslator; 056 this.subject = uriFor(resource); 057 } 058 059 /** 060 * @return The {@link Node} in question 061 */ 062 public FedoraResource resource() { 063 return resource; 064 } 065 066 /** 067 * @return local {@link org.fcrepo.kernel.api.identifiers.IdentifierConverter} 068 */ 069 public IdentifierConverter<Resource, FedoraResource> translator() { 070 return idTranslator; 071 } 072 073 /** 074 * @param resource a Fedora model instance that must be identified by an URI 075 * @return a translated URI for that resource 076 */ 077 protected org.apache.jena.graph.Node uriFor(final FedoraResource resource) { 078 return translator().reverse().convert(resource).asNode(); 079 } 080 081 /** 082 * @return local {@link org.fcrepo.kernel.api.identifiers.IdentifierConverter} 083 */ 084 public Converter<Node, Resource> nodeConverter() { 085 return nodeToResource(idTranslator); 086 } 087 088 /** 089 * @return the RDF subject at the center of this context 090 */ 091 public org.apache.jena.graph.Node subject() { 092 return subject; 093 } 094}