throw new MarshalException("Object must be annotated with @XmlRootElement or be a JAXBElement!");
}
Boolean frag = (Boolean) getProperty(Marshaller.JAXB_FRAGMENT);
XoXMLStreamWriter w = new XoXMLStreamWriterImpl(xsw);
if (frag == null || !frag) {
w.writeStartDocument();
}
JAXBElement jaxbElement = null;
if (o instanceof JAXBElement) {
jaxbElement = (JAXBElement) o;
}
if (jaxbElement != null) {
QName n = jaxbElement.getName();
w.writeStartElement("", n.getLocalPart(), n.getNamespaceURI());
// TODO: we should check to see if a NS is already written here
w.writeDefaultNamespace(n.getNamespaceURI());
o = jaxbElement.getValue();
}
if (o == null) {
w.writeXsiNil();
} else {
Class c = o.getClass();
if (c == String.class) {
w.writeCharacters((String) o);
} else if (c == Boolean.class) {
w.writeBoolean((Boolean) o);
} else if (c == Byte.class) {
w.writeByte((Byte) o);
} else if (c == Double.class) {
w.writeDouble((Double) o);
} else if (c == Float.class) {
w.writeFloat((Float) o);
} else if (c == Long.class) {
w.writeLong((Long) o);
} else if (c == Integer.class) {
w.writeInt((Integer) o);
} else if (c == Short.class) {
w.writeShort((Short) o);
} else if (c == Duration.class) {
w.writeCharacters(((Duration) o).toString());
} else if (c == XMLGregorianCalendar.class) {
w.writeCharacters(((XMLGregorianCalendar) o).toXMLFormat());
} else if (c == byte[].class) {
BinaryUtils.encodeBytes(w, (byte[]) o);
} else {
context.createWriter().write(w, o);
}
}
if (jaxbElement != null) {
w.writeEndElement();
}
if (frag == null || !frag) {
w.writeEndDocument();
}
} catch (Exception e) {
if (e instanceof JAXBException) {
throw (JAXBException) e;
} else if (e instanceof RuntimeException) {