commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject svn commit: r718767 - in /commons/proper/scxml/trunk/src: main/java/org/apache/commons/scxml/io/SCXMLSerializer.java test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
Date Tue, 18 Nov 2008 23:29:59 GMT
Author: rahul
Date: Tue Nov 18 15:29:59 2008
New Revision: 718767

URL: http://svn.apache.org/viewvc?rev=718767&view=rev
Log:
Improved serialization of <send>
Patch thanks to Ingmar Kliche <ingmar dot kliche at googlemail dot>
SCXML-83

Modified:
    commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
    commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java

Modified: commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java?rev=718767&r1=718766&r2=718767&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
(original)
+++ commons/proper/scxml/trunk/src/main/java/org/apache/commons/scxml/io/SCXMLSerializer.java
Tue Nov 18 15:29:59 2008
@@ -497,16 +497,31 @@
      */
     public static void serializeSend(final StringBuffer b,
             final Send send, final String indent) {
-        b.append(indent).append("<send sendid=\"")
-            .append(send.getSendid()).append("\" target=\"")
-            .append(send.getTarget()).append("\" targetType=\"")
-            .append(send.getTargettype()).append("\" namelist=\"")
-            .append(send.getNamelist()).append("\" delay=\"")
-            .append(send.getDelay()).append("\" event=\"")
-            .append(send.getEvent()).append("\" hints=\"")
-            .append(send.getHints()).append("\">\n")
-            .append(getBodyContent(send))
-            .append(indent).append("</send>\n");
+        b.append(indent).append("<send");
+        if (send.getSendid() != null) {
+            b.append(" sendid=\"").append(send.getSendid()).append("\"");
+        }
+        if (send.getTarget() != null) {
+            b.append(" target=\"").append(send.getTarget()).append("\"");
+        }
+        if (send.getTargettype() != null) {
+            b.append(" targetType=\"").append(send.getTargettype()).append("\"");
+        }
+        if (send.getNamelist() != null) {
+            b.append(" namelist=\"").append(send.getNamelist()).append("\"");
+        }
+        if (send.getDelay() != null) {
+            b.append(" delay=\"").append(send.getDelay()).append("\"");
+        }
+        if (send.getEvent() != null) {
+            b.append(" event=\"").append(send.getEvent()).append("\"");
+        }
+        if (send.getHints() != null) {
+            b.append(" hints=\"").append(send.getHints()).append("\"");
+        }
+        b.append(">\n");
+        b.append(getBodyContent(send));
+        b.append(indent).append("</send>\n");
     }
 
     /**

Modified: commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java?rev=718767&r1=718766&r2=718767&view=diff
==============================================================================
--- commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
(original)
+++ commons/proper/scxml/trunk/src/test/java/org/apache/commons/scxml/io/SCXMLSerializerTest.java
Tue Nov 18 15:29:59 2008
@@ -92,6 +92,19 @@
         assertEquals(assertValue.toString(), returnValue.toString());
     }
 
+    public void testSerializeSendEmptyAttributes() {
+        // test a <send event="foo"/>, i.e.most attributes are empty
+        Send send = new Send();
+        send.setEvent("foo");
+
+        String assertValue = " <send event=\"foo\">\n </send>\n";
+
+        StringBuffer returnValue = new StringBuffer();
+        SCXMLSerializer.serializeSend(returnValue, send, " ");
+
+        assertEquals(assertValue.toString(), returnValue.toString());
+    }
+
     public void testSerializeActionsListNull() {
         TransitionTarget target = new State();
         target.setId("1");



Mime
View raw message