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;
017
018import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
019import static org.fcrepo.kernel.RdfLexicon.isManagedNamespace;
020import static org.fcrepo.kernel.RdfLexicon.isManagedPredicate;
021
022import com.google.common.base.Predicate;
023import com.hp.hpl.jena.graph.Triple;
024import com.hp.hpl.jena.rdf.model.Model;
025import com.hp.hpl.jena.rdf.model.Resource;
026
027/**
028 * {@link Predicate}s for determining when RDF is managed by the repository.
029 *
030 * @author ajs6f
031 * @since Oct 23, 2013
032 */
033public final class ManagedRdf {
034
035    private static final Model model = createDefaultModel();
036
037    /**
038     * No public constructor on utility class
039     */
040    private ManagedRdf() {
041    }
042
043    public static final Predicate<Triple> isManagedTriple =
044        new Predicate<Triple>() {
045
046            @Override
047            public boolean apply(final Triple t) {
048                return isManagedPredicate.apply(model.asStatement(t)
049                        .getPredicate());
050            }
051
052        };
053
054    public static final Predicate<Resource> isManagedMixin =
055        new Predicate<Resource>() {
056
057            @Override
058            public boolean apply(final Resource m) {
059                return isManagedNamespace.apply(m.getNameSpace());
060            }
061
062        };
063}