public void writeTo(Feed feed, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException
{
JAXBContextFinder finder = getFinder(mediaType);
if (finder == null)
{
throw new JAXBMarshalException("Unable to find JAXBContext for media type: " + mediaType);
}
HashSet<Class> set = new HashSet<Class>();
set.add(Feed.class);
for (Entry entry : feed.getEntries())
{
if (entry.getAnyOtherJAXBObject() != null)
{
set.add(entry.getAnyOtherJAXBObject().getClass());
}
if (entry.getContent() != null && entry.getContent().getJAXBObject() != null)
{
set.add(entry.getContent().getJAXBObject().getClass());
}
}
try
{
JAXBContext ctx = finder.findCacheContext(mediaType, annotations, set.toArray(new Class[set.size()]));
Marshaller marshaller = ctx.createMarshaller();
NamespacePrefixMapper mapper = new NamespacePrefixMapper()
{
public String getPreferredPrefix(String namespace, String s1, boolean b)
{
if (namespace.equals("http://www.w3.org/2005/Atom")) return "atom";
else return s1;
}
};
marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
marshaller.marshal(feed, entityStream);
}
catch (JAXBException e)
{
throw new JAXBMarshalException("Unable to marshal: " + mediaType, e);
}
}