Java Reference
In-Depth Information
package com.soacookbook.rest.forms;
import javax.ws.rs.Produces;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
/**
* Creates an HTML representation of a user.
*/
@Produces("text/html")
@Provider
public class UserHtmlWriter
implements MessageBodyWriter<User> {
//match type parameter to make sure runtime picks up
//this class as writer for User
public boolean isWriteable(Class<?> type, Type genericType,
Annotation[ ] annotations, MediaType mediaType) {
return User.class.isAssignableFrom(type);
}
public long getSize(User data,
Class<?> type, Type genericType,
Annotation annotations[ ], MediaType mediaType) {
return -1;
}
/**
* Gets executed by putting entity in Response and by
* matching that same class to the isWriteable method.
*/
public void writeTo(User user,
Class<?> type, Type genericType,
Annotation[ ] annotations, MediaType mediaType,
MultivaluedMap<String, Object> headers,
OutputStream out) throws IOException {
Search WWH ::




Custom Search