← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15551: minor fixes to serializers

 

------------------------------------------------------------
revno: 15551
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-04 13:18:05 +0200
message:
  minor fixes to serializers
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeDeserializer.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/JacksonJsonNodeSerializer.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeDeserializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeDeserializer.java	2014-06-01 11:39:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeDeserializer.java	2014-06-04 11:18:05 +0000
@@ -66,5 +66,5 @@
  */
 public interface NodeDeserializer
 {
-    RootNode render( InputStream inputStream ) throws IOException;
+    RootNode deserialize( InputStream inputStream ) throws IOException;
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/JacksonJsonNodeSerializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/JacksonJsonNodeSerializer.java	2014-06-04 10:49:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/JacksonJsonNodeSerializer.java	2014-06-04 11:18:05 +0000
@@ -73,11 +73,11 @@
     {
         JsonGenerator generator = objectMapper.getFactory().createGenerator( outputStream );
 
-        renderRootNode( rootNode, generator );
+        writeRootNode( rootNode, generator );
         generator.flush();
     }
 
-    private void renderRootNode( RootNode rootNode, JsonGenerator generator ) throws IOException
+    private void writeRootNode( RootNode rootNode, JsonGenerator generator ) throws IOException
     {
         generator.writeStartObject();
 
@@ -90,7 +90,7 @@
         generator.writeEndObject();
     }
 
-    private void renderSimpleNode( SimpleNode simpleNode, JsonGenerator generator, boolean writeKey ) throws IOException
+    private void writeSimpleNode( SimpleNode simpleNode, JsonGenerator generator, boolean writeKey ) throws IOException
     {
         if ( simpleNode.getValue() == null ) // add hint for this, exclude if null
         {
@@ -107,7 +107,7 @@
         }
     }
 
-    private void renderComplexNode( ComplexNode complexNode, JsonGenerator generator, boolean writeKey ) throws IOException
+    private void writeComplexNode( ComplexNode complexNode, JsonGenerator generator, boolean writeKey ) throws IOException
     {
         if ( writeKey )
         {
@@ -126,7 +126,7 @@
         generator.writeEndObject();
     }
 
-    private void renderCollectionNode( CollectionNode collectionNode, JsonGenerator generator, boolean writeKey ) throws IOException
+    private void writeCollectionNode( CollectionNode collectionNode, JsonGenerator generator, boolean writeKey ) throws IOException
     {
         if ( writeKey )
         {
@@ -150,13 +150,13 @@
         switch ( node.getType() )
         {
             case SIMPLE:
-                renderSimpleNode( (SimpleNode) node, generator, writeKey );
+                writeSimpleNode( (SimpleNode) node, generator, writeKey );
                 break;
             case COMPLEX:
-                renderComplexNode( (ComplexNode) node, generator, writeKey );
+                writeComplexNode( (ComplexNode) node, generator, writeKey );
                 break;
             case COLLECTION:
-                renderCollectionNode( (CollectionNode) node, generator, writeKey );
+                writeCollectionNode( (CollectionNode) node, generator, writeKey );
                 break;
         }
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java	2014-06-04 10:49:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java	2014-06-04 11:18:05 +0000
@@ -67,7 +67,7 @@
         try
         {
             writer = xmlFactory.createXMLStreamWriter( outputStream );
-            renderRootNode( rootNode, writer );
+            writeRootNode( rootNode, writer );
             writer.flush();
         }
         catch ( XMLStreamException e )
@@ -76,7 +76,7 @@
         }
     }
 
-    private void renderRootNode( RootNode rootNode, XMLStreamWriter writer ) throws IOException, XMLStreamException
+    private void writeRootNode( RootNode rootNode, XMLStreamWriter writer ) throws IOException, XMLStreamException
     {
         writer.writeStartDocument( "UTF-8", "1.0" );
 
@@ -97,40 +97,35 @@
         writer.writeEndDocument();
     }
 
-    private void renderSimpleNode( SimpleNode simpleNode, XMLStreamWriter writer ) throws XMLStreamException
-    {
-        if ( simpleNode.getValue() == null ) // add hint for this, exclude if null
-        {
-            return;
-        }
-
-        String value = String.format( "%s", simpleNode.getValue() );
-
-        writeStartElement( simpleNode, writer );
-        writer.writeCharacters( value );
-        writeEndElement( writer );
-    }
-
-    private void renderSimpleNodeAttribute( SimpleNode simpleNode, XMLStreamWriter writer ) throws XMLStreamException
-    {
-        if ( simpleNode.getValue() == null ) // add hint for this, exclude if null
-        {
-            return;
-        }
-
-        String value = String.format( "%s", simpleNode.getValue() );
-
-        if ( !StringUtils.isEmpty( simpleNode.getNamespace() ) )
-        {
-            writer.writeAttribute( "", simpleNode.getNamespace(), simpleNode.getName(), value );
+    private void writeSimpleNode( SimpleNode simpleNode, XMLStreamWriter writer ) throws XMLStreamException
+    {
+        if ( simpleNode.getValue() == null ) // TODO include null or not?
+        {
+            return;
+        }
+
+        String value = String.format( "%s", simpleNode.getValue() );
+
+        if ( simpleNode.isAttribute() )
+        {
+            if ( !StringUtils.isEmpty( simpleNode.getNamespace() ) )
+            {
+                writer.writeAttribute( "", simpleNode.getNamespace(), simpleNode.getName(), value );
+            }
+            else
+            {
+                writer.writeAttribute( simpleNode.getName(), value );
+            }
         }
         else
         {
-            writer.writeAttribute( simpleNode.getName(), value );
+            writeStartElement( simpleNode, writer );
+            writer.writeCharacters( value );
+            writeEndElement( writer );
         }
     }
 
-    private void renderComplexNode( ComplexNode complexNode, XMLStreamWriter writer ) throws XMLStreamException, IOException
+    private void writeComplexNode( ComplexNode complexNode, XMLStreamWriter writer ) throws XMLStreamException, IOException
     {
         writeStartElement( complexNode, writer );
 
@@ -142,9 +137,9 @@
         writeEndElement( writer );
     }
 
-    private void renderCollectionNode( CollectionNode collectionNode, XMLStreamWriter writer, boolean useWrapping ) throws XMLStreamException, IOException
+    private void writeCollectionNode( CollectionNode collectionNode, XMLStreamWriter writer ) throws XMLStreamException, IOException
     {
-        if ( useWrapping )
+        if ( collectionNode.isWrapping() )
         {
             writeStartElement( collectionNode, writer );
         }
@@ -154,7 +149,7 @@
             dispatcher( node, writer );
         }
 
-        if ( useWrapping )
+        if ( collectionNode.isWrapping() )
         {
             writeEndElement( writer );
         }
@@ -170,21 +165,13 @@
         switch ( node.getType() )
         {
             case SIMPLE:
-                if ( ((SimpleNode) node).isAttribute() )
-                {
-                    renderSimpleNodeAttribute( (SimpleNode) node, writer );
-                }
-                else
-                {
-                    renderSimpleNode( (SimpleNode) node, writer );
-                }
+                writeSimpleNode( (SimpleNode) node, writer );
                 break;
             case COMPLEX:
-                renderComplexNode( (ComplexNode) node, writer );
+                writeComplexNode( (ComplexNode) node, writer );
                 break;
             case COLLECTION:
-                boolean useWrapping = ((CollectionNode) node).isWrapping();
-                renderCollectionNode( (CollectionNode) node, writer, useWrapping );
+                writeCollectionNode( (CollectionNode) node, writer );
                 break;
         }
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java	2014-06-04 10:49:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/types/SimpleNode.java	2014-06-04 11:18:05 +0000
@@ -49,12 +49,6 @@
         this.attribute = false;
     }
 
-    public SimpleNode( String name, NodeType nodeType, Object value, boolean attribute )
-    {
-        super( name, nodeType );
-        this.value = value;
-    }
-
     public Object getValue()
     {
         return value;