| 335 | | MailboxNode mailbox; |
| 336 | | synchronized(rootMailboxLock) { |
| 337 | | mailbox = this.rootMailbox; |
| 338 | | } |
| 339 | | mailStore.requestFolderStatus(mailbox.getFolderTreeItem()); |
| | 343 | int size = pathMailboxMap.size(); |
| | 344 | FolderTreeItem[] folders = new FolderTreeItem[size]; |
| | 345 | Enumeration e = pathMailboxMap.keys(); |
| | 346 | for(int i=0; i<size; i++) { |
| | 347 | folders[i] = ((MailboxNode)pathMailboxMap.get(e.nextElement())).getFolderTreeItem(); |
| | 348 | } |
| | 349 | mailStore.requestFolderStatus(folders); |
| | 694 | |
| | 695 | /** |
| | 696 | * Saves the mailbox tree to persistent storage. |
| | 697 | */ |
| | 698 | private void save() { |
| | 699 | if(accountConfig == null) { |
| | 700 | return; |
| | 701 | } |
| | 702 | if(accountDataStore == null) { |
| | 703 | long accountId = accountConfig.getUniqueId(); |
| | 704 | accountDataStore = DataStoreFactory.getConnectionCacheStore(accountId); |
| | 705 | accountDataStore.load(); |
| | 706 | } |
| | 707 | |
| | 708 | accountDataStore.putNamedObject("ROOT_MAILBOX", rootMailbox); |
| | 709 | accountDataStore.save(); |
| | 710 | } |
| | 711 | |
| | 712 | /** |
| | 713 | * Loads the mailbox tree from persistent storage. |
| | 714 | */ |
| | 715 | private void load() { |
| | 716 | if(accountConfig == null) { |
| | 717 | return; |
| | 718 | } |
| | 719 | if(accountDataStore == null) { |
| | 720 | long accountId = accountConfig.getUniqueId(); |
| | 721 | accountDataStore = DataStoreFactory.getConnectionCacheStore(accountId); |
| | 722 | accountDataStore.load(); |
| | 723 | } |
| | 724 | |
| | 725 | Object loadedObject = accountDataStore.getNamedObject("ROOT_MAILBOX"); |
| | 726 | if(loadedObject instanceof MailboxNode) { |
| | 727 | synchronized(rootMailboxLock) { |
| | 728 | this.rootMailbox = (MailboxNode)loadedObject; |
| | 729 | this.rootMailbox.setParentAccount(this); |
| | 730 | prepareDeserializedMailboxNode(rootMailbox); |
| | 731 | } |
| | 732 | } |
| | 733 | } |
| | 734 | |
| | 735 | //TODO: Handle deleted account nodes |
| | 736 | |
| | 737 | /** |
| | 738 | * Traverses the deserialized mailbox nodes, populates any necessary |
| | 739 | * data structures in the account node, and sets the mailbox parent |
| | 740 | * account references. |
| | 741 | * |
| | 742 | * @param mailboxNode The mailbox node. |
| | 743 | */ |
| | 744 | private void prepareDeserializedMailboxNode(MailboxNode mailboxNode) { |
| | 745 | mailboxNode.setParentAccount(this); |
| | 746 | FolderTreeItem item = mailboxNode.getFolderTreeItem(); |
| | 747 | if(item != null && item.getPath().length() > 0) { |
| | 748 | this.pathMailboxMap.put(item.getPath(), mailboxNode); |
| | 749 | } |
| | 750 | MailboxNode[] children = mailboxNode.getMailboxes(); |
| | 751 | for(int i=0; i<children.length; i++) { |
| | 752 | prepareDeserializedMailboxNode(children[i]); |
| | 753 | } |
| | 754 | } |