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.sword.jersey; 017 018import org.apache.abdera.model.Service; 019 020import javax.ws.rs.WebApplicationException; 021import javax.ws.rs.core.MediaType; 022import javax.ws.rs.core.MultivaluedMap; 023import javax.ws.rs.ext.MessageBodyWriter; 024import javax.ws.rs.ext.Provider; 025import java.io.IOException; 026import java.io.OutputStream; 027import java.lang.annotation.Annotation; 028import java.lang.reflect.Type; 029 030/** 031 * @author claussni 032 */ 033@Provider 034public class AbderaServiceMessageBodyWriter implements MessageBodyWriter<Service> { 035 @Override 036 public boolean isWriteable( 037 final Class<?> type, 038 final Type genericType, 039 final Annotation[] annotations, 040 final MediaType mediaType) { 041 return genericType == Service.class; 042 } 043 044 @Override 045 public long getSize( 046 final Service elements, 047 final Class<?> type, 048 final Type genericType, 049 final Annotation[] annotations, 050 final MediaType mediaType) { 051 // deprecated by JAX-RS 2.0 and ignored by Jersey runtime 052 return 0; 053 } 054 055 @Override 056 public void writeTo( 057 final Service elements, 058 final Class<?> type, 059 final Type genericType, 060 final Annotation[] annotations, 061 final MediaType mediaType, 062 final MultivaluedMap<String, Object> httpHeaders, 063 final OutputStream entityStream) 064 throws IOException, WebApplicationException { 065 elements.writeTo(entityStream); 066 } 067}