I have a class that encapsulates StAX Writer for a special XML business record. You can click on some domain objects, and the logic generates adequate XML.
I do not want to offer an instance XMLStreamWriterfor security reasons, so this class is only responsible for the record of this author. XMLStreamWriterwill be installed in this class. To support almost all output changes, such as Result, OutputStream, and Writer, I also provide constructs for these changes.
public CustomStreamWriter ([...], Result result) {
this([...], (Object) result);
}
public CustomStreamWriter ([...], OutputStream outputStream) {
this([...], (Object) outputStream);
}
public CustomStreamWriter ([...], Writer writer) {
this([...], (Object) writer);
}
protected CustomStreamWriter ([...], Object outputHandler) {
XMLOutputFactory factory = XMLOutputFactory.newInstance();
if(outputHandler instanceof OutputStream) {
this.writer = factory.createXMLStreamWriter((OutputStream) outputHandler);
} else if(outputHandler instanceof Result) {
this.writer = factory.createXMLStreamWriter((Result) outputHandler);
} else if(outputHandler instanceof Writer) {
this.writer = factory.createXMLStreamWriter((Writer) outputHandler);
}
}
When I look at it, I think it is very ugly, not a neat way to achieve this. Stackoverflow, do you have any hints for me?