001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.automation.jaxrs.io; 013 014import java.io.IOException; 015import java.io.OutputStream; 016import java.lang.annotation.Annotation; 017import java.lang.reflect.Type; 018 019import javax.ws.rs.Produces; 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; 025 026import org.nuxeo.ecm.automation.jaxrs.LoginInfo; 027 028/** 029 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 030 */ 031@Provider 032@Produces({ "application/json+nxentity", "application/json" }) 033public class JsonLoginInfoWriter implements MessageBodyWriter<LoginInfo> { 034 035 @Override 036 public long getSize(LoginInfo arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4) { 037 return -1; 038 } 039 040 @Override 041 public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3) { 042 return LoginInfo.class.isAssignableFrom(arg0); 043 } 044 045 @Override 046 public void writeTo(LoginInfo login, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4, 047 MultivaluedMap<String, Object> arg5, OutputStream out) throws IOException, WebApplicationException { 048 JsonWriter.writeLogin(out, login); 049 } 050 051}