diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-27 14:07:45 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-01-27 14:07:45 +0100 |
commit | 75ab63c8dea02c4e8148fb7e79730d163eb6647e (patch) | |
tree | b2557fc192f6faff27066fddb1b7692c9d06cc93 /document | |
parent | b6e493d2eba1e35bd07de4eb380299e2d21ec1bc (diff) |
Deprecate xml methods
Diffstat (limited to 'document')
30 files changed, 37 insertions, 433 deletions
diff --git a/document/abi-spec.json b/document/abi-spec.json index 1ab6c91dbf9..5f520f1a4d1 100644 --- a/document/abi-spec.json +++ b/document/abi-spec.json @@ -3138,54 +3138,6 @@ ], "fields" : [ ] }, - "com.yahoo.document.serialization.XmlDocumentWriter" : { - "superClass" : "java.lang.Object", - "interfaces" : [ - "com.yahoo.document.serialization.DocumentWriter" - ], - "attributes" : [ - "public", - "final" - ], - "methods" : [ - "public static com.yahoo.document.serialization.XmlDocumentWriter createWriter(java.lang.String)", - "public void <init>()", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.FieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.Document)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.Array)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.MapFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.ByteFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.BoolFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.CollectionFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.DoubleFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.FloatFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.IntegerFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.LongFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.Raw)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.PredicateFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.StringFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.TensorFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.ReferenceFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.Struct)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.StructuredFieldValue)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.datatypes.WeightedSet)", - "public void write(com.yahoo.vespa.objects.FieldBase, com.yahoo.document.annotation.AnnotationReference)", - "public com.yahoo.vespa.objects.Serializer putByte(com.yahoo.vespa.objects.FieldBase, byte)", - "public com.yahoo.vespa.objects.Serializer putShort(com.yahoo.vespa.objects.FieldBase, short)", - "public com.yahoo.vespa.objects.Serializer putInt(com.yahoo.vespa.objects.FieldBase, int)", - "public com.yahoo.vespa.objects.Serializer putLong(com.yahoo.vespa.objects.FieldBase, long)", - "public com.yahoo.vespa.objects.Serializer putFloat(com.yahoo.vespa.objects.FieldBase, float)", - "public com.yahoo.vespa.objects.Serializer putDouble(com.yahoo.vespa.objects.FieldBase, double)", - "public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase, byte[])", - "public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase, java.nio.ByteBuffer)", - "public com.yahoo.vespa.objects.Serializer put(com.yahoo.vespa.objects.FieldBase, java.lang.String)", - "public void write(com.yahoo.document.Document)", - "public void write(com.yahoo.document.DocumentId)", - "public void write(com.yahoo.document.DocumentType)", - "public java.lang.String lastRendered()" - ], - "fields" : [ ] - }, "com.yahoo.document.serialization.XmlSerializationHelper" : { "superClass" : "java.lang.Object", "interfaces" : [ ], diff --git a/document/src/main/java/com/yahoo/document/Document.java b/document/src/main/java/com/yahoo/document/Document.java index 3dc628e0a90..ac789bc681d 100644 --- a/document/src/main/java/com/yahoo/document/Document.java +++ b/document/src/main/java/com/yahoo/document/Document.java @@ -204,6 +204,7 @@ public class Document extends StructuredFieldValue { return "document '" + docId + "' of type '" + getDataType().getName() + "'"; } + @Deprecated public String toXML(String indent) { XmlStream xml = new XmlStream(); xml.setIndent(indent); @@ -218,10 +219,12 @@ public class Document extends StructuredFieldValue { * within a <document></document> tag. * @return XML representation of document */ + @Deprecated public String toXml() { return toXML(" "); } + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printDocumentXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/PositionDataType.java b/document/src/main/java/com/yahoo/document/PositionDataType.java index d4160fc58c7..c442145a74e 100644 --- a/document/src/main/java/com/yahoo/document/PositionDataType.java +++ b/document/src/main/java/com/yahoo/document/PositionDataType.java @@ -53,6 +53,7 @@ public final class PositionDataType { return buf.toString(); } + @Deprecated public static void renderXml(Struct pos, XmlStream target) { target.addContent(renderAsString(pos)); } diff --git a/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java b/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java index cb8a7a6dd0a..924f401f8be 100644 --- a/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java +++ b/document/src/main/java/com/yahoo/document/annotation/AnnotationReference.java @@ -122,6 +122,7 @@ public class AnnotationReference extends FieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { // TODO: Implement AnnotationReference.printXml() } diff --git a/document/src/main/java/com/yahoo/document/datatypes/Array.java b/document/src/main/java/com/yahoo/document/datatypes/Array.java index dba1c0783cf..f1d1255916c 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Array.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Array.java @@ -112,6 +112,7 @@ public final class Array<T extends FieldValue> extends CollectionFieldValue<T> i } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printArrayXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/BoolFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/BoolFieldValue.java index 962ed6b1817..199ca199667 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/BoolFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/BoolFieldValue.java @@ -76,6 +76,7 @@ public class BoolFieldValue extends FieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printBoolXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/ByteFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/ByteFieldValue.java index bf010b4715d..ec455f90f06 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/ByteFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/ByteFieldValue.java @@ -93,6 +93,7 @@ public class ByteFieldValue extends NumericFieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printByteXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/DoubleFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/DoubleFieldValue.java index 55dfff2a954..2fbf1808a75 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/DoubleFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/DoubleFieldValue.java @@ -88,6 +88,7 @@ public final class DoubleFieldValue extends NumericFieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printDoubleXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/FieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/FieldValue.java index 493dd964b9e..d43fed19005 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/FieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/FieldValue.java @@ -37,6 +37,7 @@ public abstract class FieldValue extends Identifiable implements Comparable<Fiel * * @return XML representation of field in a <value> element */ + @Deprecated public String toXml() { XmlStream xml = new XmlStream(); xml.setIndent(" "); @@ -58,6 +59,7 @@ public abstract class FieldValue extends Identifiable implements Comparable<Fiel serialize(DocumentSerializerFactory.create6(buf)); } + @Deprecated public abstract void printXml(XmlStream xml); public abstract void clear(); diff --git a/document/src/main/java/com/yahoo/document/datatypes/Float16FieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/Float16FieldValue.java index f9cf7419e01..06ec0d692ce 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Float16FieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Float16FieldValue.java @@ -86,6 +86,7 @@ public final class Float16FieldValue extends NumericFieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printShortfloatXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/FloatFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/FloatFieldValue.java index 5fa850f69a3..ffc13dc42e8 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/FloatFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/FloatFieldValue.java @@ -88,6 +88,7 @@ public final class FloatFieldValue extends NumericFieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printFloatXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/IntegerFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/IntegerFieldValue.java index c02122525b1..d2c20abbb9d 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/IntegerFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/IntegerFieldValue.java @@ -85,6 +85,7 @@ public final class IntegerFieldValue extends NumericFieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printIntegerXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/LongFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/LongFieldValue.java index da6b91e4071..0dedfa72fc4 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/LongFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/LongFieldValue.java @@ -89,6 +89,7 @@ public final class LongFieldValue extends NumericFieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printLongXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java index a82639cae0c..01cd092bf57 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/MapFieldValue.java @@ -98,6 +98,7 @@ public class MapFieldValue<K extends FieldValue, V extends FieldValue> extends C } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printMapXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/PredicateFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/PredicateFieldValue.java index aba5e51f723..dc62a5f413d 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/PredicateFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/PredicateFieldValue.java @@ -45,6 +45,7 @@ public class PredicateFieldValue extends FieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { if (predicate == null) { return; diff --git a/document/src/main/java/com/yahoo/document/datatypes/Raw.java b/document/src/main/java/com/yahoo/document/datatypes/Raw.java index f6efc626f06..adae64f3874 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Raw.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Raw.java @@ -100,6 +100,7 @@ public final class Raw extends FieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printRawXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java index ebc39b14eb1..75ae0164b65 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/ReferenceFieldValue.java @@ -88,6 +88,7 @@ public class ReferenceFieldValue extends FieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { } @Override diff --git a/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java index 6133c9ca0ad..6e999bb4041 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/StringFieldValue.java @@ -218,6 +218,7 @@ public class StringFieldValue extends FieldValue { * @param xml the stream to print to */ @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printStringXml(this, xml); //TODO: add spanTree printing diff --git a/document/src/main/java/com/yahoo/document/datatypes/Struct.java b/document/src/main/java/com/yahoo/document/datatypes/Struct.java index d522e8cda44..11d5db06819 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/Struct.java +++ b/document/src/main/java/com/yahoo/document/datatypes/Struct.java @@ -92,6 +92,7 @@ public class Struct extends StructuredFieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { if (getDataType().equals(PositionDataType.INSTANCE)) { try { diff --git a/document/src/main/java/com/yahoo/document/datatypes/TensorFieldValue.java b/document/src/main/java/com/yahoo/document/datatypes/TensorFieldValue.java index 105739da508..2dab9e97246 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/TensorFieldValue.java +++ b/document/src/main/java/com/yahoo/document/datatypes/TensorFieldValue.java @@ -88,6 +88,7 @@ public class TensorFieldValue extends FieldValue { } @Override + @Deprecated public void printXml(XmlStream xml) { // TODO (geirst) } diff --git a/document/src/main/java/com/yahoo/document/datatypes/WeightedSet.java b/document/src/main/java/com/yahoo/document/datatypes/WeightedSet.java index 583c68d631b..08c151b2d51 100644 --- a/document/src/main/java/com/yahoo/document/datatypes/WeightedSet.java +++ b/document/src/main/java/com/yahoo/document/datatypes/WeightedSet.java @@ -91,6 +91,7 @@ public final class WeightedSet<K extends FieldValue> extends CollectionFieldValu @Override + @Deprecated public void printXml(XmlStream xml) { XmlSerializationHelper.printWeightedSetXml(this, xml); } diff --git a/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java b/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java deleted file mode 100644 index aeb4bbe79b1..00000000000 --- a/document/src/main/java/com/yahoo/document/serialization/XmlDocumentWriter.java +++ /dev/null @@ -1,339 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.serialization; - -import com.yahoo.document.Document; -import com.yahoo.document.DocumentId; -import com.yahoo.document.DocumentType; -import com.yahoo.document.Field; -import com.yahoo.document.annotation.AnnotationReference; -import com.yahoo.document.datatypes.Array; -import com.yahoo.document.datatypes.BoolFieldValue; -import com.yahoo.document.datatypes.ByteFieldValue; -import com.yahoo.document.datatypes.CollectionFieldValue; -import com.yahoo.document.datatypes.DoubleFieldValue; -import com.yahoo.document.datatypes.FieldValue; -import com.yahoo.document.datatypes.FloatFieldValue; -import com.yahoo.document.datatypes.IntegerFieldValue; -import com.yahoo.document.datatypes.LongFieldValue; -import com.yahoo.document.datatypes.MapFieldValue; -import com.yahoo.document.datatypes.PredicateFieldValue; -import com.yahoo.document.datatypes.Raw; -import com.yahoo.document.datatypes.ReferenceFieldValue; -import com.yahoo.document.datatypes.StringFieldValue; -import com.yahoo.document.datatypes.Struct; -import com.yahoo.document.datatypes.StructuredFieldValue; -import com.yahoo.document.datatypes.TensorFieldValue; -import com.yahoo.document.datatypes.WeightedSet; -import com.yahoo.vespa.objects.FieldBase; -import com.yahoo.vespa.objects.Serializer; - -import java.nio.ByteBuffer; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Iterator; -import java.util.Map; - -// TODO: Just inline all use of XmlSerializationHelper when the toXml methods in FieldValue subclasses are to be removed -// TODO: More cleanup, the put() methods generate a lot of superfluous objects (write should call put, not the other way around) -// TODO: remove pingpong between XmlSerializationHelper and FieldValue, this will go away when the toXml methods go away -/** - * Render a Document instance as XML. - * - * @author Steinar Knutsen - */ -public final class XmlDocumentWriter implements DocumentWriter { - - private final String indent; - private XmlStream buffer; - private final Deque<FieldBase> optionalWrapperMarker = new ArrayDeque<>(); - - public static XmlDocumentWriter createWriter(String indent) { - return new XmlDocumentWriter(indent); - } - - public XmlDocumentWriter() { - this(" "); - } - - private XmlDocumentWriter(String indent) { - this.indent = indent; - } - - // this method is silly, what is the intended way of doing this? - @Override - public void write(FieldBase field, FieldValue value) { - Class<?> valueType = value.getClass(); - if (valueType == AnnotationReference.class) { - write(field, (AnnotationReference) value); - } else if (valueType == Array.class) { - write(field, (Array<?>) value); - } else if (valueType == WeightedSet.class) { - write(field, (WeightedSet<?>) value); - } else if (valueType == Document.class) { - write(field, (Document) value); - } else if (valueType == Struct.class) { - write(field, (Struct) value); - } else if (valueType == ByteFieldValue.class) { - write(field, (ByteFieldValue) value); - } else if (valueType == DoubleFieldValue.class) { - write(field, (DoubleFieldValue) value); - } else if (valueType == FloatFieldValue.class) { - write(field, (FloatFieldValue) value); - } else if (valueType == IntegerFieldValue.class) { - write(field, (IntegerFieldValue) value); - } else if (valueType == LongFieldValue.class) { - write(field, (LongFieldValue) value); - } else if (valueType == Raw.class) { - write(field, (Raw) value); - } else if (valueType == PredicateFieldValue.class) { - write(field, (PredicateFieldValue) value); - } else if (valueType == StringFieldValue.class) { - write(field, (StringFieldValue) value); - } else { - throw new UnsupportedOperationException("Cannot serialize a " - + valueType.getName()); - } - } - - @Override - public void write(FieldBase field, Document value) { - buffer.beginTag("document"); - buffer.addAttribute("documenttype", value.getDataType().getName()); - buffer.addAttribute("documentid", value.getId()); - final java.lang.Long lastModified = value.getLastModified(); - if (lastModified != null) { - buffer.addAttribute("lastmodifiedtime", lastModified); - } - StructuredFieldValue asStructured = value; - write(null, asStructured); - - buffer.endTag(); - } - - @Override - public <T extends FieldValue> void write(FieldBase field, Array<T> value) { - buffer.beginTag(field.getName()); - XmlSerializationHelper.printArrayXml(value, buffer); - buffer.endTag(); - } - - private void singleValueTag(FieldBase field, FieldValue value) { - buffer.beginTag(field.getName()); - value.printXml(buffer); - buffer.endTag(); - } - - @Override - public <K extends FieldValue, V extends FieldValue> void write(FieldBase field, MapFieldValue<K, V> map) { - // TODO Auto-generated method stub - buffer.beginTag(field.getName()); - XmlSerializationHelper.printMapXml(map, buffer); - buffer.endTag(); - } - - @Override - public void write(FieldBase field, ByteFieldValue value) { - singleValueTag(field, value); - } - - @Override - public void write(FieldBase field, BoolFieldValue value) { - singleValueTag(field, value); - } - - @Override - public <T extends FieldValue> void write(FieldBase field, - CollectionFieldValue<T> value) { - buffer.beginTag(field.getName()); - for (@SuppressWarnings("unchecked") - Iterator<FieldValue> i = (Iterator<FieldValue>) value.iterator(); - i.hasNext();) { - buffer.beginTag("item"); - i.next().printXml(buffer); - buffer.endTag(); - } - buffer.endTag(); - } - - @Override - public void write(FieldBase field, DoubleFieldValue value) { - singleValueTag(field, value); - } - - @Override - public void write(FieldBase field, FloatFieldValue value) { - singleValueTag(field, value); - } - - @Override - public void write(FieldBase field, IntegerFieldValue value) { - singleValueTag(field, value); - } - - @Override - public void write(FieldBase field, LongFieldValue value) { - singleValueTag(field, value); - } - - @Override - public void write(FieldBase field, Raw value) { - buffer.beginTag(field.getName()); - XmlSerializationHelper.printRawXml(value, buffer); - buffer.endTag(); - } - - @Override - public void write(FieldBase field, PredicateFieldValue value) { - singleValueTag(field, value); - } - - @Override - public void write(FieldBase field, StringFieldValue value) { - buffer.beginTag(field.getName()); - XmlSerializationHelper.printStringXml(value, buffer); - buffer.endTag(); - } - - @Override - public void write(FieldBase field, TensorFieldValue value) { - throw new IllegalArgumentException("write() for tensor field value not implemented yet"); - } - - @Override - public void write(FieldBase field, ReferenceFieldValue value) { - throw new IllegalArgumentException("write() for reference field value not implemented yet"); - } - - private void optionalWrapperStart(FieldBase field) { - if (field == null) { - return; - } - - optionalWrapperMarker.addFirst(field); - - buffer.beginTag(field.getName()); - } - - private void optionalWrapperEnd(FieldBase field) { - if (field == null) { - return; - } - - if (optionalWrapperMarker.removeFirst() != field) { - throw new IllegalStateException("Unbalanced optional wrapper tags."); - } - - buffer.endTag(); - } - - @Override - public void write(FieldBase field, Struct value) { - StructuredFieldValue asStructured = value; - write(field, asStructured); - } - - @Override - public void write(FieldBase field, StructuredFieldValue value) { - optionalWrapperStart(field); - Iterator<Map.Entry<Field, FieldValue>> i = value.iterator(); - while (i.hasNext()) { - Map.Entry<Field, FieldValue> v = i.next(); - buffer.beginTag(v.getKey().getName()); - v.getValue().printXml(buffer); - buffer.endTag(); - } - optionalWrapperEnd(field); - } - - @Override - public <T extends FieldValue> void write(FieldBase field, - WeightedSet<T> value) { - buffer.beginTag(field.getName()); - XmlSerializationHelper.printWeightedSetXml(value, buffer); - buffer.endTag(); - } - - @Override - public void write(FieldBase field, AnnotationReference value) { - // TODO Auto-generated method stub - - } - - @Override - public Serializer putByte(FieldBase field, byte value) { - singleValueTag(field, new ByteFieldValue(value)); - return this; - } - - @Override - public Serializer putShort(FieldBase field, short value) { - singleValueTag(field, new IntegerFieldValue(value)); - return this; - } - - @Override - public Serializer putInt(FieldBase field, int value) { - singleValueTag(field, new IntegerFieldValue(value)); - return this; - } - - @Override - public Serializer putLong(FieldBase field, long value) { - singleValueTag(field, new LongFieldValue(value)); - return this; - } - - @Override - public Serializer putFloat(FieldBase field, float value) { - singleValueTag(field, new FloatFieldValue(value)); - return this; - } - - @Override - public Serializer putDouble(FieldBase field, double value) { - singleValueTag(field, new DoubleFieldValue(value)); - return this; - } - - @Override - public Serializer put(FieldBase field, byte[] value) { - write(field, new Raw(value)); - return this; - } - - @Override - public Serializer put(FieldBase field, ByteBuffer value) { - write(field, new Raw(value)); - return this; - } - - @Override - public Serializer put(FieldBase field, String value) { - write(field, new StringFieldValue(value)); - return this; - } - - @Override - public void write(Document document) { - buffer = new XmlStream(); - buffer.setIndent(indent); - optionalWrapperMarker.clear(); - write(new Field(document.getDataType().getName(), 0, document.getDataType()), document); - } - - @Override - public void write(DocumentId id) { - throw new UnsupportedOperationException("Writing a DocumentId as XML is not implemented."); - } - - @Override - public void write(DocumentType type) { - throw new UnsupportedOperationException("Writing a DocumentId as XML is not implemented."); - - } - - public String lastRendered() { - return buffer.toString(); - } - -} diff --git a/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java b/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java index 899ef1f9195..9c1df0cd6c7 100644 --- a/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java +++ b/document/src/main/java/com/yahoo/document/serialization/XmlSerializationHelper.java @@ -30,6 +30,8 @@ import java.util.Map; * * @author <a href="mailto:humbe@yahoo-inc.com">Håkon Humberset</a> */ +@Deprecated +@SuppressWarnings("removal") public class XmlSerializationHelper { public static void printArrayXml(Array array, XmlStream xml) { diff --git a/document/src/main/java/com/yahoo/document/serialization/XmlStream.java b/document/src/main/java/com/yahoo/document/serialization/XmlStream.java index 40ded73b5aa..b9e29d03f7f 100644 --- a/document/src/main/java/com/yahoo/document/serialization/XmlStream.java +++ b/document/src/main/java/com/yahoo/document/serialization/XmlStream.java @@ -27,6 +27,7 @@ import java.util.ListIterator; * * @author <a href="humbe@yahoo-inc.com">Haakon Humberset</a> */ +@Deprecated public class XmlStream { // Utility class to hold attributes internally until it's time to write them diff --git a/document/src/test/java/com/yahoo/document/DocumentTestCase.java b/document/src/test/java/com/yahoo/document/DocumentTestCase.java index f1c74ad6efc..33b77cb1878 100644 --- a/document/src/test/java/com/yahoo/document/DocumentTestCase.java +++ b/document/src/test/java/com/yahoo/document/DocumentTestCase.java @@ -20,7 +20,6 @@ import com.yahoo.document.datatypes.WeightedSet; import com.yahoo.document.serialization.DocumentDeserializerFactory; import com.yahoo.document.serialization.DocumentReader; import com.yahoo.document.serialization.DocumentSerializerFactory; -import com.yahoo.document.serialization.XmlDocumentWriter; import com.yahoo.io.GrowableByteBuffer; import com.yahoo.vespa.objects.BufferSerializer; import org.junit.Test; @@ -920,6 +919,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testToXml() { setUpSertestDocType(); Document doc = getSertestDocument(); @@ -935,19 +935,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { } @Test - public void testXmlSerializer() { - setUpSertestDocType(); - Document doc = getSertestDocument(); - doc.setFieldValue("mailid", "emailfromalicetobob&someone"); - doc.setFieldValue("myposfield", PositionDataType.valueOf(-122057174, 37374821)); - String xml = doc.toXML(" "); - XmlDocumentWriter w = XmlDocumentWriter.createWriter(" "); - w.write(doc); - String otherXml = doc.toXML(" "); - assertEquals(xml, otherXml); - } - - @Test + @SuppressWarnings("deprecation") public void testSingleFieldToXml() { Document doc = new Document(docMan.getDocumentType("testdoc"), new DocumentId("id:ns:testdoc::xmltest")); doc.setFieldValue("stringattr", new StringFieldValue("hello world")); @@ -955,6 +943,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testDelegatedDocumentToXml() { Document doc = new Document(docMan.getDocumentType("testdoc"), new DocumentId("id:ns:testdoc::xmltest")); doc.setFieldValue("stringattr", new StringFieldValue("hello universe")); @@ -1159,6 +1148,7 @@ public class DocumentTestCase extends DocumentTestCaseBase { } @Test + @SuppressWarnings("deprecation") public void testDocumentComparisonDoesNotCorruptStateBug6394548() { DocumentTypeManager docMan = new DocumentTypeManager(); DocumentType docType = new DocumentType("bug2354045"); diff --git a/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java b/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java index 3ec858062be..424fd0018c8 100644 --- a/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java +++ b/document/src/test/java/com/yahoo/document/annotation/Bug6394548TestCase.java @@ -17,6 +17,7 @@ import static org.junit.Assert.*; public class Bug6394548TestCase { @Test + @SuppressWarnings("deprecation") public void testSerializeAndDeserializeMultipleAdjacentStructAnnotations() { DocumentTypeManager manager = new DocumentTypeManager(); var sub = DocumentTypeManagerConfigurer.configure @@ -65,6 +66,7 @@ public class Bug6394548TestCase { assertEquals(annotationsBefore, annotationsAfter); } + @SuppressWarnings("deprecation") private String dumpAllAnnotations(SpanTree tree) { ArrayList<String> tmp = new ArrayList<>(); for (Annotation anno : tree) { diff --git a/document/src/test/java/com/yahoo/document/datatypes/PredicateFieldValueTest.java b/document/src/test/java/com/yahoo/document/datatypes/PredicateFieldValueTest.java index 95bdf8f4bc4..c77ad8493c9 100644 --- a/document/src/test/java/com/yahoo/document/datatypes/PredicateFieldValueTest.java +++ b/document/src/test/java/com/yahoo/document/datatypes/PredicateFieldValueTest.java @@ -53,6 +53,7 @@ public class PredicateFieldValueTest { } @Test + @SuppressWarnings("deprecation") public void requireThatXmlOutputIsEmptyForNullPredicate() { XmlStream expected = new XmlStream(); expected.beginTag("tag"); @@ -61,6 +62,7 @@ public class PredicateFieldValueTest { } @Test + @SuppressWarnings("deprecation") public void requireThatXmlOutputIsPredicateLanguage() { Predicate predicate = new FeatureSet("key", "valueA", "valueB"); XmlStream expected = new XmlStream(); @@ -181,6 +183,7 @@ public class PredicateFieldValueTest { assertTrue(lhs.equals(rhs)); } + @SuppressWarnings("deprecation") private static String printXml(String tag, FieldValue value) { XmlStream out = new XmlStream(); out.beginTag(tag); diff --git a/document/src/test/java/com/yahoo/document/datatypes/StructTestCase.java b/document/src/test/java/com/yahoo/document/datatypes/StructTestCase.java index ea066ff4ffd..06875b8ca3c 100644 --- a/document/src/test/java/com/yahoo/document/datatypes/StructTestCase.java +++ b/document/src/test/java/com/yahoo/document/datatypes/StructTestCase.java @@ -248,6 +248,7 @@ public class StructTestCase { } @Test + @SuppressWarnings("deprecation") public void testCompareToDoesNotMutateStateBug6394548() { StructDataType type = new StructDataType("test"); // NOTE: non-increasing ID order! diff --git a/document/src/test/java/com/yahoo/document/serialization/XmlDocumentWriterTestCase.java b/document/src/test/java/com/yahoo/document/serialization/XmlDocumentWriterTestCase.java deleted file mode 100644 index b291d3e784d..00000000000 --- a/document/src/test/java/com/yahoo/document/serialization/XmlDocumentWriterTestCase.java +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.document.serialization; - -import com.yahoo.document.DataType; -import com.yahoo.document.Document; -import com.yahoo.document.DocumentType; -import com.yahoo.document.Field; -import com.yahoo.document.datatypes.PredicateFieldValue; -import org.junit.Test; -import org.mockito.Mockito; - -/** - * @author Simon Thoresen Hult - */ -public class XmlDocumentWriterTestCase { - - @Test - public void requireThatPredicateFieldValuesAreSerializedAsString() { - DocumentType docType = new DocumentType("my_type"); - Field field = new Field("my_predicate", DataType.PREDICATE); - docType.addField(field); - Document doc = new Document(docType, "id:ns:my_type::"); - PredicateFieldValue predicate = Mockito.mock(PredicateFieldValue.class); - doc.setFieldValue("my_predicate", predicate); - - new XmlDocumentWriter().write(doc); - Mockito.verify(predicate, Mockito.times(1)).printXml(Mockito.any(XmlStream.class)); - } -} diff --git a/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java b/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java index afe08aeb2d6..4a66b562f35 100644 --- a/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java +++ b/document/src/test/java/com/yahoo/document/serialization/XmlStreamTestCase.java @@ -1,11 +1,8 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.document.serialization; -import com.yahoo.document.serialization.XmlStream; import org.junit.Test; -import java.io.IOException; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -14,6 +11,7 @@ import static org.junit.Assert.assertTrue; * * @author HÃ¥kon Humberset */ +@Deprecated public class XmlStreamTestCase { /** A catch all test checking that regular usage looks good. */ |