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;
019import static org.slf4j.LoggerFactory.getLogger;
020
021import javax.jcr.Node;
022
023import org.fcrepo.kernel.models.FedoraResource;
024import org.fcrepo.kernel.identifiers.IdentifierConverter;
025import org.fcrepo.kernel.utils.iterators.RdfStream;
026import org.slf4j.Logger;
027
028import com.google.common.base.Converter;
029import com.hp.hpl.jena.rdf.model.Resource;
030
031/**
032 * {@link RdfStream} that holds contexts related to a specific {@link Node}.
033 *
034 * @author ajs6f
035 * @since Oct 10, 2013
036 */
037public class NodeRdfContext extends RdfStream {
038
039    private final FedoraResource resource;
040
041    private final IdentifierConverter<Resource, FedoraResource> idTranslator;
042
043    private final com.hp.hpl.jena.graph.Node subject;
044
045    private static final Logger LOGGER = getLogger(NodeRdfContext.class);
046
047    /**
048     * Default constructor.
049     *
050     * @param resource
051     * @param idTranslator
052     */
053    public NodeRdfContext(final FedoraResource resource,
054                          final IdentifierConverter<Resource, FedoraResource> idTranslator) {
055        super();
056        this.resource = resource;
057        this.idTranslator = idTranslator;
058        this.subject = idTranslator.reverse().convert(resource).asNode();
059    }
060
061    /**
062     * @return The {@link Node} in question
063     */
064    public FedoraResource resource() {
065        return resource;
066    }
067
068    /**
069     * @return local {@link org.fcrepo.kernel.identifiers.IdentifierConverter}
070     */
071    public IdentifierConverter<Resource, FedoraResource> translator() {
072        return idTranslator;
073    }
074
075    /**
076     * @return local {@link org.fcrepo.kernel.identifiers.IdentifierConverter}
077     */
078    public Converter<Node, Resource> nodeConverter() {
079        return nodeToResource(idTranslator);
080    }
081
082    /**
083     * @return the RDF subject at the center of this context
084     */
085    public com.hp.hpl.jena.graph.Node subject() {
086        return subject;
087    }
088}