AegisContext context = getAegisContext(type, genericType);
AegisType aegisType = context.getTypeMapping().getType(genericType);
AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
try {
W3CDOMStreamWriter w3cStreamWriter = new W3CDOMStreamWriter();
XMLStreamWriter spyingWriter = new PrefixCollectingXMLStreamWriter(w3cStreamWriter,
namespaceMap);
spyingWriter.writeStartDocument();
// use type qname as element qname?
aegisWriter.write(obj, aegisType.getSchemaType(), false, spyingWriter, aegisType);
spyingWriter.writeEndDocument();
spyingWriter.close();
Document dom = w3cStreamWriter.getDocument();
// ok, now the namespace map has all the prefixes.
XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(), os);
xmlStreamWriter.writeStartDocument();