From 9d17d36a3ee7fc310ee67ea42958d8b8e200bb5e Mon Sep 17 00:00:00 2001 From: Claus Nagel Date: Sun, 10 Dec 2023 21:25:58 +0100 Subject: [PATCH] minor change --- .../java/org/xmlobjects/stream/XMLOutput.java | 17 +++++++---------- .../xmlobjects/util/xml/SAXOutputHandler.java | 5 +++++ .../java/org/xmlobjects/util/xml/SAXWriter.java | 5 +++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/xmlobjects/stream/XMLOutput.java b/src/main/java/org/xmlobjects/stream/XMLOutput.java index a2329fc..c18e2b1 100644 --- a/src/main/java/org/xmlobjects/stream/XMLOutput.java +++ b/src/main/java/org/xmlobjects/stream/XMLOutput.java @@ -35,6 +35,8 @@ public abstract class XMLOutput> extends SAXFilter implem protected boolean writeXMLDeclaration = true; protected String[] headerComment; + protected abstract T self(); + public XMLOutput() { super(new DefaultHandler()); } @@ -57,11 +59,10 @@ String createPrefix(String namespaceURI) { return prefixMapping.createPrefix(namespaceURI); } - @SuppressWarnings("unchecked") public T withPrefix(String prefix, String namespaceURI) { prefixMapping.pushContext(); prefixMapping.declarePrefix(prefix, namespaceURI); - return (T) this; + return self(); } public String getNamespaceURI(String prefix) { @@ -76,46 +77,42 @@ public String getSchemaLocation(String namespaceURI) { return schemaLocations.get(namespaceURI); } - @SuppressWarnings("unchecked") public T withSchemaLocation(String namespaceURI, String schemaLocation) { if (namespaceURI != null && schemaLocation != null) { schemaLocations.put(namespaceURI, schemaLocation); withPrefix("xsi", XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); } - return (T) this; + return self(); } public String getIndent() { return indent; } - @SuppressWarnings("unchecked") public T withIndent(String indent) { this.indent = indent; - return (T) this; + return self(); } public boolean isWriteXMLDeclaration() { return writeXMLDeclaration; } - @SuppressWarnings("unchecked") public T writeXMLDeclaration(boolean writeXMLDeclaration) { this.writeXMLDeclaration = writeXMLDeclaration; - return (T) this; + return self(); } public String[] getHeaderComment() { return headerComment; } - @SuppressWarnings("unchecked") public T withHeaderComment(String... headerMessage) { if (headerMessage != null) { this.headerComment = headerMessage; } - return (T) this; + return self(); } } diff --git a/src/main/java/org/xmlobjects/util/xml/SAXOutputHandler.java b/src/main/java/org/xmlobjects/util/xml/SAXOutputHandler.java index 9882917..1c92e68 100644 --- a/src/main/java/org/xmlobjects/util/xml/SAXOutputHandler.java +++ b/src/main/java/org/xmlobjects/util/xml/SAXOutputHandler.java @@ -105,4 +105,9 @@ public void endElement(String uri, String localName, String qName) throws SAXExc prefixMapping.popContext(); } + + @Override + protected SAXOutputHandler self() { + return this; + } } diff --git a/src/main/java/org/xmlobjects/util/xml/SAXWriter.java b/src/main/java/org/xmlobjects/util/xml/SAXWriter.java index 190fd38..c5f868e 100644 --- a/src/main/java/org/xmlobjects/util/xml/SAXWriter.java +++ b/src/main/java/org/xmlobjects/util/xml/SAXWriter.java @@ -517,4 +517,9 @@ private void writeAttributeContent(String content) throws IOException { writer.write(content, pos, end - pos); } + + @Override + protected SAXWriter self() { + return this; + } }