Red Hat Application Migration Toolkit
package org.exolab.castor.xml;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Writer;
import java.lang.reflect.Method;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.castor.core.util.Messages;
import org.exolab.castor.xml.OutputFormat;
import org.exolab.castor.xml.Serializer;
import org.xml.sax.DocumentHandler;
public class XercesSerializer implements Serializer {
private static final Log LOG = LogFactory.getLog(XercesSerializer.class);
private Object _serializer;
public XercesSerializer() {
try {
this._serializer = Class.forName("org.apache.xml.serialize.XMLSerializer").newInstance();
} catch (Exception var2) {
throw new RuntimeException(Messages.format("conf.failedInstantiateSerializer", "org.apache.xml.serialize.XMLSerializer", var2));
}
}
public void setOutputCharStream(Writer out) {
try {
Method method = this._serializer.getClass().getMethod("setOutputCharStream", new Class[]{Writer.class});
method.invoke(this._serializer, new Object[]{out});
} catch (Exception var5) {
String msg = "Problem invoking XMLSerializer.setOutputCharStream()";
LOG.error(msg, var5);
throw new RuntimeException(msg + var5.getMessage());
}
}
public DocumentHandler asDocumentHandler() throws IOException {
try {
Method method = this._serializer.getClass().getMethod("asDocumentHandler", (Class[])null);
return (DocumentHandler)method.invoke(this._serializer, (Object[])null);
} catch (Exception var4) {
String msg = "Problem invoking XMLSerializer.asDocumentHandler()";
LOG.error(msg, var4);
throw new RuntimeException(msg + var4.getMessage());
}
}
public void setOutputFormat(OutputFormat format) {
try {
Class e = Class.forName("org.apache.xml.serialize.OutputFormat");
Method method = this._serializer.getClass().getMethod("setOutputFormat", new Class[]{e});
method.invoke(this._serializer, new Object[]{format.getFormat()});
} catch (Exception var5) {
String msg = "Problem invoking XMLSerializer.setOutputFormat()";
LOG.error(msg, var5);
throw new RuntimeException(msg + var5.getMessage());
}
}
public void setOutputByteStream(OutputStream output) {
try {
Method method = this._serializer.getClass().getMethod("setOutputByteStream", new Class[]{OutputStream.class});
method.invoke(this._serializer, new Object[]{output});
} catch (Exception var5) {
String msg = "Problem invoking XMLSerializer.setOutputByteStream()";
LOG.error(msg, var5);
throw new RuntimeException(msg + var5.getMessage());
}
}
}