List<Class<?>> clses = new ArrayList<Class<?>>(ctxClasses);
clses.add(ref.type.getClass());
try {
JAXBRIContext riContext = JAXBRIContext.newInstance(clses.toArray(new Class[clses.size()]),
typeRefs, null, null, true, null);
Bridge bridge = riContext.createBridge(ref);
if (source instanceof XMLStreamWriter) {
bridge.marshal(elValue, (XMLStreamWriter)source);
} else if (source instanceof OutputStream) {
//the namespace is missing when marshal the xsd:QName type
//to the OutputStream directly
java.io.StringWriter sw = new java.io.StringWriter();
StreamResult s1 = new StreamResult(sw);
bridge.marshal(elValue, s1);
((OutputStream)source).write(sw.toString().getBytes());
} else if (source instanceof Node) {
bridge.marshal(elValue, (Node)source);
} else {
throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
}
} catch (Exception ex) {
ex.printStackTrace();