public void marshall(@SuppressWarnings("rawtypes") Class parent, QName qname,
ExtensibilityElement obj, PrintWriter pw,
final Definition wsdl, ExtensionRegistry registry) throws WSDLException {
// TODO Auto-generated method stub
try {
Marshaller u = getContext().createMarshaller();
u.setProperty("jaxb.encoding", "UTF-8");
u.setProperty("jaxb.fragment", Boolean.TRUE);
u.setProperty("jaxb.formatted.output", Boolean.TRUE);
Object mObj = obj;
Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(typeClass) + ".ObjectFactory",
true,
obj.getClass().getClassLoader());
Method methods[] = objectFactory.getDeclaredMethods();
for (Method method : methods) {
if (method.getParameterTypes().length == 1
&& method.getParameterTypes()[0].equals(typeClass)) {
mObj = method.invoke(objectFactory.newInstance(), new Object[] {obj});
}
}
javax.xml.stream.XMLOutputFactory fact = javax.xml.stream.XMLOutputFactory.newInstance();
XMLStreamWriter writer =
new PrettyPrintXMLStreamWriter(fact.createXMLStreamWriter(pw), parent);
writer.setNamespaceContext(new javax.xml.namespace.NamespaceContext() {
public String getNamespaceURI(String arg) {
return wsdl.getNamespace(arg);
}
public String getPrefix(String arg) {
if (arg.equals(jaxbNamespace)) {
arg = namespace;
}
for (Object ent : wsdl.getNamespaces().entrySet()) {
Map.Entry<?, ?> entry = (Map.Entry<?, ?>)ent;
if (arg.equals(entry.getValue())) {
return (String)entry.getKey();
}
}
return null;
}
public Iterator<String> getPrefixes(String arg) {
if (arg.equals(jaxbNamespace)) {
arg = namespace;
}
Iterator<String> ret = CastUtils.cast(wsdl.getNamespaces().keySet().iterator());
return ret;
}
});
u.marshal(mObj, writer);
writer.flush();
} catch (Exception ex) {
throw new WSDLException(WSDLException.PARSER_ERROR,
"",
ex);