Element element = createElement("urn:Bean", "root", "b");
MapNamespaceContext namespaces = new MapNamespaceContext();
for (Map.Entry<String, String> entry : getNamespaces().entrySet()) {
namespaces.addNamespace(entry.getKey(), entry.getValue());
}
ElementWriter rootWriter = getElementWriter(element, namespaces);
Context context = getContext();
// get Type based on the object instance
assertNotNull("type is null", type);
// write the ref
SoapRefType soapRefType = new SoapRefType(type);
MessageWriter cwriter = rootWriter.getElementWriter(soapRefType.getSchemaType());
soapRefType.writeObject(instance, cwriter, context);
cwriter.close();
// write the trailing blocks (referenced objects)
trailingBlocks.writeBlocks(rootWriter, context);