KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > output > TestMethodNodeChildren


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.junit.output;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import java.util.List JavaDoc;
25 import org.openide.nodes.Children;
26 import org.openide.nodes.Node;
27 import static org.netbeans.modules.junit.output.RegexpUtils.NESTED_EXCEPTION_PREFIX;
28
29 /**
30  *
31  * @author Marian Petras
32  */

33 final class TestMethodNodeChildren extends Children.Array {
34
35     /** */
36     private final Report.Testcase testcase;
37
38     /** Creates a new instance of TestMethodNodeChildren */
39     public TestMethodNodeChildren(final Report.Testcase testcase) {
40         this.testcase = testcase;
41     }
42
43     /**
44      */

45     protected void addNotify() {
46         Report.Trouble trouble = testcase.trouble;
47
48         int nodesCount = 1; //exception class name
49
if (trouble.message != null) {
50             nodesCount++;
51         }
52         if (trouble.stackTrace != null) {
53             nodesCount += trouble.stackTrace.length;
54         }
55         
56         String JavaDoc topFrameInfo = (trouble.stackTrace != null)
57                                     && (trouble.stackTrace.length != 0)
58                                             ? trouble.stackTrace[0]
59                                             : null;
60
61         Node[] children = new Node[nodesCount];
62         int index = 0;
63         if (trouble.message != null) {
64             children[index++] = new CallstackFrameNode(topFrameInfo,
65                                                        trouble.message);
66         }
67         children[index++] = new CallstackFrameNode(topFrameInfo,
68                                                    trouble.exceptionClsName);
69         for (int i = 0; index < nodesCount; i++) {
70             children[index++] = new CallstackFrameNode(trouble.stackTrace[i]);
71         }
72         
73         if (trouble.nestedTrouble != null) {
74             List JavaDoc<Node> childrenList = new ArrayList JavaDoc<Node>(nodesCount * 3);
75             childrenList.addAll(Arrays.asList(children));
76             
77             trouble = trouble.nestedTrouble;
78             do {
79                 String JavaDoc[] stackTrace = trouble.stackTrace;
80                 topFrameInfo = (stackTrace != null) && (stackTrace.length != 0)
81                                ? stackTrace[0]
82                                : null;
83                 StringBuilder JavaDoc topNodeDispName = new StringBuilder JavaDoc(200);
84                 topNodeDispName.append(NESTED_EXCEPTION_PREFIX);
85                 topNodeDispName.append(trouble.exceptionClsName);
86                 if (trouble.message != null) {
87                     topNodeDispName.append(": ") //NOI18N
88
.append(trouble.message);
89                 }
90                 childrenList.add(new CallstackFrameNode(topFrameInfo,
91                                                         topNodeDispName.toString()));
92                 if (stackTrace != null) {
93                     for (String JavaDoc frameInfo : stackTrace) {
94                         childrenList.add(new CallstackFrameNode(frameInfo));
95                     }
96                 }
97             } while ((trouble = trouble.nestedTrouble) != null);
98             
99             children = childrenList.toArray(new Node[childrenList.size()]);
100         }
101         
102         add(children);
103     }
104     
105     /**
106      */

107     protected void removeNotify() {
108         remove(getNodes());
109     }
110     
111 }
112
Popular Tags