- Timestamp:
- 08/01/08 10:18:16 PM (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/model/MailboxNode.java
r256 r259 31 31 package org.logicprobe.LogicMail.model; 32 32 33 import java.io.DataInputStream; 34 import java.io.DataOutputStream; 35 import java.io.IOException; 33 36 import java.util.Hashtable; 34 37 import java.util.Vector; … … 37 40 import org.logicprobe.LogicMail.mail.FolderTreeItem; 38 41 import org.logicprobe.LogicMail.util.EventListenerList; 42 import org.logicprobe.LogicMail.util.Serializable; 43 import org.logicprobe.LogicMail.util.UniqueIdGenerator; 39 44 40 45 /** … … 43 48 * <tt>MessageNode</tt> instances as its children. 44 49 */ 45 public class MailboxNode implements Node { 50 public class MailboxNode implements Node, Serializable { 51 private long uniqueId; 46 52 private AccountNode parentAccount; 47 53 private MailboxNode parentMailbox; … … 59 65 public final static int TYPE_TRASH = 4; 60 66 67 /** 68 * Initializes a new instance of <tt>MailboxNode</tt>. 69 * 70 * @param folderTreeItem The folder item this node wraps. 71 * @param type The type of mailbox this is representing. 72 */ 61 73 MailboxNode(FolderTreeItem folderTreeItem, int type) { 74 this.uniqueId = UniqueIdGenerator.getInstance().getUniqueId(); 62 75 this.mailboxes = new Vector(); 63 76 this.messages = new Vector(); 64 77 this.messageMap = new Hashtable(); 65 this.folderTreeItem = folderTreeItem; 78 if(folderTreeItem != null) { 79 this.setFolderTreeItem(new FolderTreeItem(folderTreeItem)); 80 } 66 81 this.type = type; 67 82 } 68 83 84 /** 85 * Initializes a new instance of <tt>MailboxNode</tt>. 86 * 87 * @param folderTreeItem The folder item this node wraps. 88 */ 69 89 MailboxNode(FolderTreeItem folderTreeItem) { 70 90 this(folderTreeItem, TYPE_NORMAL); 71 91 } 72 92 73 MailboxNode() { 93 /** 94 * Initializes a new instance of <tt>MailboxNode</tt>. 95 * 96 * <p><i>Note:</i> This constructor is only exposed for 97 * serialization purposes, and should never be called from 98 * outside this package for any other reason. 99 */ 100 public MailboxNode() { 74 101 this(null, TYPE_NORMAL); 75 102 } … … 121 148 * that maintain cache data for it. 122 149 * 150 * <p><i>Note:</i> The actual <tt>FolderTreeItem</tt> used by this 151 * class is a deep copy of the one passed to this method. It is 152 * implemented this way since we need a standalone object that 153 * is not part of a tree. This is necessary to avoid excessive 154 * recursion during serialization. 155 * 123 156 * @param folderTreeItem Folder tree item. 124 157 */ 125 158 void setFolderTreeItem(FolderTreeItem folderTreeItem) { 126 this.folderTreeItem = folderTreeItem;159 this.folderTreeItem = new FolderTreeItem(folderTreeItem); 127 160 } 128 161 … … 452 485 } 453 486 } 487 488 public long getUniqueId() { 489 return uniqueId; 490 } 491 492 public void serialize(DataOutputStream output) throws IOException { 493 output.writeLong(uniqueId); 494 output.writeInt(type); 495 folderTreeItem.serialize(output); 496 synchronized(mailboxes) { 497 int size = mailboxes.size(); 498 output.writeInt(size); 499 for(int i=0; i<size; i++) { 500 ((MailboxNode)mailboxes.elementAt(i)).serialize(output); 501 } 502 } 503 } 504 505 public void deserialize(DataInputStream input) throws IOException { 506 uniqueId = input.readLong(); 507 type = input.readInt(); 508 folderTreeItem = new FolderTreeItem(); 509 folderTreeItem.deserialize(input); 510 synchronized(mailboxes) { 511 int size = input.readInt(); 512 for(int i=0; i<size; i++) { 513 MailboxNode child = new MailboxNode(); 514 child.deserialize(input); 515 child.parentMailbox = this; 516 mailboxes.addElement(child); 517 } 518 } 519 } 454 520 }
