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.modeshape.utils.impl;
017
018import org.fcrepo.kernel.api.utils.CacheEntry;
019import org.fcrepo.kernel.modeshape.utils.BinaryCacheEntry;
020import org.fcrepo.kernel.modeshape.utils.ProjectedCacheEntry;
021import org.modeshape.jcr.value.binary.ExternalBinaryValue;
022
023import javax.jcr.Binary;
024import javax.jcr.Property;
025import javax.jcr.RepositoryException;
026
027/**
028 * @author cabeer
029 */
030public final class CacheEntryFactory {
031
032    /**
033     * No public constructor on utility class
034     */
035    private CacheEntryFactory() {
036    }
037
038    /**
039     * Load a store-specific CacheEntry model
040     * @param property the property
041     * @return CacheEntry model for the property in the given repository
042     * @throws RepositoryException if repository exception occurred
043     */
044    public static CacheEntry forProperty(final Property property) throws RepositoryException {
045        final Binary binary = property.getBinary();
046
047        if (binary instanceof ExternalBinaryValue) {
048            return new ProjectedCacheEntry(property);
049        }
050        return new BinaryCacheEntry(property);
051    }
052}