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.services.functions; 017 018import static com.google.common.base.Preconditions.checkArgument; 019import static com.google.common.base.Throwables.propagate; 020 021import javax.jcr.Property; 022import javax.jcr.RepositoryException; 023 024import org.modeshape.jcr.value.BinaryKey; 025import org.modeshape.jcr.value.BinaryValue; 026 027import com.google.common.base.Function; 028 029/** 030 * Get the internal Modeshape BinaryKey for a binary property 031 * 032 * @author awoods 033 */ 034public class GetBinaryKey implements Function<Property, BinaryKey> { 035 036 @Override 037 public BinaryKey apply(final Property input) { 038 checkArgument(input != null, "null cannot have a Binarykey!"); 039 try { 040 return ((BinaryValue) input.getBinary()).getKey(); 041 } catch (final RepositoryException e) { 042 throw propagate(e); 043 } 044 } 045 046}