Skip to content

Package: StoreTreeNode

StoreTreeNode

nameinstructionbranchcomplexitylinemethod
StoreTreeNode(Store)
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getChildCount()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isLeaf()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
loadChildren()
M: 42 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
toString()
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 8 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Distribution License v. 1.0, which is available at
6: * http://www.eclipse.org/org/documents/edl-v10.php.
7: *
8: * SPDX-License-Identifier: BSD-3-Clause
9: */
10:
11: package example.client;
12:
13: import jakarta.mail.Folder;
14: import jakarta.mail.MessagingException;
15: import jakarta.mail.Store;
16: import jakarta.mail.URLName;
17:
18: import javax.swing.tree.DefaultMutableTreeNode;
19:
20: /**
21: * Node which represents a Store in the jakarta.mail apis.
22: *
23: * @author Christopher Cotton
24: */
25: public class StoreTreeNode extends DefaultMutableTreeNode {
26:
27: protected Store store = null;
28: protected Folder folder = null;
29: protected String display = null;
30:
31: /**
32: * creates a tree node that points to the particular Store.
33: *
34: * @param what the store for this node
35: */
36: public StoreTreeNode(Store what) {
37: super(what);
38: store = what;
39: }
40:
41:
42: /**
43: * a Store is never a leaf node. It can always contain stuff
44: */
45: public boolean isLeaf() {
46: return false;
47: }
48:
49:
50: /**
51: * return the number of children for this store node. The first
52: * time this method is called we load up all of the folders
53: * under the store's defaultFolder
54: */
55:
56: public int getChildCount() {
57:• if (folder == null) {
58: loadChildren();
59: }
60: return super.getChildCount();
61: }
62:
63: protected void loadChildren() {
64: try {
65: // connect to the Store if we need to
66:• if (!store.isConnected()) {
67: store.connect();
68: }
69:
70: // get the default folder, and list the
71: // subscribed folders on it
72: folder = store.getDefaultFolder();
73: // Folder[] sub = folder.listSubscribed();
74: Folder[] sub = folder.list();
75:
76: // add a client.FolderTreeNode for each Folder
77: int num = sub.length;
78:• for (int i = 0; i < num; i++) {
79: FolderTreeNode node = new FolderTreeNode(sub[i]);
80: // we used insert here, since add() would make
81: // another recursive call to getChildCount();
82: insert(node, i);
83: }
84:
85: } catch (MessagingException me) {
86: me.printStackTrace();
87: }
88: }
89:
90: /**
91: * We override toString() so we can display the store URLName
92: * without the password.
93: */
94:
95: public String toString() {
96:• if (display == null) {
97: URLName url = store.getURLName();
98:• if (url == null) {
99: display = store.toString();
100: } else {
101: // don't show the password
102: URLName too = new URLName(url.getProtocol(), url.getHost(), url.getPort(),
103: url.getFile(), url.getUsername(), null);
104: display = too.toString();
105: }
106: }
107:
108: return display;
109: }
110:
111:
112: }
113: