return new XmlWrapper(((ByteArrayOutputStream)rt.getOutputStream()).toByteArray(), null);
}
@SuppressWarnings("unchecked")
public Source marshal(XmlWrapper xmlWrapper, ValidationEventHandler errorHandler) {
MediaType type = null;
String contentType = xmlWrapper.getType();
if (contentType == null) {
// should never happen
type = MediaType.APPLICATION_OCTET_STREAM_TYPE;
} else if (contentType.equals("xhtml")) {
type = MediaType.APPLICATION_XML_TYPE;
} else {
type = MediaType.valueOf(contentType);
}
RuntimeContext runtimeContext = RuntimeContextTLS.getRuntimeContext();
Providers providers = runtimeContext.getProviders();
Class<? extends Object> cls = xmlWrapper.getValue().getClass();
// this code ignores possible generic types
// if in the future we would like to support the generic types
// should check here if cls is GenericEntity and handle it
MessageBodyWriter<Object> writer =
(MessageBodyWriter<Object>)providers.getMessageBodyWriter(cls, cls, null, type);
if (writer == null) {
logger.error(Messages.getMessage("noWriterFound"), cls.getName(), type.toString());
throw new WebApplicationException(500);
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {