Remove XMLStreamNormalizedNodeStreamWriter.toString() 89/81189/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Mar 2019 14:10:16 +0000 (15:10 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 26 Mar 2019 14:39:10 +0000 (15:39 +0100)
This method is not used anywhere, forces us to have a dependency
on transformers and does not allow control over output augmentation.

It has been deprecated in 2.1.x release train, remove it now.

Change-Id: I07b048e16efba657045c4f0ce10376672f0ddece
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/XMLStreamNormalizedNodeStreamWriter.java

index aca9efc88070a33054ea0cc270486da7bc455aa0..905291b353f0c128c9da11c6d60fcb9e952b3732 100644 (file)
@@ -11,16 +11,10 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
 import java.io.IOException;
-import java.io.StringWriter;
 import java.util.Map;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -32,19 +26,16 @@ import org.opendaylight.yangtools.yang.data.impl.codec.SchemaTracker;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
 /**
  * A {@link NormalizedNodeStreamWriter} which translates the events into an {@link XMLStreamWriter},
  * resulting in a RFC 6020 XML encoding. There are 2 versions of this class, one that takes a
- * SchemaContext and encodes values appropriately according to the yang schema. The other is
+ * SchemaContext and encodes values appropriately according to the YANG schema. The other is
  * schema-less and merely outputs values using toString. The latter is intended for debugging
  * where doesn't have a SchemaContext available and isn't meant for production use.
  */
 public abstract class XMLStreamNormalizedNodeStreamWriter<T> implements NormalizedNodeStreamAttributeWriter {
-    private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance();
-
     private final @NonNull StreamWriterFacade facade;
 
     XMLStreamNormalizedNodeStreamWriter(final XMLStreamWriter writer) {
@@ -101,26 +92,6 @@ public abstract class XMLStreamNormalizedNodeStreamWriter<T> implements Normaliz
         return new SchemalessXMLStreamNormalizedNodeStreamWriter(writer);
     }
 
-    /**
-     * Utility method for formatting an {@link Element} to a string.
-     *
-     * @deprecated This method not used anywhere, users are advised to use their own formatting.
-     */
-    @Deprecated
-    public static String toString(final Element xml) {
-        try {
-            final Transformer transformer = TRANSFORMER_FACTORY.newTransformer();
-            transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-
-            final StreamResult result = new StreamResult(new StringWriter());
-            transformer.transform(new DOMSource(xml), result);
-
-            return result.getWriter().toString();
-        } catch (IllegalArgumentException | TransformerException e) {
-            throw new IllegalStateException("Unable to serialize xml element " + xml, e);
-        }
-    }
-
     abstract void startList(NodeIdentifier name);
 
     abstract void startListItem(PathArgument name) throws IOException;