Do not constrain XmlDeserializer input to Document, use Node instead This gives users of the XmlDeserializer service more freedom as to where they get the XML state from.
Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/82f1dbc8 Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/82f1dbc8 Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/82f1dbc8 Branch: refs/heads/develop Commit: 82f1dbc8b9932257753d32abba489f2f728b9142 Parents: 14fe39c Author: Paul Merlin <[email protected]> Authored: Sun Apr 2 15:26:34 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Sun Apr 2 19:16:24 2017 +0200 ---------------------------------------------------------------------- .../spi/serialization/XmlDeserializer.java | 21 ++++++++++---------- .../spi/serialization/XmlSerializer.java | 2 +- .../javaxxml/JavaxXmlDeserializer.java | 3 +-- 3 files changed, 13 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/82f1dbc8/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlDeserializer.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlDeserializer.java b/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlDeserializer.java index f61e533..3d42828 100644 --- a/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlDeserializer.java +++ b/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlDeserializer.java @@ -33,57 +33,58 @@ import org.apache.polygene.spi.module.ModuleSpi; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import org.w3c.dom.Node; /** * {@literal javax.xml} deserializer. */ public interface XmlDeserializer extends Deserializer { - <T> T fromXml( ModuleDescriptor module, ValueType valueType, Document state ); + <T> T fromXml( ModuleDescriptor module, ValueType valueType, Node state ); - default <T> Function<Document, T> fromXmlFunction( ModuleDescriptor module, ValueType valueType ) + default <T> Function<Node, T> fromXmlFunction( ModuleDescriptor module, ValueType valueType ) { return state -> fromXml( module, valueType, state ); } - default <T> Stream<T> fromXmlEach( ModuleDescriptor module, ValueType valueType, Stream<Document> states ) + default <T> Stream<T> fromXmlEach( ModuleDescriptor module, ValueType valueType, Stream<Node> states ) { return states.map( fromXmlFunction( module, valueType ) ); } - default <T> Stream<T> fromXmlEach( ModuleDescriptor module, ValueType valueType, Iterable<Document> states ) + default <T> Stream<T> fromXmlEach( ModuleDescriptor module, ValueType valueType, Iterable<Node> states ) { return fromXmlEach( module, valueType, StreamSupport.stream( states.spliterator(), false ) ); } - default <T> Stream<T> fromXmlEach( ModuleDescriptor module, ValueType valueType, Document... states ) + default <T> Stream<T> fromXmlEach( ModuleDescriptor module, ValueType valueType, Node... states ) { return fromXmlEach( module, valueType, Stream.of( states ) ); } - default <T> T fromXml( ModuleDescriptor module, Class<T> type, Document state ) + default <T> T fromXml( ModuleDescriptor module, Class<T> type, Node state ) { // TODO Remove (ModuleSpi) cast ValueType valueType = ( (ModuleSpi) module.instance() ).valueTypeFactory().valueTypeOf( module, type ); return fromXml( module, valueType, state ); } - default <T> Function<Document, T> fromXml( ModuleDescriptor module, Class<T> type ) + default <T> Function<Node, T> fromXml( ModuleDescriptor module, Class<T> type ) { return state -> fromXml( module, type, state ); } - default <T> Stream<T> fromXmlEach( ModuleDescriptor module, Class<T> valueType, Stream<Document> states ) + default <T> Stream<T> fromXmlEach( ModuleDescriptor module, Class<T> valueType, Stream<Node> states ) { return states.map( fromXml( module, valueType ) ); } - default <T> Stream<T> fromXmlEach( ModuleDescriptor module, Class<T> valueType, Iterable<Document> states ) + default <T> Stream<T> fromXmlEach( ModuleDescriptor module, Class<T> valueType, Iterable<Node> states ) { return fromXmlEach( module, valueType, StreamSupport.stream( states.spliterator(), false ) ); } - default <T> Stream<T> fromXmlEach( ModuleDescriptor module, Class<T> valueType, Document... states ) + default <T> Stream<T> fromXmlEach( ModuleDescriptor module, Class<T> valueType, Node... states ) { return fromXmlEach( module, valueType, Stream.of( states ) ); } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/82f1dbc8/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlSerializer.java ---------------------------------------------------------------------- diff --git a/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlSerializer.java b/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlSerializer.java index afffe5f..6e1b7dc 100644 --- a/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlSerializer.java +++ b/core/spi/src/main/java/org/apache/polygene/spi/serialization/XmlSerializer.java @@ -96,7 +96,7 @@ public interface XmlSerializer extends Serializer } try { - // We want plain Strings to be serialized without quotes + // We want plain text nodes to be serialized without surrounding elements if( xmlDocument.getNodeType() == Node.TEXT_NODE ) { writer.write( xmlDocument.getNodeValue() ); http://git-wip-us.apache.org/repos/asf/polygene-java/blob/82f1dbc8/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java ---------------------------------------------------------------------- diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java index 8c6bc7b..5caed72 100644 --- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java +++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java @@ -53,7 +53,6 @@ import org.apache.polygene.api.value.ValueBuilder; import org.apache.polygene.api.value.ValueDescriptor; import org.apache.polygene.spi.serialization.AbstractTextDeserializer; import org.apache.polygene.spi.serialization.XmlDeserializer; -import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -77,7 +76,7 @@ public class JavaxXmlDeserializer extends AbstractTextDeserializer implements Xm private ServiceDescriptor descriptor; @Override - public <T> T fromXml( ModuleDescriptor module, ValueType valueType, Document state ) + public <T> T fromXml( ModuleDescriptor module, ValueType valueType, Node state ) { Optional<Element> stateElement = JavaxXml.firstChildElementNamed( state, getSettings().getRootTagName() ); if( stateElement.isPresent() )
