geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r578497 - in /geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message: Message.java MessageSupport.java
Date Sat, 22 Sep 2007 20:58:09 GMT
Author: jdillon
Date: Sat Sep 22 13:58:09 2007
New Revision: 578497

URL: http://svn.apache.org/viewvc?rev=578497&view=rev
Log:
Add some extra muck to render some better default toString() for messages

Modified:
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
    geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java?rev=578497&r1=578496&r2=578497&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/Message.java
Sat Sep 22 13:58:09 2007
@@ -40,7 +40,7 @@
 
     void setCorrelationId(ID id);
 
-    MessageType getType() throws IOException;
+    MessageType getType();
 
     long getTimestamp();
 

Modified: geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java?rev=578497&r1=578496&r2=578497&view=diff
==============================================================================
--- geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
(original)
+++ geronimo/sandbox/gshell/trunk/gshell-remote/gshell-remote-common/src/main/java/org/apache/geronimo/gshell/remote/message/MessageSupport.java
Sat Sep 22 13:58:09 2007
@@ -63,8 +63,6 @@
         this.type = type;
 
         this.timestamp = System.currentTimeMillis();
-
-        // late init id and sequence
     }
 
     public int hashCode() {
@@ -75,18 +73,61 @@
     // TODO: Add equals()
     //
     
-    public String toString() {
-        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
+    protected static final class MessageToStringStyle
+        extends ToStringStyle
+    {
+        private static final long serialVersionUID = 1L;
+
+        public static final String[] EXCLUDED_FIELDS = {
+            "type",
+            "session",
+            "frozen"
+        };
+
+        MessageToStringStyle() {
+            this.setUseShortClassName(true);
+            this.setUseIdentityHashCode(false);
+        }
+
+        protected void appendClassName(StringBuffer buffer, Object object) {
+            if (object instanceof Message) {
+                Message msg = (Message) object;
+
+                buffer.append(msg.getType());
+            }
+            else {
+                super.appendClassName(buffer, object);
+            }
+        }
+
+        private Object readResolve() {
+            return MESSAGE_STYLE;
+        }
     }
 
+    private static final ToStringStyle MESSAGE_STYLE = new MessageToStringStyle();
+
     protected ToStringBuilder createToStringBuilder() {
-        return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
+        return new ToStringBuilder(this, MESSAGE_STYLE)
                 .append("id", getId())
                 .append("sequence", getSequence())
                 .append("timestamp", getTimestamp());
     }
 
-    public MessageType getType() throws IOException {
+    public String toString() {
+        //
+        // HACK: Make sure these init before we reflect
+        //
+        
+        getId();
+        getSequence();
+
+        return new ReflectionToStringBuilder(this, MESSAGE_STYLE)
+                .setExcludeFieldNames(MessageToStringStyle.EXCLUDED_FIELDS)
+                .toString();
+    }
+
+    public MessageType getType() {
         return type;
     }
 



Mime
View raw message